Skip to content

Commit

Permalink
Merge pull request LesnyRumcajs#130 from Vake93/dotnet-minimal-api
Browse files Browse the repository at this point in the history
.NET: Updated to use the new web application builder pattern
  • Loading branch information
LesnyRumcajs authored May 9, 2021
2 parents 28c686b + 42ebd1c commit cc8c28e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 81 deletions.
59 changes: 30 additions & 29 deletions dotnet_grpc_bench/GreeterServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,38 @@

#endregion

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using GreeterServer.Services;
using GreeterServer;
using System;

namespace GreeterServer
var builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureKestrel(options =>
{
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.ConfigureKestrel(options =>
{
options.AddServerHeader = false;
options.ListenAnyIP(50051, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
});
});
webBuilder.ConfigureLogging(logging =>
{
logging.ClearProviders();
});
webBuilder.UseStartup<Startup>();
});
}
}
options.AddServerHeader = false;
options.ListenAnyIP(50051, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
});
});

builder.Logging.ClearProviders();

builder.Services.AddGrpc(o => o.IgnoreUnknownServices = true);
builder.Services.Configure<RouteOptions>(c => c.SuppressCheckForUnhandledSecurityMetadata = true);
builder.Services.AddSingleton<GreeterService>();

var app = builder.Build();

app.Lifetime.ApplicationStarted.Register(() => Console.WriteLine("Application started."));
app.UseMiddleware<ServiceProvidersMiddleware>();
app.MapGrpcService<GreeterService>();

await app.RunAsync();
52 changes: 0 additions & 52 deletions dotnet_grpc_bench/GreeterServer/Startup.cs

This file was deleted.

0 comments on commit cc8c28e

Please sign in to comment.