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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.AddTransient<FeedBusiness>();
  46. services.AddTransient<FeedDataAccess>();
  47. services.Configure<AppConfigDbo>(dbo =>
  48. {
  49. dbo.SleepTime = Env.IsProduction() ? 0 : int.Parse(Configuration["SleepTime"]);
  50. dbo.FeedUrl = Configuration["FeedUrl"];
  51. });
  52. services.AddDbContext<WsDbContext>(options =>
  53. {
  54. options.UseNpgsql(Configuration.GetConnectionString("default"));
  55. options.UseInternalServiceProvider(new ServiceCollection()
  56. .AddEntityFrameworkNpgsqlLuticate()
  57. .AddEntityFrameworkNpgsql()
  58. .BuildServiceProvider());
  59. }, ServiceLifetime.Transient);
  60. services.AddMvc()
  61. .AddLuticateUtils();
  62. }
  63. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
  64. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  65. {
  66. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  67. loggerFactory.AddDebug();
  68. app.UseLuticateUtils();
  69. if (Env.IsDevelopment())
  70. {
  71. app.UseMiddleware<SleepMiddleware>();
  72. }
  73. app.UseMvc();
  74. }
  75. }
  76. }