From eaed98f6dd5298d84d7ec3e97e5df84fc0fb208c Mon Sep 17 00:00:00 2001 From: Samuele Resca Date: Tue, 5 May 2020 22:37:23 +0100 Subject: [PATCH] Updating to netcoreapp3.1 (#199) --- .../csharp/Controllers/SubtractController.cs | 3 --- 3.distributed-calculator/csharp/Dockerfile | 4 ++-- 3.distributed-calculator/csharp/Program.cs | 20 +++++++--------- .../csharp/Properties/launchSettings.json | 2 +- 3.distributed-calculator/csharp/Startup.cs | 23 +++++++------------ .../csharp/Subtract.csproj | 8 +------ 6 files changed, 20 insertions(+), 40 deletions(-) diff --git a/3.distributed-calculator/csharp/Controllers/SubtractController.cs b/3.distributed-calculator/csharp/Controllers/SubtractController.cs index e2d6edfe..052a95ae 100644 --- a/3.distributed-calculator/csharp/Controllers/SubtractController.cs +++ b/3.distributed-calculator/csharp/Controllers/SubtractController.cs @@ -4,9 +4,6 @@ // ------------------------------------------------------------ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Subtract.Models; diff --git a/3.distributed-calculator/csharp/Dockerfile b/3.distributed-calculator/csharp/Dockerfile index 99e00b31..1a0cbf22 100644 --- a/3.distributed-calculator/csharp/Dockerfile +++ b/3.distributed-calculator/csharp/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers @@ -10,7 +10,7 @@ COPY . ./ RUN dotnet publish -c Release -o out # Build runtime image -FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "Subtract.dll"] \ No newline at end of file diff --git a/3.distributed-calculator/csharp/Program.cs b/3.distributed-calculator/csharp/Program.cs index f5623b21..ef3f8551 100644 --- a/3.distributed-calculator/csharp/Program.cs +++ b/3.distributed-calculator/csharp/Program.cs @@ -3,15 +3,8 @@ // Licensed under the MIT License. // ------------------------------------------------------------ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Hosting; namespace Subtract { @@ -19,11 +12,14 @@ namespace Subtract { public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } } diff --git a/3.distributed-calculator/csharp/Properties/launchSettings.json b/3.distributed-calculator/csharp/Properties/launchSettings.json index 1ea82ac8..ee76730b 100644 --- a/3.distributed-calculator/csharp/Properties/launchSettings.json +++ b/3.distributed-calculator/csharp/Properties/launchSettings.json @@ -20,7 +20,7 @@ "Subtract": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "api/values", + "launchUrl": "api/subtract", "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/3.distributed-calculator/csharp/Startup.cs b/3.distributed-calculator/csharp/Startup.cs index 1f3a0a9c..f4d0c04e 100644 --- a/3.distributed-calculator/csharp/Startup.cs +++ b/3.distributed-calculator/csharp/Startup.cs @@ -3,18 +3,11 @@ // Licensed under the MIT License. // ------------------------------------------------------------ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; +using Microsoft.Extensions.Hosting; namespace Subtract { @@ -30,22 +23,22 @@ namespace Subtract // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + services.AddControllers(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } - else - { - app.UseHsts(); - } - app.UseMvc(); + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); } } } diff --git a/3.distributed-calculator/csharp/Subtract.csproj b/3.distributed-calculator/csharp/Subtract.csproj index ffe2b91d..b0623378 100644 --- a/3.distributed-calculator/csharp/Subtract.csproj +++ b/3.distributed-calculator/csharp/Subtract.csproj @@ -1,16 +1,10 @@ - netcoreapp2.1 + netcoreapp3.1 - - - - - -