From 0346fe8447640022bddae3b7600588100978aeb8 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 30 Oct 2020 22:10:30 -0400 Subject: [PATCH 1/5] Target .NET 5 --- .../AspNetControllers.csproj | 2 +- samples/AspNetControllers/Program.cs | 24 +++----- samples/CarterSample/CarterSample.csproj | 2 +- samples/CarterSample/Program.cs | 33 +++++------ samples/GRPC/GRPC.csproj | 2 +- samples/GRPC/Program.cs | 30 ++++------ samples/GRPCClient/GRPCClient.csproj | 2 +- samples/HelloWorld/HelloWorld.csproj | 2 +- samples/HelloWorld/Program.cs | 18 ++---- samples/SignalRServer/Program.cs | 24 +++----- samples/SignalRServer/SignalRServer.csproj | 2 +- samples/Uber/Program.cs | 58 +++++++++---------- samples/Uber/Uber.csproj | 2 +- .../Content/FeatherHttp-Template.csproj | 2 +- src/FeatherHttp/FeatherHttp.csproj | 2 +- src/FeatherHttp/JsonHttpContextExtensions.cs | 46 --------------- 16 files changed, 84 insertions(+), 167 deletions(-) delete mode 100644 src/FeatherHttp/JsonHttpContextExtensions.cs diff --git a/samples/AspNetControllers/AspNetControllers.csproj b/samples/AspNetControllers/AspNetControllers.csproj index 1962d1b..8a3814e 100644 --- a/samples/AspNetControllers/AspNetControllers.csproj +++ b/samples/AspNetControllers/AspNetControllers.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/samples/AspNetControllers/Program.cs b/samples/AspNetControllers/Program.cs index 2e7c22d..05f9f3e 100644 --- a/samples/AspNetControllers/Program.cs +++ b/samples/AspNetControllers/Program.cs @@ -3,24 +3,18 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -public class HomeController -{ - [HttpGet("/")] - public string HelloWorld() => "Hello World"; -} +var builder = WebApplication.CreateBuilder(args); -class Program -{ - static async Task Main(string[] args) - { - var builder = WebApplication.CreateBuilder(args); +builder.Services.AddControllers(); - builder.Services.AddControllers(); +var app = builder.Build(); - var app = builder.Build(); +app.MapControllers(); - app.MapControllers(); +await app.RunAsync(); - await app.RunAsync(); - } +public class HomeController +{ + [HttpGet("/")] + public string HelloWorld() => "Hello World"; } \ No newline at end of file diff --git a/samples/CarterSample/CarterSample.csproj b/samples/CarterSample/CarterSample.csproj index 398c9b1..9fb6533 100644 --- a/samples/CarterSample/CarterSample.csproj +++ b/samples/CarterSample/CarterSample.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/samples/CarterSample/Program.cs b/samples/CarterSample/Program.cs index d2bbfc5..a84745e 100644 --- a/samples/CarterSample/Program.cs +++ b/samples/CarterSample/Program.cs @@ -1,30 +1,23 @@ -using System.Threading.Tasks; -using Carter; +using Carter; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; -public class HomeModule : CarterModule -{ - public HomeModule() - { - Get("/", async (req, res) => await res.WriteAsync("Hello from Carter!")); - } -} +var builder = WebApplication.CreateBuilder(args); -class Program -{ - static async Task Main(string[] args) - { - var builder = WebApplication.CreateBuilder(args); +builder.Services.AddCarter(); - builder.Services.AddCarter(); +var app = builder.Build(); - var app = builder.Build(); +app.Listen("http://localhost:3000"); - app.Listen("http://localhost:3000"); +app.MapCarter(); - app.MapCarter(); +await app.RunAsync(); - await app.RunAsync(); +public class HomeModule : CarterModule +{ + public HomeModule() + { + Get("/", async (req, res) => await res.WriteAsync("Hello from Carter!")); } -} \ No newline at end of file +} diff --git a/samples/GRPC/GRPC.csproj b/samples/GRPC/GRPC.csproj index 56408d2..04bacfd 100644 --- a/samples/GRPC/GRPC.csproj +++ b/samples/GRPC/GRPC.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/samples/GRPC/Program.cs b/samples/GRPC/Program.cs index e0b918b..5b66aae 100644 --- a/samples/GRPC/Program.cs +++ b/samples/GRPC/Program.cs @@ -5,6 +5,18 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddGrpc(); + +var app = builder.Build(); + +app.Listen("http://localhost:3000"); + +app.MapGrpcService(); + +await app.RunAsync(); + public class GreeterService : Greeter.GreeterBase { private readonly ILogger _logger; @@ -21,21 +33,3 @@ public override Task SayHello(HelloRequest request, ServerCallContex }); } } - -class Program -{ - static async Task Main(string[] args) - { - var builder = WebApplication.CreateBuilder(args); - - builder.Services.AddGrpc(); - - var app = builder.Build(); - - app.Listen("http://localhost:3000"); - - app.MapGrpcService(); - - await app.RunAsync(); - } -} \ No newline at end of file diff --git a/samples/GRPCClient/GRPCClient.csproj b/samples/GRPCClient/GRPCClient.csproj index 878fb05..44cc631 100644 --- a/samples/GRPCClient/GRPCClient.csproj +++ b/samples/GRPCClient/GRPCClient.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net5.0 false diff --git a/samples/HelloWorld/HelloWorld.csproj b/samples/HelloWorld/HelloWorld.csproj index 1962d1b..8a3814e 100644 --- a/samples/HelloWorld/HelloWorld.csproj +++ b/samples/HelloWorld/HelloWorld.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/samples/HelloWorld/Program.cs b/samples/HelloWorld/Program.cs index c430e20..704f4c8 100644 --- a/samples/HelloWorld/Program.cs +++ b/samples/HelloWorld/Program.cs @@ -2,17 +2,11 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; -class Program -{ - static async Task Main(string[] args) - { - var app = WebApplication.Create(args); +var app = WebApplication.Create(args); - app.MapGet("/", async http => - { - await http.Response.WriteJsonAsync(new { message = "Hello World" }); - }); +app.MapGet("/", async http => +{ + await http.Response.WriteAsJsonAsync(new { message = "Hello World" }); +}); - await app.RunAsync(); - } -} \ No newline at end of file +await app.RunAsync(); \ No newline at end of file diff --git a/samples/SignalRServer/Program.cs b/samples/SignalRServer/Program.cs index 48e9ce7..fef8124 100644 --- a/samples/SignalRServer/Program.cs +++ b/samples/SignalRServer/Program.cs @@ -3,23 +3,17 @@ using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.DependencyInjection; -class Chat : Hub -{ - public Task Send(string message) => Clients.All.SendAsync("Send", message); -} +var builder = WebApplication.CreateBuilder(args); -class Program -{ - static async Task Main(string[] args) - { - var builder = WebApplication.CreateBuilder(args); +builder.Services.AddSignalR(); - builder.Services.AddSignalR(); +var app = builder.Build(); - var app = builder.Build(); - - app.MapHub("/chat"); +app.MapHub("/chat"); - await app.RunAsync(); - } +await app.RunAsync(); + +class Chat : Hub +{ + public Task Send(string message) => Clients.All.SendAsync("Send", message); } \ No newline at end of file diff --git a/samples/SignalRServer/SignalRServer.csproj b/samples/SignalRServer/SignalRServer.csproj index d4359d9..62b645f 100644 --- a/samples/SignalRServer/SignalRServer.csproj +++ b/samples/SignalRServer/SignalRServer.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 diff --git a/samples/Uber/Program.cs b/samples/Uber/Program.cs index bf9053c..f5ad5dd 100644 --- a/samples/Uber/Program.cs +++ b/samples/Uber/Program.cs @@ -7,45 +7,39 @@ using Microsoft.Extensions.Hosting; using Serilog; -class Program -{ - static async Task Main(string[] args) - { - var builder = WebApplication.CreateBuilder(args); +var builder = WebApplication.CreateBuilder(args); - builder.Configuration.AddYamlFile("appsettings.yml", optional: true); +builder.Configuration.AddYamlFile("appsettings.yml", optional: true); - builder.Host.UseSerilog((context, configuration) - => configuration - .Enrich - .FromLogContext() - .WriteTo - .Console() - ); +builder.Host.UseSerilog((context, configuration) + => configuration + .Enrich + .FromLogContext() + .WriteTo + .Console() + ); - builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); +builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); - builder.Host.ConfigureContainer(b => - { - // Register services using Autofac specific methods here - }); +builder.Host.ConfigureContainer(b => +{ + // Register services using Autofac specific methods here +}); - var app = builder.Build(); +var app = builder.Build(); - app.Listen("http://localhost:3000"); +app.Listen("http://localhost:3000"); - if (app.Environment.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); +} - app.UseRouting(); +app.UseRouting(); - app.MapGet("/", async http => - { - await http.Response.WriteAsync("Hello World"); - }); +app.MapGet("/", async http => +{ + await http.Response.WriteAsync("Hello World"); +}); - await app.RunAsync(); - } -} \ No newline at end of file +await app.RunAsync(); \ No newline at end of file diff --git a/samples/Uber/Uber.csproj b/samples/Uber/Uber.csproj index f1db133..1232788 100644 --- a/samples/Uber/Uber.csproj +++ b/samples/Uber/Uber.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/src/FeatherHttp.Templates/Content/FeatherHttp-Template.csproj b/src/FeatherHttp.Templates/Content/FeatherHttp-Template.csproj index fe9a7c4..440a2b3 100644 --- a/src/FeatherHttp.Templates/Content/FeatherHttp-Template.csproj +++ b/src/FeatherHttp.Templates/Content/FeatherHttp-Template.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 $(RestoreSources); https://api.nuget.org/v3/index.json; diff --git a/src/FeatherHttp/FeatherHttp.csproj b/src/FeatherHttp/FeatherHttp.csproj index e9e20b3..de7c9af 100644 --- a/src/FeatherHttp/FeatherHttp.csproj +++ b/src/FeatherHttp/FeatherHttp.csproj @@ -2,7 +2,7 @@ FeatherHttp - netcoreapp3.1 + net5.0 A lightweight low ceremony API for ASP.NET Core services. David Fowler true diff --git a/src/FeatherHttp/JsonHttpContextExtensions.cs b/src/FeatherHttp/JsonHttpContextExtensions.cs deleted file mode 100644 index 7ed0f8f..0000000 --- a/src/FeatherHttp/JsonHttpContextExtensions.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Http -{ - /// - /// Various extension methods to read and write JSON to and from the and . - /// - public static class JsonHttpContextExtensions - { - /// - /// Asynchronously reads the UTF-8 encoded text representing a single JSON value - /// into an instance of a type specified by a generic type parameter. The body - /// will be read to completion. - /// - /// The target type of the JSON value. - /// The to read the JSON from. - /// Options to control the behavior during reading. - /// A token that may be used to cancel the read operation. - /// A TValue representation of the JSON value. - public static ValueTask ReadJsonAsync(this HttpRequest request, JsonSerializerOptions options = null, CancellationToken cancellationToken = default) - { - // TODO: Handle non-utf8 encoding - return JsonSerializer.DeserializeAsync(request.Body, options, cancellationToken); - } - - /// - /// Asynchronously converts a value of a type specified by a generic type parameter - /// to UTF-8 encoded JSON text and writes it to the body with an application/json content-type. - /// - /// The type of the value to serialize. - /// The to write the JSON to. - /// The value to convert - /// Options to control behavior during writing. - /// A token that may be used to cancel the write operation. - /// A task that represents the asynchronous write operation. - public static Task WriteJsonAsync(this HttpResponse response, TValue value, JsonSerializerOptions options = null, CancellationToken cancellationToken = default) - { - // Set the content type to application/json if it's not already set - response.ContentType ??= "application/json"; - - return JsonSerializer.SerializeAsync(response.Body, value, options, cancellationToken); - } - } -} From 87b798be570cafe5a6a61a8912ed6e44cc48fba7 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 30 Oct 2020 22:13:55 -0400 Subject: [PATCH 2/5] Fixed readme --- README.md | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3d65c35..181cc68 100644 --- a/README.md +++ b/README.md @@ -15,20 +15,14 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; -class Program +var app = WebApplication.Create(args); + +app.MapGet("/", async http => { - static async Task Main(string[] args) - { - var app = WebApplication.Create(args); - - app.MapGet("/", async http => - { - await http.Response.WriteAsync("Hello World"); - }); - - await app.RunAsync(); - } -} + await http.Response.WriteAsync("Hello World"); +}); + +await app.RunAsync(); ``` ## Tutorial From 40c53f3e3d57df70387e26cf40465274decb7a16 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 1 Nov 2020 12:39:39 -0400 Subject: [PATCH 3/5] Use top level functions in the project template --- src/FeatherHttp.Templates/Content/Program.cs | 21 ++++++-------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/FeatherHttp.Templates/Content/Program.cs b/src/FeatherHttp.Templates/Content/Program.cs index ec93e27..f3c49d0 100644 --- a/src/FeatherHttp.Templates/Content/Program.cs +++ b/src/FeatherHttp.Templates/Content/Program.cs @@ -2,20 +2,11 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; -namespace FeatherHttp_Template -{ - class Program - { - static async Task Main(string[] args) - { - var app = WebApplication.Create(args); +var app = WebApplication.Create(args); - app.MapGet("/", async http => - { - await http.Response.WriteAsync("Hello World!"); - }); +app.MapGet("/", async http => +{ + await http.Response.WriteAsync("Hello World!"); +}); - await app.RunAsync(); - } - } -} +await app.RunAsync(); \ No newline at end of file From e1fec947d286789378e708a9b80afce3dcb5cdea Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 11 Nov 2020 00:23:59 -0400 Subject: [PATCH 4/5] Updated 5.0.0 --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 98d53fa..3d72ada 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET Core SDK uses: actions/setup-dotnet@v1.4.0 with: - version: 3.1.100 + version: 5.0.100 - name: dotnet build run: dotnet build FeatherHttp.sln -c Release From b8a6afc186d84652556eb7add5d134ad11a8e7db Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 11 Nov 2020 00:30:10 -0400 Subject: [PATCH 5/5] Update? --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 7b2ebc9..e244d5e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -12,7 +12,7 @@ - 3.0.28 + 3.3.37 all