mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Add DI and Initialisation
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Autofac;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using Jackett.Common.Models.Config;
|
||||
using Jackett.Common.Plumbing;
|
||||
using Jackett.Common.Services.Interfaces;
|
||||
using Jackett.Server.Services;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Jackett.Server
|
||||
{
|
||||
@@ -21,18 +25,47 @@ namespace Jackett.Server
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMvc();
|
||||
services
|
||||
.AddMvc()
|
||||
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); //Web app uses Pascal Case JSON
|
||||
|
||||
RuntimeSettings runtimeSettings = new RuntimeSettings();
|
||||
Configuration.GetSection("RuntimeSettings").Bind(runtimeSettings);
|
||||
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
Initialisation.SetupLogging(runtimeSettings, builder);
|
||||
|
||||
builder.Populate(services);
|
||||
builder.RegisterModule(new JackettModule(runtimeSettings));
|
||||
builder.RegisterType<SecuityService>().As<ISecuityService>();
|
||||
builder.RegisterType<ServerService>().As<IServerService>();
|
||||
builder.RegisterType<ProtectionService>().As<IProtectionService>();
|
||||
|
||||
IContainer container = builder.Build();
|
||||
Initialisation.ApplicationContainer = container;
|
||||
|
||||
return new AutofacServiceProvider(container);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
Initialisation.Initialize();
|
||||
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
app.UseFileServer(new FileServerOptions
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
FileProvider = new PhysicalFileProvider(Initialisation.ConfigService.GetContentFolder()),
|
||||
RequestPath = "",
|
||||
EnableDefaultFiles = true,
|
||||
EnableDirectoryBrowsing = false
|
||||
});
|
||||
|
||||
app.UseMvc();
|
||||
}
|
||||
|
Reference in New Issue
Block a user