Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Startup.cs 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System.Reflection;
  2. using Luticate2.Utils.Controllers;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.EntityFrameworkCore;
  6. using Microsoft.Extensions.Configuration;
  7. using Microsoft.Extensions.DependencyInjection;
  8. using Microsoft.Extensions.Logging;
  9. using WebApiWebSem.Business;
  10. using WebApiWebSem.DataAccess;
  11. using WebApiWebSem.Dbo;
  12. using WebApiWebSem.Middleware;
  13. namespace WebApiWebSem
  14. {
  15. public class Startup
  16. {
  17. public IHostingEnvironment Env { get; }
  18. public Startup(IHostingEnvironment env)
  19. {
  20. Env = env;
  21. var builder = new ConfigurationBuilder()
  22. .SetBasePath(env.ContentRootPath)
  23. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  24. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  25. if (env.IsEnvironment("Development"))
  26. {
  27. // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
  28. builder.AddApplicationInsightsSettings(developerMode: true);
  29. }
  30. builder.AddEnvironmentVariables();
  31. Configuration = builder.Build();
  32. }
  33. public IConfigurationRoot Configuration { get; }
  34. // This method gets called by the runtime. Use this method to add services to the container
  35. public void ConfigureServices(IServiceCollection services)
  36. {
  37. var version = typeof(Startup).GetTypeInfo().Assembly.GetName().Version;
  38. services.AddLuticateUtils(options => options.Version = version + "-dev");
  39. services.AddTransient<ArticlesBusiness>();
  40. services.AddTransient<ArticlesDataAccess>();
  41. services.Configure<AppConfigDbo>(dbo =>
  42. {
  43. dbo.SleepTime = Env.IsProduction() ? 0 : int.Parse(Configuration["SleepTime"]);
  44. });
  45. services.AddDbContext<WsDbContext>(options =>
  46. {
  47. options.UseNpgsql(Configuration.GetConnectionString("default"));
  48. options.UseInternalServiceProvider(new ServiceCollection()
  49. .AddEntityFrameworkNpgsqlLuticate()
  50. .AddEntityFrameworkNpgsql()
  51. .BuildServiceProvider());
  52. }, ServiceLifetime.Transient);
  53. services.AddMvc()
  54. .AddLuticateUtils();
  55. }
  56. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
  57. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  58. {
  59. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  60. loggerFactory.AddDebug();
  61. app.UseLuticateUtils();
  62. if (Env.IsDevelopment())
  63. {
  64. app.UseMiddleware<SleepMiddleware>();
  65. }
  66. app.UseMvc();
  67. }
  68. }
  69. }