Startup.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.Hosting;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. namespace XYY.gRpc.Customer
  11. {
  12. public class Startup
  13. {
  14. // This method gets called by the runtime. Use this method to add services to the container.
  15. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
  16. public void ConfigureServices(IServiceCollection services)
  17. {
  18. services.AddGrpc();
  19. }
  20. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  21. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  22. {
  23. if (env.IsDevelopment())
  24. {
  25. app.UseDeveloperExceptionPage();
  26. }
  27. app.UseRouting();
  28. app.UseEndpoints(endpoints =>
  29. {
  30. endpoints.MapGrpcService<GreeterService>();
  31. endpoints.MapGet("/", async context =>
  32. {
  33. await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
  34. });
  35. });
  36. }
  37. }
  38. }