diff --git a/common/ASC.Api.Core/Core/BaseStartup.cs b/common/ASC.Api.Core/Core/BaseStartup.cs index 5c23ebf891..82f39f409a 100644 --- a/common/ASC.Api.Core/Core/BaseStartup.cs +++ b/common/ASC.Api.Core/Core/BaseStartup.cs @@ -4,7 +4,6 @@ using ASC.Api.Core.Auth; using ASC.Api.Core.Core; using ASC.Api.Core.Middleware; using ASC.Common; -using ASC.Common.DependencyInjection; using ASC.Common.Logging; using Microsoft.AspNetCore.Authentication; @@ -100,8 +99,6 @@ namespace ASC.Api.Core { DIHelper.AddNLogManager(LogParams); } - - services.AddAutofac(Configuration, HostEnvironment.ContentRootPath); } public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/common/ASC.Common/ASC.Common.csproj b/common/ASC.Common/ASC.Common.csproj index b6b657bd36..a74019033f 100644 --- a/common/ASC.Common/ASC.Common.csproj +++ b/common/ASC.Common/ASC.Common.csproj @@ -28,9 +28,9 @@ - - - + + + diff --git a/common/ASC.Common/DependencyInjection/AutofacExtension.cs b/common/ASC.Common/DependencyInjection/AutofacExtension.cs index 46b0953c06..8fa409fe82 100644 --- a/common/ASC.Common/DependencyInjection/AutofacExtension.cs +++ b/common/ASC.Common/DependencyInjection/AutofacExtension.cs @@ -6,11 +6,8 @@ using System.Runtime.Loader; using Autofac; using Autofac.Configuration; -using Autofac.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; namespace ASC.Common.DependencyInjection { @@ -26,7 +23,7 @@ namespace ASC.Common.DependencyInjection public static class AutofacExtension { - public static IContainer AddAutofac(this IServiceCollection services, IConfiguration configuration, string currentDir, bool loadproducts = true, bool loadconsumers = true, params string[] intern) + public static void Register(this ContainerBuilder builder, IConfiguration configuration, string currentDir, bool loadproducts = true, bool loadconsumers = true, params string[] intern) { var folder = configuration["core:products:folder"]; var subfolder = configuration["core:products:subfolder"]; @@ -48,7 +45,6 @@ namespace ASC.Common.DependencyInjection productsDir = folder; } - var builder = new ContainerBuilder(); var modules = new List<(bool, string)> { (true, "autofac.json") @@ -88,13 +84,7 @@ namespace ASC.Common.DependencyInjection } } - builder.Populate(services); - - var container = builder.Build(); - - services.TryAddSingleton(container); - - return container; + return; void FindAndLoad(IConfigurationSection sectionSettings) { diff --git a/common/services/ASC.ApiSystem/Program.cs b/common/services/ASC.ApiSystem/Program.cs index db20dc7d71..19d4c26054 100644 --- a/common/services/ASC.ApiSystem/Program.cs +++ b/common/services/ASC.ApiSystem/Program.cs @@ -25,7 +25,9 @@ using System.Collections.Generic; -using System.IO; +using System.IO; + +using Autofac.Extensions.DependencyInjection; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -43,6 +45,7 @@ namespace ASC.ApiSystem public static IHostBuilder CreateHostBuilder(string[] args) { return Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/common/services/ASC.ApiSystem/Startup.cs b/common/services/ASC.ApiSystem/Startup.cs index b818968d2a..5299a9144a 100644 --- a/common/services/ASC.ApiSystem/Startup.cs +++ b/common/services/ASC.ApiSystem/Startup.cs @@ -28,7 +28,9 @@ using ASC.ApiSystem.Classes; using ASC.ApiSystem.Controllers; using ASC.Common; using ASC.Common.DependencyInjection; -using ASC.Common.Logging; +using ASC.Common.Logging; + +using Autofac; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; @@ -81,8 +83,6 @@ namespace ASC.ApiSystem .AddRegistrationController() .AddSettingsController() .AddTariffController(); - - services.AddAutofac(Configuration, HostEnvironment.ContentRootPath, false); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -114,6 +114,10 @@ namespace ASC.ApiSystem { endpoints.MapControllers(); }); + } + public void ConfigureContainer(ContainerBuilder builder) + { + builder.Register(Configuration, HostEnvironment.ContentRootPath, false); } } } diff --git a/common/services/ASC.Data.Backup/Program.cs b/common/services/ASC.Data.Backup/Program.cs index ed8fa6d17f..b4e8c22902 100644 --- a/common/services/ASC.Data.Backup/Program.cs +++ b/common/services/ASC.Data.Backup/Program.cs @@ -2,6 +2,8 @@ using System.IO; using System.Threading.Tasks; +using Autofac.Extensions.DependencyInjection; + using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -12,7 +14,8 @@ namespace ASC.Data.Backup { public static async Task Main(string[] args) { - await Host.CreateDefaultBuilder(args) + await Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/common/services/ASC.Data.Backup/Startup.cs b/common/services/ASC.Data.Backup/Startup.cs index 09d474e0b9..577cd378b0 100644 --- a/common/services/ASC.Data.Backup/Startup.cs +++ b/common/services/ASC.Data.Backup/Startup.cs @@ -1,10 +1,13 @@ using System; using ASC.Api.Core; -using ASC.Common; +using ASC.Common; +using ASC.Common.DependencyInjection; using ASC.Data.Backup.Controllers; using ASC.Data.Backup.Service; +using Autofac; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -29,6 +32,11 @@ namespace ASC.Data.Backup .AddProgressQueue(1, (int)TimeSpan.FromMinutes(5).TotalMilliseconds, true, false, 0); services.AddHostedService(); + } + + public void ConfigureContainer(ContainerBuilder builder) + { + builder.Register(Configuration, HostEnvironment.ContentRootPath); } } } diff --git a/common/services/ASC.Data.Storage.Encryption/Program.cs b/common/services/ASC.Data.Storage.Encryption/Program.cs index 070dc94a28..e6d62c73a5 100644 --- a/common/services/ASC.Data.Storage.Encryption/Program.cs +++ b/common/services/ASC.Data.Storage.Encryption/Program.cs @@ -24,8 +24,10 @@ */ using System.Collections.Generic; using System.IO; -using System.Threading.Tasks; - +using System.Threading.Tasks; + +using Autofac.Extensions.DependencyInjection; + using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -36,7 +38,8 @@ namespace ASC.Data.Storage.Encryption { public static async Task Main(string[] args) { - await Host.CreateDefaultBuilder(args) + await Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/common/services/ASC.Data.Storage.Encryption/Startup.cs b/common/services/ASC.Data.Storage.Encryption/Startup.cs index 40c322fe65..3211429217 100644 --- a/common/services/ASC.Data.Storage.Encryption/Startup.cs +++ b/common/services/ASC.Data.Storage.Encryption/Startup.cs @@ -24,10 +24,10 @@ */ using ASC.Api.Core; -using ASC.Common; -using ASC.Common.DependencyInjection; +using ASC.Common; +using ASC.Common.DependencyInjection; -using Autofac.Extensions.DependencyInjection; +using Autofac; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -51,8 +51,11 @@ namespace ASC.Data.Storage.Encryption DIHelper.AddEncryptionServiceLauncher(); services.AddHostedService(); - - services.AddAutofac(Configuration, HostEnvironment.ContentRootPath); + } + + public void ConfigureContainer(ContainerBuilder builder) + { + builder.Register(Configuration, HostEnvironment.ContentRootPath); } } } diff --git a/common/services/ASC.Data.Storage.Migration/Program.cs b/common/services/ASC.Data.Storage.Migration/Program.cs index 0af05cae85..b7affccbe0 100644 --- a/common/services/ASC.Data.Storage.Migration/Program.cs +++ b/common/services/ASC.Data.Storage.Migration/Program.cs @@ -5,8 +5,10 @@ using System.Threading.Tasks; using ASC.Common; using ASC.Common.DependencyInjection; using ASC.Common.Logging; -using ASC.Core.Common; - + +using Autofac; +using Autofac.Extensions.DependencyInjection; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -17,7 +19,8 @@ namespace ASC.Data.Storage.Migration { public static async Task Main(string[] args) { - await Host.CreateDefaultBuilder(args) + await Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureAppConfiguration((hostContext, config) => { var buided = config.Build(); @@ -52,8 +55,10 @@ namespace ASC.Data.Storage.Migration diHelper.AddMigrationServiceLauncher(); services.AddHostedService(); - - services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); + }) + .ConfigureContainer((context, builder) => + { + builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath); }) .UseConsoleLifetime() .Build() diff --git a/common/services/ASC.ElasticSearch/Engine/FactoryIndexer.cs b/common/services/ASC.ElasticSearch/Engine/FactoryIndexer.cs index 1ea1c2e93e..df4b32dff3 100644 --- a/common/services/ASC.ElasticSearch/Engine/FactoryIndexer.cs +++ b/common/services/ASC.ElasticSearch/Engine/FactoryIndexer.cs @@ -461,18 +461,9 @@ namespace ASC.ElasticSearch FactoryIndexerHelper factoryIndexerHelper, Client client, IOptionsMonitor options, - CoreBaseSettings coreBaseSettings) : this(null, factoryIndexerHelper, client, options, coreBaseSettings) - { - Builder = container; - } - - public FactoryIndexer( - IContainer container, - FactoryIndexerHelper factoryIndexerHelper, - Client client, - IOptionsMonitor options, CoreBaseSettings coreBaseSettings) { + Builder = container; FactoryIndexerHelper = factoryIndexerHelper; Client = client; CoreBaseSettings = coreBaseSettings; diff --git a/common/services/ASC.ElasticSearch/Service/Launcher.cs b/common/services/ASC.ElasticSearch/Service/Launcher.cs index fbae991c5b..b56d3051f5 100644 --- a/common/services/ASC.ElasticSearch/Service/Launcher.cs +++ b/common/services/ASC.ElasticSearch/Service/Launcher.cs @@ -48,7 +48,7 @@ namespace ASC.ElasticSearch private ICacheNotify Notify { get; } private ICacheNotify IndexNotify { get; } private IServiceProvider ServiceProvider { get; } - public IContainer Container { get; } + public ILifetimeScope Container { get; } private bool IsStarted { get; set; } private CancellationTokenSource CancellationTokenSource { get; set; } private Timer Timer { get; set; } @@ -59,7 +59,7 @@ namespace ASC.ElasticSearch ICacheNotify notify, ICacheNotify indexNotify, IServiceProvider serviceProvider, - IContainer container, + ILifetimeScope container, Settings settings) { Log = options.Get("ASC.Indexer"); diff --git a/common/services/ASC.ElasticSearch/Service/Service.cs b/common/services/ASC.ElasticSearch/Service/Service.cs index 95979d6222..58e6ccec3a 100644 --- a/common/services/ASC.ElasticSearch/Service/Service.cs +++ b/common/services/ASC.ElasticSearch/Service/Service.cs @@ -42,11 +42,11 @@ namespace ASC.ElasticSearch.Service { public class Service { - public IContainer Container { get; } + private ILifetimeScope Container { get; } private IServiceProvider ServiceProvider { get; } private ICacheNotify CacheNotify { get; } - public Service(IContainer container, IServiceProvider serviceProvider, ICacheNotify cacheNotify) + public Service(ILifetimeScope container, IServiceProvider serviceProvider, ICacheNotify cacheNotify) { Container = container; ServiceProvider = serviceProvider; diff --git a/common/services/ASC.Feed.Aggregator/Service/FeedAggregatorService.cs b/common/services/ASC.Feed.Aggregator/Service/FeedAggregatorService.cs index 3dbabf6736..df9fbf473d 100644 --- a/common/services/ASC.Feed.Aggregator/Service/FeedAggregatorService.cs +++ b/common/services/ASC.Feed.Aggregator/Service/FeedAggregatorService.cs @@ -63,12 +63,12 @@ namespace ASC.Feed.Aggregator private IConfiguration Configuration { get; } private IServiceProvider ServiceProvider { get; } - public IContainer Container { get; } + public ILifetimeScope Container { get; } public FeedAggregatorService( IConfiguration configuration, IServiceProvider serviceProvider, - IContainer container, + ILifetimeScope container, IOptionsMonitor optionsMonitor, SignalrServiceClient signalrServiceClient, IConfigureNamedOptions configureOptions) diff --git a/common/services/ASC.Notify/NotifyServiceLauncher.cs b/common/services/ASC.Notify/NotifyServiceLauncher.cs index 582bfa3d58..7e9abc310c 100644 --- a/common/services/ASC.Notify/NotifyServiceLauncher.cs +++ b/common/services/ASC.Notify/NotifyServiceLauncher.cs @@ -31,7 +31,6 @@ using System.Threading.Tasks; using ASC.Common; using ASC.Common.Logging; -using ASC.Core.Common; using ASC.Notify.Config; using ASC.Web.Core; using ASC.Web.Studio.Core.Notify; diff --git a/common/services/ASC.Notify/Program.cs b/common/services/ASC.Notify/Program.cs index bfa808616f..a1bdc73614 100644 --- a/common/services/ASC.Notify/Program.cs +++ b/common/services/ASC.Notify/Program.cs @@ -5,11 +5,13 @@ using System.Threading.Tasks; using ASC.Common; using ASC.Common.DependencyInjection; using ASC.Common.Logging; -using ASC.Core.Common; using ASC.Core.Notify; using ASC.Core.Notify.Senders; using ASC.Notify.Config; +using Autofac; +using Autofac.Extensions.DependencyInjection; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -22,6 +24,7 @@ namespace ASC.Notify public static async Task Main(string[] args) { var host = Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureAppConfiguration((hostContext, config) => { var buided = config.Build(); @@ -65,8 +68,10 @@ namespace ASC.Notify .AddSmtpSenderService() .AddAWSSenderService() .AddEmailSenderSinkService(); - - services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); + }) + .ConfigureContainer((context, builder) => + { + builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath); }) .UseConsoleLifetime() .Build(); diff --git a/common/services/ASC.Socket.IO.Svc/Program.cs b/common/services/ASC.Socket.IO.Svc/Program.cs index 681549493a..adb11a6818 100644 --- a/common/services/ASC.Socket.IO.Svc/Program.cs +++ b/common/services/ASC.Socket.IO.Svc/Program.cs @@ -28,10 +28,13 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; -using ASC.Common; +using ASC.Common; using ASC.Common.DependencyInjection; -using ASC.Common.Logging; - +using ASC.Common.Logging; + +using Autofac; +using Autofac.Extensions.DependencyInjection; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -43,7 +46,8 @@ namespace ASC.Socket.IO.Svc { public static async Task Main(string[] args) { - var host = Host.CreateDefaultBuilder(args) + var host = Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureAppConfiguration((hostContext, config) => { var buided = config.Build(); @@ -77,8 +81,10 @@ namespace ASC.Socket.IO.Svc diHelper.AddNLogManager("ASC.Socket.IO.Svc"); services.AddHostedService(); diHelper.AddSocketServiceLauncher(); - - services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath, false, false); + }) + .ConfigureContainer((context, builder) => + { + builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath, false, false); }) .UseConsoleLifetime() .Build(); diff --git a/common/services/ASC.Socket.IO.Svc/SocketServiceLauncher.cs b/common/services/ASC.Socket.IO.Svc/SocketServiceLauncher.cs index a9fa9c519f..e9d013e0e7 100644 --- a/common/services/ASC.Socket.IO.Svc/SocketServiceLauncher.cs +++ b/common/services/ASC.Socket.IO.Svc/SocketServiceLauncher.cs @@ -40,8 +40,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; -using WebSocketSharp; - namespace ASC.Socket.IO.Svc { public class SocketServiceLauncher : IHostedService diff --git a/common/services/ASC.Studio.Notify/Program.cs b/common/services/ASC.Studio.Notify/Program.cs index 42ed7b685a..3f3c65ee01 100644 --- a/common/services/ASC.Studio.Notify/Program.cs +++ b/common/services/ASC.Studio.Notify/Program.cs @@ -8,6 +8,9 @@ using ASC.Common.Logging; using ASC.Core.Notify; using ASC.Notify; +using Autofac; +using Autofac.Extensions.DependencyInjection; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -19,6 +22,7 @@ namespace ASC.Studio.Notify public static async Task Main(string[] args) { var host = Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureAppConfiguration((hostContext, config) => { var buided = config.Build(); @@ -52,7 +56,10 @@ namespace ASC.Studio.Notify services.AddHostedService(); diHelper.AddServiceLauncher(); diHelper.AddEmailSenderSinkService(); - services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath); + }) + .ConfigureContainer((context, builder) => + { + builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath); }) .UseConsoleLifetime() .Build(); diff --git a/common/services/ASC.TelegramService/Program.cs b/common/services/ASC.TelegramService/Program.cs index 3275941e2f..cfb8535526 100644 --- a/common/services/ASC.TelegramService/Program.cs +++ b/common/services/ASC.TelegramService/Program.cs @@ -24,8 +24,10 @@ */ using System.Collections.Generic; using System.IO; -using System.Threading.Tasks; - +using System.Threading.Tasks; + +using Autofac.Extensions.DependencyInjection; + using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -36,7 +38,8 @@ namespace ASC.TelegramService { public static async Task Main(string[] args) { - await Host.CreateDefaultBuilder(args) + await Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/common/services/ASC.TelegramService/Startup.cs b/common/services/ASC.TelegramService/Startup.cs index 7b5190bf98..cb4b9fec83 100644 --- a/common/services/ASC.TelegramService/Startup.cs +++ b/common/services/ASC.TelegramService/Startup.cs @@ -25,9 +25,9 @@ using ASC.Api.Core; using ASC.Common; -using ASC.Common.DependencyInjection; +using ASC.Common.DependencyInjection; -using Autofac.Extensions.DependencyInjection; +using Autofac; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -51,8 +51,11 @@ namespace ASC.TelegramService DIHelper.AddTelegramLauncher(); services.AddHostedService(); - - services.AddAutofac(Configuration, HostEnvironment.ContentRootPath); + } + + public void ConfigureContainer(ContainerBuilder builder) + { + builder.Register(Configuration, HostEnvironment.ContentRootPath); } } } diff --git a/common/services/ASC.Thumbnails.Svc/Program.cs b/common/services/ASC.Thumbnails.Svc/Program.cs index 4472a63b0f..6a151249ce 100644 --- a/common/services/ASC.Thumbnails.Svc/Program.cs +++ b/common/services/ASC.Thumbnails.Svc/Program.cs @@ -27,11 +27,14 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; - + using ASC.Common; -using ASC.Common.DependencyInjection; -using ASC.Common.Logging; - +using ASC.Common.DependencyInjection; +using ASC.Common.Logging; + +using Autofac; +using Autofac.Extensions.DependencyInjection; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -43,7 +46,8 @@ namespace ASC.Thumbnails.Svc { public static async Task Main(string[] args) { - var host = Host.CreateDefaultBuilder(args) + var host = Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureAppConfiguration((hostContext, config) => { var buided = config.Build(); @@ -76,8 +80,10 @@ namespace ASC.Thumbnails.Svc diHelper.AddNLogManager("ASC.Thumbnails.Svc"); services.AddHostedService(); diHelper.AddThumbnailsServiceLauncher(); - - services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath, false, false); + }) + .ConfigureContainer((context, builder) => + { + builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath, false, false); }) .UseConsoleLifetime() .Build(); diff --git a/common/services/ASC.UrlShortener.Svc/Program.cs b/common/services/ASC.UrlShortener.Svc/Program.cs index 3002857ac8..eaaf6a3a99 100644 --- a/common/services/ASC.UrlShortener.Svc/Program.cs +++ b/common/services/ASC.UrlShortener.Svc/Program.cs @@ -28,10 +28,13 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; -using ASC.Common; +using ASC.Common; using ASC.Common.DependencyInjection; -using ASC.Common.Logging; - +using ASC.Common.Logging; + +using Autofac; +using Autofac.Extensions.DependencyInjection; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -43,7 +46,8 @@ namespace ASC.UrlShortener.Svc { public static async Task Main(string[] args) { - var host = Host.CreateDefaultBuilder(args) + var host = Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureAppConfiguration((hostContext, config) => { var buided = config.Build(); @@ -75,8 +79,10 @@ namespace ASC.UrlShortener.Svc diHelper.AddNLogManager("ASC.UrlShortener.Svc"); services.AddHostedService(); diHelper.AddUrlShortenerServiceLauncher(); - - services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath, false, false); + }) + .ConfigureContainer((context, builder) => + { + builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath, false, false); }) .UseConsoleLifetime() .Build(); diff --git a/products/ASC.Files/Client/public/index.html b/products/ASC.Files/Client/public/index.html index 8e4c8301f8..0b5b2d7839 100644 --- a/products/ASC.Files/Client/public/index.html +++ b/products/ASC.Files/Client/public/index.html @@ -19,7 +19,7 @@ - + (); - DropboxLoginProvider = ConsumerFactory.Get(); - GoogleLoginProvider = ConsumerFactory.Get(); - OneDriveLoginProvider = ConsumerFactory.Get(); MessageService = messageService; CommonLinkUtility = commonLinkUtility; DocumentServiceConnector = documentServiceConnector; @@ -1357,19 +1349,25 @@ namespace ASC.Api.Documents if (ThirdpartyConfiguration.SupportBoxInclusion) { - result.Add(new List { "Box", BoxLoginProvider.ClientID, BoxLoginProvider.RedirectUri }); + var boxLoginProvider = ConsumerFactory.Get(); + result.Add(new List { "Box", boxLoginProvider.ClientID, boxLoginProvider.RedirectUri }); } if (ThirdpartyConfiguration.SupportDropboxInclusion) { - result.Add(new List { "DropboxV2", DropboxLoginProvider.ClientID, DropboxLoginProvider.RedirectUri }); + var dropboxLoginProvider = ConsumerFactory.Get(); + result.Add(new List { "DropboxV2", dropboxLoginProvider.ClientID, dropboxLoginProvider.RedirectUri }); } + if (ThirdpartyConfiguration.SupportGoogleDriveInclusion) { - result.Add(new List { "GoogleDrive", GoogleLoginProvider.ClientID, GoogleLoginProvider.RedirectUri }); + var googleLoginProvider = ConsumerFactory.Get(); + result.Add(new List { "GoogleDrive", googleLoginProvider.ClientID, googleLoginProvider.RedirectUri }); } + if (ThirdpartyConfiguration.SupportOneDriveInclusion) { - result.Add(new List { "OneDrive", OneDriveLoginProvider.ClientID, OneDriveLoginProvider.RedirectUri }); + var oneDriveLoginProvider = ConsumerFactory.Get(); + result.Add(new List { "OneDrive", oneDriveLoginProvider.ClientID, oneDriveLoginProvider.RedirectUri }); } if (ThirdpartyConfiguration.SupportSharePointInclusion) { diff --git a/products/ASC.Files/Server/Program.cs b/products/ASC.Files/Server/Program.cs index 17a9c346c6..6fc50dd18c 100644 --- a/products/ASC.Files/Server/Program.cs +++ b/products/ASC.Files/Server/Program.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.IO; +using Autofac.Extensions.DependencyInjection; + using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -17,6 +19,7 @@ namespace ASC.Files public static IHostBuilder CreateHostBuilder(string[] args) { return Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/products/ASC.Files/Server/Startup.cs b/products/ASC.Files/Server/Startup.cs index e6786ff0fe..9991949bab 100644 --- a/products/ASC.Files/Server/Startup.cs +++ b/products/ASC.Files/Server/Startup.cs @@ -1,4 +1,3 @@ -using System.Linq; using System.Text; using System.Text.Json.Serialization; diff --git a/products/ASC.Files/Service/Program.cs b/products/ASC.Files/Service/Program.cs index 5c788e0b1d..af06593cda 100644 --- a/products/ASC.Files/Service/Program.cs +++ b/products/ASC.Files/Service/Program.cs @@ -11,6 +11,9 @@ using ASC.Feed.Aggregator; using ASC.Web.Files.Core.Search; using ASC.Web.Files.Utils; +using Autofac; +using Autofac.Extensions.DependencyInjection; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -22,6 +25,7 @@ namespace ASC.Files.Service public static async Task Main(string[] args) { var host = Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureAppConfiguration((hostContext, config) => { var buided = config.Build(); @@ -65,8 +69,10 @@ namespace ASC.Files.Service services.AddHostedService(); diHelper .AddFeedAggregatorService(); - - services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath, true, false, "search.json", "feed.json"); + }) + .ConfigureContainer((context, builder) => + { + builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath, true, false, "search.json", "feed.json"); }) .UseConsoleLifetime() .Build(); diff --git a/products/ASC.People/Client/public/index.html b/products/ASC.People/Client/public/index.html index 8e4c8301f8..0b5b2d7839 100644 --- a/products/ASC.People/Client/public/index.html +++ b/products/ASC.People/Client/public/index.html @@ -19,7 +19,7 @@ - + { webBuilder.UseStartup(); diff --git a/products/ASC.People/Server/Startup.cs b/products/ASC.People/Server/Startup.cs index ed3d01ef07..a203efdc33 100644 --- a/products/ASC.People/Server/Startup.cs +++ b/products/ASC.People/Server/Startup.cs @@ -2,11 +2,14 @@ using System; using ASC.Api.Core; -using ASC.Common; +using ASC.Common; +using ASC.Common.DependencyInjection; using ASC.Data.Reassigns; using ASC.Employee.Core.Controllers; using ASC.Web.Core.Users; +using Autofac; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -33,6 +36,11 @@ namespace ASC.People DIHelper .AddPeopleController() .AddGroupController(); + } + + public void ConfigureContainer(ContainerBuilder builder) + { + builder.Register(Configuration, HostEnvironment.ContentRootPath); } } } \ No newline at end of file diff --git a/web/ASC.Web.Api/Controllers/CapabilitiesController.cs b/web/ASC.Web.Api/Controllers/CapabilitiesController.cs index 09c08b2219..69073a8dc6 100644 --- a/web/ASC.Web.Api/Controllers/CapabilitiesController.cs +++ b/web/ASC.Web.Api/Controllers/CapabilitiesController.cs @@ -2,14 +2,12 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Web; using ASC.Common.Logging; using ASC.Core; using ASC.Core.Common.Settings; -using ASC.FederatedLogin; using ASC.FederatedLogin.LoginProviders; using ASC.Web.Api.Models; using ASC.Web.Api.Routing; diff --git a/web/ASC.Web.Api/Controllers/PortalController.cs b/web/ASC.Web.Api/Controllers/PortalController.cs index 80e4a593f4..f3e006428c 100644 --- a/web/ASC.Web.Api/Controllers/PortalController.cs +++ b/web/ASC.Web.Api/Controllers/PortalController.cs @@ -8,7 +8,6 @@ using ASC.Common; using ASC.Common.Logging; using ASC.Core; using ASC.Core.Billing; -using ASC.Core.Common.Notify.Push; using ASC.Core.Common.Settings; using ASC.Core.Tenants; using ASC.Core.Users; diff --git a/web/ASC.Web.Api/Controllers/SettingsController.cs b/web/ASC.Web.Api/Controllers/SettingsController.cs index fda8a6bc5c..5b492428e9 100644 --- a/web/ASC.Web.Api/Controllers/SettingsController.cs +++ b/web/ASC.Web.Api/Controllers/SettingsController.cs @@ -351,7 +351,7 @@ namespace ASC.Api.Settings MessageService.Send(MessageAction.AdministratorMessageSettingsUpdated); - return Resource.SuccessfullySaveSettingsMessage; + return Resource.SuccessfullySaveSettingsMessage; } [AllowAnonymous] @@ -446,23 +446,23 @@ namespace ASC.Api.Settings switch (Tenant.TrustedDomainsType) { case TenantTrustedDomainsType.Custom: - { - var address = new MailAddress(email); - if (Tenant.TrustedDomains.Any(d => address.Address.EndsWith("@" + d, StringComparison.InvariantCultureIgnoreCase))) - { - StudioNotifyService.SendJoinMsg(email, emplType); - MessageService.Send(MessageInitiator.System, MessageAction.SentInviteInstructions, email); - return Resource.FinishInviteJoinEmailMessage; - } - - throw new Exception(Resource.ErrorEmailDomainNotAllowed); - } - case TenantTrustedDomainsType.All: + { + var address = new MailAddress(email); + if (Tenant.TrustedDomains.Any(d => address.Address.EndsWith("@" + d, StringComparison.InvariantCultureIgnoreCase))) { StudioNotifyService.SendJoinMsg(email, emplType); MessageService.Send(MessageInitiator.System, MessageAction.SentInviteInstructions, email); - return Resource.FinishInviteJoinEmailMessage ; + return Resource.FinishInviteJoinEmailMessage; } + + throw new Exception(Resource.ErrorEmailDomainNotAllowed); + } + case TenantTrustedDomainsType.All: + { + StudioNotifyService.SendJoinMsg(email, emplType); + MessageService.Send(MessageInitiator.System, MessageAction.SentInviteInstructions, email); + return Resource.FinishInviteJoinEmailMessage; + } default: throw new Exception(Resource.ErrorNotCorrectEmail); } diff --git a/web/ASC.Web.Api/Models/CapabilitiesData.cs b/web/ASC.Web.Api/Models/CapabilitiesData.cs index 86cebca6eb..3dbf0b6e48 100644 --- a/web/ASC.Web.Api/Models/CapabilitiesData.cs +++ b/web/ASC.Web.Api/Models/CapabilitiesData.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; namespace ASC.Web.Api.Models { diff --git a/web/ASC.Web.Api/Program.cs b/web/ASC.Web.Api/Program.cs index 4b9a18a4a5..94de58fa19 100644 --- a/web/ASC.Web.Api/Program.cs +++ b/web/ASC.Web.Api/Program.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.IO; +using Autofac.Extensions.DependencyInjection; + using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -18,6 +20,7 @@ namespace ASC.Web.Api public static IHostBuilder CreateHostBuilder(string[] args) { return Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/web/ASC.Web.Api/Startup.cs b/web/ASC.Web.Api/Startup.cs index 5998567c6e..5160e18f8b 100644 --- a/web/ASC.Web.Api/Startup.cs +++ b/web/ASC.Web.Api/Startup.cs @@ -3,9 +3,9 @@ using ASC.Api.Core; using ASC.Api.Settings; using ASC.Common; using ASC.Common.DependencyInjection; -using ASC.Web.Api.Controllers; +using ASC.Web.Api.Controllers; -using Autofac.Extensions.DependencyInjection; +using Autofac; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -27,7 +27,9 @@ namespace ASC.Web.Api { base.ConfigureServices(services); - services.AddMemoryCache(); + services.AddMemoryCache(); + + services.AddOptions(); DIHelper .AddAuthenticationController() @@ -35,10 +37,12 @@ namespace ASC.Web.Api .AddPortalController() .AddSettingsController() .AddSecurityController() - .AddSmtpSettingsController(); - - services.AddAutofac(Configuration, HostEnvironment.ContentRootPath); - + .AddSmtpSettingsController(); + } + + public void ConfigureContainer(ContainerBuilder builder) + { + builder.Register(Configuration, HostEnvironment.ContentRootPath); } } } diff --git a/web/ASC.Web.Client/public/index.html b/web/ASC.Web.Client/public/index.html index a4661232b3..b1b47bff65 100644 --- a/web/ASC.Web.Client/public/index.html +++ b/web/ASC.Web.Client/public/index.html @@ -19,7 +19,7 @@ - + options) + public WebItemManager(ILifetimeScope container, IConfiguration configuration, IOptionsMonitor options) { Container = container; Configuration = configuration; @@ -126,13 +126,6 @@ namespace ASC.Web.Core LoadItems(); } - public WebItemManager(ILifetimeScope container, IConfiguration configuration, IOptionsMonitor options) - : this(null, configuration, options) - { - Container = container; - LoadItems(); - } - public void LoadItems() { if (Container == null) return; diff --git a/web/ASC.Web.Studio/Program.cs b/web/ASC.Web.Studio/Program.cs index f8d099fc6b..6c13dac559 100644 --- a/web/ASC.Web.Studio/Program.cs +++ b/web/ASC.Web.Studio/Program.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.IO; +using Autofac.Extensions.DependencyInjection; + using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -17,6 +19,7 @@ namespace ASC.Web.Studio public static IHostBuilder CreateWebHostBuilder(string[] args) { return Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(w => { w.UseStartup(); @@ -33,7 +36,7 @@ namespace ASC.Web.Studio config .AddInMemoryCollection(new Dictionary { - {"pathToConf", path} + {"pathToConf", path} }) .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true) diff --git a/web/ASC.Web.Studio/Startup.cs b/web/ASC.Web.Studio/Startup.cs index b106b1fba2..3eb5cceee0 100644 --- a/web/ASC.Web.Studio/Startup.cs +++ b/web/ASC.Web.Studio/Startup.cs @@ -6,6 +6,8 @@ using ASC.Data.Storage.Configuration; using ASC.Data.Storage.DiscStorage; using ASC.FederatedLogin; +using Autofac; + using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpOverrides; @@ -37,15 +39,16 @@ namespace ASC.Web.Studio .AddStorageHandlerService() .AddLoginHandlerService(); - services.AddMemoryCache(); + services.AddMemoryCache(); + } - - services.AddAutofac(Configuration, HostEnvironment.ContentRootPath); - } + public void ConfigureContainer(ContainerBuilder builder) + { + builder.Register(Configuration, HostEnvironment.ContentRootPath); + } public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto