diff --git a/samples/Calculator/add/.dockerignore b/samples/Calculator/add/.dockerignore new file mode 100644 index 00000000..a02c9edb --- /dev/null +++ b/samples/Calculator/add/.dockerignore @@ -0,0 +1,2 @@ +bin\ +obj\ \ No newline at end of file diff --git a/samples/Calculator/add/.gitignore b/samples/Calculator/add/.gitignore new file mode 100644 index 00000000..1746e326 --- /dev/null +++ b/samples/Calculator/add/.gitignore @@ -0,0 +1,2 @@ +bin +obj diff --git a/samples/Calculator/add/Addition.csproj b/samples/Calculator/add/Addition.csproj new file mode 100644 index 00000000..b0623378 --- /dev/null +++ b/samples/Calculator/add/Addition.csproj @@ -0,0 +1,10 @@ + + + + netcoreapp3.1 + + + + + + diff --git a/samples/Calculator/add/Controllers/AdditionController.cs b/samples/Calculator/add/Controllers/AdditionController.cs new file mode 100644 index 00000000..0e16ecd5 --- /dev/null +++ b/samples/Calculator/add/Controllers/AdditionController.cs @@ -0,0 +1,23 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using System; +using Microsoft.AspNetCore.Mvc; + +namespace Addition.Controllers +{ + [ApiController] + public class AdditionController : ControllerBase + { + + [HttpGet] + [Route("{op1?}/{op2?}")] + public decimal Add(decimal op1, decimal op2) + { + Console.WriteLine($"Add {op1} to {op2}"); + return op1 + op2; + } + } +} diff --git a/samples/Calculator/add/Dockerfile b/samples/Calculator/add/Dockerfile new file mode 100644 index 00000000..1a0cbf22 --- /dev/null +++ b/samples/Calculator/add/Dockerfile @@ -0,0 +1,16 @@ +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env +WORKDIR /app + +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +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/samples/Calculator/add/Program.cs b/samples/Calculator/add/Program.cs new file mode 100644 index 00000000..ef3f8551 --- /dev/null +++ b/samples/Calculator/add/Program.cs @@ -0,0 +1,25 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/samples/Calculator/add/Properties/launchSettings.json b/samples/Calculator/add/Properties/launchSettings.json new file mode 100644 index 00000000..0a773733 --- /dev/null +++ b/samples/Calculator/add/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:4927", + "sslPort": 44366 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Subtract": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/subtract", + "applicationUrl": "https://localhost:8001;http://localhost:8000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/samples/Calculator/add/Startup.cs b/samples/Calculator/add/Startup.cs new file mode 100644 index 00000000..f4d0c04e --- /dev/null +++ b/samples/Calculator/add/Startup.cs @@ -0,0 +1,44 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/samples/Calculator/add/appsettings.Development.json b/samples/Calculator/add/appsettings.Development.json new file mode 100644 index 00000000..e203e940 --- /dev/null +++ b/samples/Calculator/add/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/samples/Calculator/add/appsettings.json b/samples/Calculator/add/appsettings.json new file mode 100644 index 00000000..def9159a --- /dev/null +++ b/samples/Calculator/add/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/samples/Calculator/add/dapr.cmd b/samples/Calculator/add/dapr.cmd new file mode 100644 index 00000000..7db05e90 --- /dev/null +++ b/samples/Calculator/add/dapr.cmd @@ -0,0 +1 @@ +dapr run --app-id add --app-port 9000 --port 3500 dotnet run \ No newline at end of file diff --git a/samples/Calculator/calculator/.dockerignore b/samples/Calculator/calculator/.dockerignore new file mode 100644 index 00000000..a02c9edb --- /dev/null +++ b/samples/Calculator/calculator/.dockerignore @@ -0,0 +1,2 @@ +bin\ +obj\ \ No newline at end of file diff --git a/samples/Calculator/calculator/.gitignore b/samples/Calculator/calculator/.gitignore new file mode 100644 index 00000000..1746e326 --- /dev/null +++ b/samples/Calculator/calculator/.gitignore @@ -0,0 +1,2 @@ +bin +obj diff --git a/samples/Calculator/calculator/Calculator.csproj b/samples/Calculator/calculator/Calculator.csproj new file mode 100644 index 00000000..b0623378 --- /dev/null +++ b/samples/Calculator/calculator/Calculator.csproj @@ -0,0 +1,10 @@ + + + + netcoreapp3.1 + + + + + + diff --git a/samples/Calculator/calculator/Controllers/CalculatorController.cs b/samples/Calculator/calculator/Controllers/CalculatorController.cs new file mode 100644 index 00000000..6d967498 --- /dev/null +++ b/samples/Calculator/calculator/Controllers/CalculatorController.cs @@ -0,0 +1,32 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace Subtract.Controllers +{ + + [ApiController] + public class SubtractController : ControllerBase + { + static readonly HttpClient client = new HttpClient(); + [HttpGet] + [Route("{operation}/{op1?}/{op2?}")] + public async Task Operation(string operation, decimal op1, decimal op2) + { + Console.WriteLine($"Operation: {operation} - op1: {op1} - op2: {op2}"); + + var operationService = operation + "Service"; + HttpResponseMessage response = await client.GetAsync($"http://localhost:3501/v1.0/invoke/{operationService}/method/{op1}/{op2}"); + + string responseBody = await response.Content.ReadAsStringAsync(); + + return Decimal.Parse(responseBody); + } + } +} diff --git a/samples/Calculator/calculator/Dockerfile b/samples/Calculator/calculator/Dockerfile new file mode 100644 index 00000000..1a0cbf22 --- /dev/null +++ b/samples/Calculator/calculator/Dockerfile @@ -0,0 +1,16 @@ +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env +WORKDIR /app + +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +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/samples/Calculator/calculator/Program.cs b/samples/Calculator/calculator/Program.cs new file mode 100644 index 00000000..ef3f8551 --- /dev/null +++ b/samples/Calculator/calculator/Program.cs @@ -0,0 +1,25 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/samples/Calculator/calculator/Properties/launchSettings.json b/samples/Calculator/calculator/Properties/launchSettings.json new file mode 100644 index 00000000..7bd72150 --- /dev/null +++ b/samples/Calculator/calculator/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:4927", + "sslPort": 44366 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Subtract": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/subtract", + "applicationUrl": "https://localhost:9001;http://localhost:9000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/samples/Calculator/calculator/Startup.cs b/samples/Calculator/calculator/Startup.cs new file mode 100644 index 00000000..f4d0c04e --- /dev/null +++ b/samples/Calculator/calculator/Startup.cs @@ -0,0 +1,44 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/samples/Calculator/calculator/appsettings.Development.json b/samples/Calculator/calculator/appsettings.Development.json new file mode 100644 index 00000000..e203e940 --- /dev/null +++ b/samples/Calculator/calculator/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/samples/Calculator/calculator/appsettings.json b/samples/Calculator/calculator/appsettings.json new file mode 100644 index 00000000..def9159a --- /dev/null +++ b/samples/Calculator/calculator/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/samples/Calculator/division/.dockerignore b/samples/Calculator/division/.dockerignore new file mode 100644 index 00000000..a02c9edb --- /dev/null +++ b/samples/Calculator/division/.dockerignore @@ -0,0 +1,2 @@ +bin\ +obj\ \ No newline at end of file diff --git a/samples/Calculator/division/.gitignore b/samples/Calculator/division/.gitignore new file mode 100644 index 00000000..1746e326 --- /dev/null +++ b/samples/Calculator/division/.gitignore @@ -0,0 +1,2 @@ +bin +obj diff --git a/samples/Calculator/division/Controllers/DivisionController.cs b/samples/Calculator/division/Controllers/DivisionController.cs new file mode 100644 index 00000000..4c33eed8 --- /dev/null +++ b/samples/Calculator/division/Controllers/DivisionController.cs @@ -0,0 +1,23 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using System; +using Microsoft.AspNetCore.Mvc; + +namespace Division.Controllers +{ + [ApiController] + public class DivisionController : ControllerBase + { + + [HttpGet] + [Route("{op1?}/{op2?}")] + public decimal Divide(decimal op1, decimal op2) + { + Console.WriteLine($"Divide {op1} with {op2}"); + return op1 / op2; + } + } +} diff --git a/samples/Calculator/division/Division.csproj b/samples/Calculator/division/Division.csproj new file mode 100644 index 00000000..b0623378 --- /dev/null +++ b/samples/Calculator/division/Division.csproj @@ -0,0 +1,10 @@ + + + + netcoreapp3.1 + + + + + + diff --git a/samples/Calculator/division/Dockerfile b/samples/Calculator/division/Dockerfile new file mode 100644 index 00000000..1a0cbf22 --- /dev/null +++ b/samples/Calculator/division/Dockerfile @@ -0,0 +1,16 @@ +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env +WORKDIR /app + +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +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/samples/Calculator/division/Program.cs b/samples/Calculator/division/Program.cs new file mode 100644 index 00000000..ef3f8551 --- /dev/null +++ b/samples/Calculator/division/Program.cs @@ -0,0 +1,25 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/samples/Calculator/division/Properties/launchSettings.json b/samples/Calculator/division/Properties/launchSettings.json new file mode 100644 index 00000000..eca138cd --- /dev/null +++ b/samples/Calculator/division/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:4927", + "sslPort": 44366 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Subtract": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/subtract", + "applicationUrl": "https://localhost:7001;http://localhost:7000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/samples/Calculator/division/Startup.cs b/samples/Calculator/division/Startup.cs new file mode 100644 index 00000000..f4d0c04e --- /dev/null +++ b/samples/Calculator/division/Startup.cs @@ -0,0 +1,44 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/samples/Calculator/division/appsettings.Development.json b/samples/Calculator/division/appsettings.Development.json new file mode 100644 index 00000000..e203e940 --- /dev/null +++ b/samples/Calculator/division/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/samples/Calculator/division/appsettings.json b/samples/Calculator/division/appsettings.json new file mode 100644 index 00000000..def9159a --- /dev/null +++ b/samples/Calculator/division/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/samples/Calculator/multiply/.dockerignore b/samples/Calculator/multiply/.dockerignore new file mode 100644 index 00000000..a02c9edb --- /dev/null +++ b/samples/Calculator/multiply/.dockerignore @@ -0,0 +1,2 @@ +bin\ +obj\ \ No newline at end of file diff --git a/samples/Calculator/multiply/.gitignore b/samples/Calculator/multiply/.gitignore new file mode 100644 index 00000000..1746e326 --- /dev/null +++ b/samples/Calculator/multiply/.gitignore @@ -0,0 +1,2 @@ +bin +obj diff --git a/samples/Calculator/multiply/Controllers/MultiplyController.cs b/samples/Calculator/multiply/Controllers/MultiplyController.cs new file mode 100644 index 00000000..b8120858 --- /dev/null +++ b/samples/Calculator/multiply/Controllers/MultiplyController.cs @@ -0,0 +1,18 @@ +using System; +using Microsoft.AspNetCore.Mvc; + +namespace Multiply.Controllers +{ + [ApiController] + public class MultiplyController : ControllerBase + { + + [HttpGet] + [Route("{op1?}/{op2?}")] + public decimal Multiply(decimal op1, decimal op2) + { + Console.WriteLine($"Multiplying {op1} with {op2}"); + return op1 * op2; + } + } +} diff --git a/samples/Calculator/multiply/Dockerfile b/samples/Calculator/multiply/Dockerfile new file mode 100644 index 00000000..1a0cbf22 --- /dev/null +++ b/samples/Calculator/multiply/Dockerfile @@ -0,0 +1,16 @@ +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env +WORKDIR /app + +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +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/samples/Calculator/multiply/Multiply.csproj b/samples/Calculator/multiply/Multiply.csproj new file mode 100644 index 00000000..b0623378 --- /dev/null +++ b/samples/Calculator/multiply/Multiply.csproj @@ -0,0 +1,10 @@ + + + + netcoreapp3.1 + + + + + + diff --git a/samples/Calculator/multiply/Program.cs b/samples/Calculator/multiply/Program.cs new file mode 100644 index 00000000..ef3f8551 --- /dev/null +++ b/samples/Calculator/multiply/Program.cs @@ -0,0 +1,25 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/samples/Calculator/multiply/Properties/launchSettings.json b/samples/Calculator/multiply/Properties/launchSettings.json new file mode 100644 index 00000000..75bb8073 --- /dev/null +++ b/samples/Calculator/multiply/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:4927", + "sslPort": 44366 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Subtract": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/subtract", + "applicationUrl": "https://localhost:6001;http://localhost:6000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/samples/Calculator/multiply/Startup.cs b/samples/Calculator/multiply/Startup.cs new file mode 100644 index 00000000..f4d0c04e --- /dev/null +++ b/samples/Calculator/multiply/Startup.cs @@ -0,0 +1,44 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/samples/Calculator/multiply/appsettings.Development.json b/samples/Calculator/multiply/appsettings.Development.json new file mode 100644 index 00000000..e203e940 --- /dev/null +++ b/samples/Calculator/multiply/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/samples/Calculator/multiply/appsettings.json b/samples/Calculator/multiply/appsettings.json new file mode 100644 index 00000000..def9159a --- /dev/null +++ b/samples/Calculator/multiply/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/samples/Calculator/subtract/.dockerignore b/samples/Calculator/subtract/.dockerignore new file mode 100644 index 00000000..a02c9edb --- /dev/null +++ b/samples/Calculator/subtract/.dockerignore @@ -0,0 +1,2 @@ +bin\ +obj\ \ No newline at end of file diff --git a/samples/Calculator/subtract/.gitignore b/samples/Calculator/subtract/.gitignore new file mode 100644 index 00000000..1746e326 --- /dev/null +++ b/samples/Calculator/subtract/.gitignore @@ -0,0 +1,2 @@ +bin +obj diff --git a/samples/Calculator/subtract/Controllers/SubtractController.cs b/samples/Calculator/subtract/Controllers/SubtractController.cs new file mode 100644 index 00000000..3b7c8929 --- /dev/null +++ b/samples/Calculator/subtract/Controllers/SubtractController.cs @@ -0,0 +1,23 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using System; +using Microsoft.AspNetCore.Mvc; + +namespace Subtract.Controllers +{ + [ApiController] + public class SubtractController : ControllerBase + { + + [HttpGet] + [Route("{op1?}/{op2?}")] + public decimal Subtract(decimal op1, decimal op2) + { + Console.WriteLine($"Subtracting {op1} from {op2}"); + return op1 - op2; + } + } +} diff --git a/samples/Calculator/subtract/Dockerfile b/samples/Calculator/subtract/Dockerfile new file mode 100644 index 00000000..1a0cbf22 --- /dev/null +++ b/samples/Calculator/subtract/Dockerfile @@ -0,0 +1,16 @@ +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env +WORKDIR /app + +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +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/samples/Calculator/subtract/Program.cs b/samples/Calculator/subtract/Program.cs new file mode 100644 index 00000000..ef3f8551 --- /dev/null +++ b/samples/Calculator/subtract/Program.cs @@ -0,0 +1,25 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/samples/Calculator/subtract/Properties/launchSettings.json b/samples/Calculator/subtract/Properties/launchSettings.json new file mode 100644 index 00000000..ee76730b --- /dev/null +++ b/samples/Calculator/subtract/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:4927", + "sslPort": 44366 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Subtract": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/subtract", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/samples/Calculator/subtract/Startup.cs b/samples/Calculator/subtract/Startup.cs new file mode 100644 index 00000000..f4d0c04e --- /dev/null +++ b/samples/Calculator/subtract/Startup.cs @@ -0,0 +1,44 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Subtract +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/samples/Calculator/subtract/Subtract.csproj b/samples/Calculator/subtract/Subtract.csproj new file mode 100644 index 00000000..b0623378 --- /dev/null +++ b/samples/Calculator/subtract/Subtract.csproj @@ -0,0 +1,10 @@ + + + + netcoreapp3.1 + + + + + + diff --git a/samples/Calculator/subtract/appsettings.Development.json b/samples/Calculator/subtract/appsettings.Development.json new file mode 100644 index 00000000..e203e940 --- /dev/null +++ b/samples/Calculator/subtract/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/samples/Calculator/subtract/appsettings.json b/samples/Calculator/subtract/appsettings.json new file mode 100644 index 00000000..def9159a --- /dev/null +++ b/samples/Calculator/subtract/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +}