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.

Startup.cs 3.2KB

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