You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

  1. #if NETCORE
  2. using Microsoft.AspNetCore.Builder;
  3. using Microsoft.AspNetCore.Hosting;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Hosting;
  8. using Microsoft.Extensions.Logging;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Threading.Tasks;
  12. namespace Apewer.Web
  13. {
  14. internal sealed class ApiStartup
  15. {
  16. public ApiStartup(IConfiguration configuration)
  17. {
  18. Configuration = configuration;
  19. }
  20. public IConfiguration Configuration { get; }
  21. // This method gets called by the runtime. Use this method to add services to the container.
  22. public void ConfigureServices(IServiceCollection services)
  23. {
  24. //services.AddControllers();
  25. services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  26. }
  27. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  28. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  29. {
  30. if (env.IsDevelopment()) app.UseDeveloperExceptionPage();
  31. app.Run(Execute);
  32. // app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); });
  33. }
  34. private Task Execute(HttpContext context)
  35. {
  36. var message = ApiInvoker.Execute(context);
  37. return string.IsNullOrEmpty(message) ? Task.CompletedTask : Task.FromException(new Exception());
  38. }
  39. }
  40. }
  41. #endif