Startup.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.Hosting;
  6. using Microsoft.AspNetCore.WebSockets;
  7. using System;
  8. using gameapi.Controllers;
  9. namespace gameapi
  10. {
  11. public class Startup
  12. {
  13. public Startup(IConfiguration configuration)
  14. {
  15. Configuration = configuration;
  16. }
  17. public IConfiguration Configuration { get; }
  18. public void ConfigureServices(IServiceCollection services)
  19. {
  20. services.AddControllers();
  21. services.AddWebSockets(options =>
  22. {
  23. options.ReceiveBufferSize = 4 * 1024;
  24. options.KeepAliveInterval = TimeSpan.FromSeconds(120);
  25. });
  26. services.AddTransient<WebsocketController>();
  27. services.AddHostedService<TickController>();
  28. }
  29. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  30. {
  31. if (env.IsDevelopment())
  32. {
  33. app.UseDeveloperExceptionPage();
  34. }
  35. app.UseRouting();
  36. app.UseDefaultFiles();
  37. app.UseStaticFiles();
  38. app.UseEndpoints(endpoints =>
  39. {
  40. endpoints.MapControllers();
  41. });
  42. app.UseWebSockets();
  43. app.UseMiddleware<WebsocketController>();
  44. Library.GlobalConfiguration.Set(Configuration);
  45. }
  46. }
  47. }