diff --git a/common/ASC.Api.Core/Model/EmployeeWraper.cs b/common/ASC.Api.Core/Model/EmployeeWraper.cs index 4204226140..333e028265 100644 --- a/common/ASC.Api.Core/Model/EmployeeWraper.cs +++ b/common/ASC.Api.Core/Model/EmployeeWraper.cs @@ -27,7 +27,6 @@ using System; using System.Runtime.Serialization; using ASC.Api.Core; -using ASC.Core; using ASC.Core.Users; using ASC.Web.Core.Users; using ASC.Web.Studio.Utility; diff --git a/common/ASC.Common/Caching/KafkaCache.cs b/common/ASC.Common/Caching/KafkaCache.cs index 70181b778f..ccf5a13e4f 100644 --- a/common/ASC.Common/Caching/KafkaCache.cs +++ b/common/ASC.Common/Caching/KafkaCache.cs @@ -3,7 +3,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; - using ASC.Common.Logging; using ASC.Common.Utils; using Confluent.Kafka; diff --git a/common/ASC.Common/Data/DbManager.cs b/common/ASC.Common/Data/DbManager.cs index 4d664462c4..3dd7324e51 100644 --- a/common/ASC.Common/Data/DbManager.cs +++ b/common/ASC.Common/Data/DbManager.cs @@ -67,9 +67,9 @@ namespace ASC.Common.Data } public class ConfigureDbManager : IConfigureNamedOptions { - public DbRegistry DbRegistry { get; } - public IOptionsMonitor Option { get; } - public IHttpContextAccessor HttpContextAccessor { get; } + private DbRegistry DbRegistry { get; } + private IOptionsMonitor Option { get; } + private IHttpContextAccessor HttpContextAccessor { get; } public ConfigureDbManager(DbRegistry dbRegistry, IOptionsMonitor option) { diff --git a/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs b/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs index 2746ee63c7..47555b00b5 100644 --- a/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs +++ b/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs @@ -45,8 +45,8 @@ namespace ASC.Common.Utils private Dictionary _translations; - public IConfiguration Configuration { get; } - public ILog Log { get; } + private IConfiguration Configuration { get; } + private ILog Log { get; } public TimeZoneConverter(IConfiguration configuration, IOptionsMonitor option) { diff --git a/common/ASC.Core.Common/Billing/TariffService.cs b/common/ASC.Core.Common/Billing/TariffService.cs index 30851f6916..9169895c67 100644 --- a/common/ASC.Core.Common/Billing/TariffService.cs +++ b/common/ASC.Core.Common/Billing/TariffService.cs @@ -40,6 +40,7 @@ using ASC.Common.Logging; using ASC.Core.Data; using ASC.Core.Tenants; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace ASC.Core.Billing @@ -605,5 +606,15 @@ client.GetPaymentUrls(null, products, !string.IsNullOrEmpty(affiliateId) ? affil } } } + } + + public static class TariffConfigFactory + { + public static IServiceCollection AddTariffService(this IServiceCollection services) + { + return services + .AddSingleton() + .AddScoped(); + } } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Caching/CachedAzService.cs b/common/ASC.Core.Common/Caching/CachedAzService.cs index 57ba4cdbea..64b74742a4 100644 --- a/common/ASC.Core.Common/Caching/CachedAzService.cs +++ b/common/ASC.Core.Common/Caching/CachedAzService.cs @@ -28,13 +28,14 @@ using System; using System.Collections.Generic; using ASC.Common.Caching; using ASC.Core.Data; +using Microsoft.Extensions.DependencyInjection; namespace ASC.Core.Caching { - public class AzServiceCache + class AzServiceCache { - public ICache Cache { get; } - public ICacheNotify CacheNotify { get; } + internal ICache Cache { get; } + internal ICacheNotify CacheNotify { get; } public AzServiceCache(ICacheNotify cacheNotify) { @@ -70,15 +71,15 @@ namespace ASC.Core.Caching } } - public class CachedAzService : IAzService + class CachedAzService : IAzService { private readonly IAzService service; private readonly ICacheNotify cacheNotify; - public ICache Cache { get; } + private ICache Cache { get; } - public TimeSpan CacheExpiration { get; set; } + private TimeSpan CacheExpiration { get; set; } public CachedAzService(DbAzService service, AzServiceCache azServiceCache) @@ -114,5 +115,16 @@ namespace ASC.Core.Caching service.RemoveAce(tenant, r); cacheNotify.Publish(r, CacheNotifyAction.Remove); } - } + } + + public static class AzConfigFactory + { + public static IServiceCollection AddAzService(this IServiceCollection services) + { + return services.AddScoped() + .AddScoped() + .AddSingleton() + .AddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>)); + } + } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Caching/CachedQuotaService.cs b/common/ASC.Core.Common/Caching/CachedQuotaService.cs index e347aef9bd..bbd6dcd89b 100644 --- a/common/ASC.Core.Common/Caching/CachedQuotaService.cs +++ b/common/ASC.Core.Common/Caching/CachedQuotaService.cs @@ -31,19 +31,20 @@ using ASC.Common.Caching; using ASC.Core.Data; using ASC.Core.Tenants; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace ASC.Core.Caching { - public class QuotaServiceCache + class QuotaServiceCache { internal const string KEY_QUOTA = "quota"; internal const string KEY_QUOTA_ROWS = "quotarows"; - public TrustInterval Interval { get; set; } - public ICache Cache { get; } - public ICacheNotify CacheNotify { get; } + internal TrustInterval Interval { get; set; } + internal ICache Cache { get; } + internal ICacheNotify CacheNotify { get; } - public bool QuotaCacheEnabled { get; } + internal bool QuotaCacheEnabled { get; } public QuotaServiceCache(IConfiguration Configuration, ICacheNotify cacheNotify) { @@ -74,15 +75,15 @@ namespace ASC.Core.Caching } } - public class CachedQuotaService : IQuotaService + class CachedQuotaService : IQuotaService { private readonly IQuotaService service; private readonly ICache cache; private readonly ICacheNotify cacheNotify; private readonly TrustInterval interval; - public TimeSpan CacheExpiration { get; set; } - public QuotaServiceCache QuotaServiceCache { get; } + private TimeSpan CacheExpiration { get; set; } + private QuotaServiceCache QuotaServiceCache { get; } public CachedQuotaService(DbQuotaService service, QuotaServiceCache quotaServiceCache) { @@ -200,5 +201,17 @@ namespace ASC.Core.Caching return list.ToList(); } } + } + + public static class QuotaConfigFactory + { + public static IServiceCollection AddQuotaService(this IServiceCollection services) + { + return services + .AddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>)) + .AddSingleton() + .AddScoped() + .AddScoped(); + } } } diff --git a/common/ASC.Core.Common/Caching/CachedSubscriptionService.cs b/common/ASC.Core.Common/Caching/CachedSubscriptionService.cs index 03ab1d45c4..734639399c 100644 --- a/common/ASC.Core.Common/Caching/CachedSubscriptionService.cs +++ b/common/ASC.Core.Common/Caching/CachedSubscriptionService.cs @@ -29,14 +29,15 @@ using System.Collections.Generic; using System.Linq; using ASC.Common.Caching; using ASC.Core.Data; +using Microsoft.Extensions.DependencyInjection; namespace ASC.Core.Caching { - public class SubscriptionServiceCache + class SubscriptionServiceCache { - public ICache Cache { get; } - public ICacheNotify NotifyRecord { get; } - public ICacheNotify NotifyMethod { get; } + internal ICache Cache { get; } + internal ICacheNotify NotifyRecord { get; } + internal ICacheNotify NotifyMethod { get; } public SubscriptionServiceCache(ICacheNotify notifyRecord, ICacheNotify notifyMethod) { @@ -99,14 +100,14 @@ namespace ASC.Core.Caching } } - public class CachedSubscriptionService : ISubscriptionService + class CachedSubscriptionService : ISubscriptionService { private readonly ISubscriptionService service; private readonly ICache cache; private readonly ICacheNotify notifyRecord; private readonly ICacheNotify notifyMethod; - public TimeSpan CacheExpiration { get; set; } + private TimeSpan CacheExpiration { get; set; } public CachedSubscriptionService(DbSubscriptionService service, SubscriptionServiceCache subscriptionServiceCache) { @@ -281,5 +282,17 @@ namespace ASC.Core.Caching { methodsByRec = methods.GroupBy(r => r.RecipientId).ToDictionary(g => g.Key, g => g.ToList()); } + } + + public static class SubscriptionConfigFactory + { + public static IServiceCollection AddSubscriptionService(this IServiceCollection services) + { + return services + .AddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>)) + .AddScoped() + .AddScoped() + .AddSingleton(); + } } } diff --git a/common/ASC.Core.Common/Caching/CachedTenantService.cs b/common/ASC.Core.Common/Caching/CachedTenantService.cs index d7ce0d91a6..a5bc50bded 100644 --- a/common/ASC.Core.Common/Caching/CachedTenantService.cs +++ b/common/ASC.Core.Common/Caching/CachedTenantService.cs @@ -28,18 +28,20 @@ using System; using System.Collections.Generic; using ASC.Common.Caching; +using ASC.Common.Utils; using ASC.Core.Data; -using ASC.Core.Tenants; - +using ASC.Core.Tenants; +using Microsoft.Extensions.DependencyInjection; + namespace ASC.Core.Caching { - public class TenantServiceCache + class TenantServiceCache { private const string KEY = "tenants"; - public TimeSpan CacheExpiration { get; set; } - public ICache Cache { get; } - public ICacheNotify CacheNotifyItem { get; } - public ICacheNotify CacheNotifySettings { get; } + private TimeSpan CacheExpiration { get; set; } + internal ICache Cache { get; } + internal ICacheNotify CacheNotifyItem { get; } + internal ICacheNotify CacheNotifySettings { get; } public TenantServiceCache(CoreBaseSettings coreBaseSettings, ICacheNotify cacheNotifyItem, ICacheNotify cacheNotifySettings) { @@ -147,15 +149,15 @@ namespace ASC.Core.Caching } } - public class CachedTenantService : ITenantService + class CachedTenantService : ITenantService { private readonly ITenantService service; private readonly ICache cache; private readonly ICacheNotify cacheNotifySettings; private readonly ICacheNotify cacheNotifyItem; - public TimeSpan SettingsExpiration { get; set; } - public TenantServiceCache TenantServiceCache { get; } + private TimeSpan SettingsExpiration { get; set; } + private TenantServiceCache TenantServiceCache { get; } public CachedTenantService(DbTenantService service, TenantServiceCache tenantServiceCache) { @@ -265,5 +267,20 @@ namespace ASC.Core.Caching var cacheKey = string.Format("settings/{0}/{1}", tenant, key); cacheNotifySettings.Publish(new TenantSetting { Key = cacheKey }, CacheNotifyAction.Remove); } + } + + public static class TenantConfigFactory + { + public static IServiceCollection AddTenantService(this IServiceCollection services) + { + return services + .AddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>)) + .AddCoreBaseSettingsService() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddScoped() + .AddScoped(); + } } } diff --git a/common/ASC.Core.Common/Caching/CachedUserService.cs b/common/ASC.Core.Common/Caching/CachedUserService.cs index 985af166cd..1371ba6f24 100644 --- a/common/ASC.Core.Common/Caching/CachedUserService.cs +++ b/common/ASC.Core.Common/Caching/CachedUserService.cs @@ -31,11 +31,12 @@ using System.Threading; using ASC.Common.Caching; using ASC.Core.Data; using ASC.Core.Tenants; -using ASC.Core.Users; - +using ASC.Core.Users; +using Microsoft.Extensions.DependencyInjection; + namespace ASC.Core.Caching { - public class UserServiceCache + class UserServiceCache { public const string USERS = "users"; private const string GROUPS = "groups"; @@ -130,7 +131,7 @@ namespace ASC.Core.Caching } } - public class CachedUserService : IUserService, ICachedService + class CachedUserService : IUserService, ICachedService { private readonly IUserService service; private readonly ICache cache; @@ -138,15 +139,15 @@ namespace ASC.Core.Caching private readonly TrustInterval trustInterval; private int getchanges; - public TimeSpan CacheExpiration { get; set; } - public TimeSpan DbExpiration { get; set; } - public TimeSpan PhotoExpiration { get; set; } - public CoreBaseSettings CoreBaseSettings { get; } - public UserServiceCache UserServiceCache { get; } - public ICacheNotify CacheUserInfoItem { get; } - public ICacheNotify CacheUserPhotoItem { get; } - public ICacheNotify CacheGroupCacheItem { get; } - public ICacheNotify CacheUserGroupRefItem { get; } + private TimeSpan CacheExpiration { get; set; } + private TimeSpan DbExpiration { get; set; } + private TimeSpan PhotoExpiration { get; set; } + private CoreBaseSettings CoreBaseSettings { get; } + private UserServiceCache UserServiceCache { get; } + private ICacheNotify CacheUserInfoItem { get; } + private ICacheNotify CacheUserPhotoItem { get; } + private ICacheNotify CacheGroupCacheItem { get; } + private ICacheNotify CacheUserGroupRefItem { get; } public CachedUserService( DbUserService service, @@ -454,5 +455,17 @@ namespace ASC.Core.Caching { public string Key { get; set; } } + } + public static class UserConfigFactory + { + public static IServiceCollection AddUserService(this IServiceCollection services) + { + return services + .AddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>)) + .AddCoreSettingsService() + .AddScoped() + .AddScoped() + .AddSingleton(); + } } } diff --git a/common/ASC.Core.Common/Context/Impl/AuthorizationManager.cs b/common/ASC.Core.Common/Context/Impl/AuthorizationManager.cs index 9803ae452c..cae047b4ed 100644 --- a/common/ASC.Core.Common/Context/Impl/AuthorizationManager.cs +++ b/common/ASC.Core.Common/Context/Impl/AuthorizationManager.cs @@ -29,15 +29,16 @@ using System.Collections.Generic; using System.Linq; using ASC.Common.Security; using ASC.Common.Security.Authorizing; -using ASC.Core.Caching; - +using ASC.Core.Caching; +using Microsoft.Extensions.DependencyInjection; + namespace ASC.Core { public class AuthorizationManager { private readonly IAzService service; - public TenantManager TenantManager { get; } + private TenantManager TenantManager { get; } public AuthorizationManager(IAzService service, TenantManager tenantManager) { @@ -125,5 +126,16 @@ namespace ASC.Core store.Get(objId).Where(a => (a.SubjectId == subjectId || subjectId == Guid.Empty) && (a.ActionId == actionId || actionId == Guid.Empty)) : aces.Where(a => (a.SubjectId == subjectId || subjectId == Guid.Empty) && (a.ActionId == actionId || actionId == Guid.Empty) && a.ObjectId == objId); } + } + + public static class AuthorizationManagerConfigFactory + { + public static IServiceCollection AddAuthorizationManagerService(this IServiceCollection services) + { + return services + .AddAzService() + .AddTenantManagerService() + .AddScoped(); + } } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Context/Impl/CoreConfiguration.cs b/common/ASC.Core.Common/Context/Impl/CoreConfiguration.cs index 4fb19cc3cd..c6eb4292ba 100644 --- a/common/ASC.Core.Common/Context/Impl/CoreConfiguration.cs +++ b/common/ASC.Core.Common/Context/Impl/CoreConfiguration.cs @@ -26,9 +26,11 @@ using System; using System.Text; +using ASC.Core.Caching; using ASC.Core.Configuration; using ASC.Core.Tenants; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; namespace ASC.Core @@ -307,5 +309,28 @@ namespace ASC.Core } #endregion + } + + public static class CoreSettingsConfigFactory + { + public static IServiceCollection AddCoreBaseSettingsService(this IServiceCollection services) + { + return services.AddSingleton(); + } + + public static IServiceCollection AddCoreSettingsService(this IServiceCollection services) + { + return services + .AddCoreBaseSettingsService() + .AddTenantService() + .AddScoped() + .AddScoped(); + } + public static IServiceCollection AddCoreConfigurationService(this IServiceCollection services) + { + return services + .AddCoreSettingsService() + .AddScoped(); + } } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Context/Impl/TenantManager.cs b/common/ASC.Core.Common/Context/Impl/TenantManager.cs index 3db6b0bd80..a0557db105 100644 --- a/common/ASC.Core.Common/Context/Impl/TenantManager.cs +++ b/common/ASC.Core.Common/Context/Impl/TenantManager.cs @@ -34,9 +34,11 @@ using System.Web; using ASC.Common.Notify.Engine; using ASC.Core.Billing; +using ASC.Core.Caching; using ASC.Core.Tenants; using Microsoft.AspNetCore.Http; - +using Microsoft.Extensions.DependencyInjection; + namespace ASC.Core { public class TenantManager @@ -47,9 +49,9 @@ namespace ASC.Core private readonly ITariffService tariffService; private static List thisCompAddresses = new List(); - public HttpContext HttpContext { get; } - public CoreBaseSettings CoreBaseSettings { get; } - public CoreSettings CoreSettings { get; } + private HttpContext HttpContext { get; } + private CoreBaseSettings CoreBaseSettings { get; } + private CoreSettings CoreSettings { get; } static TenantManager() { @@ -278,5 +280,20 @@ namespace ASC.Core { return quotaService.FindTenantQuotaRows(query).ToList(); } - } + } + + public static class TenantManagerConfigFactory + { + public static IServiceCollection AddTenantManagerService(this IServiceCollection services) + { + return services + .AddHttpContextAccessor() + .AddTenantService() + .AddQuotaService() + .AddTariffService() + .AddCoreBaseSettingsService() + .AddCoreSettingsService() + .AddScoped(); + } + } } diff --git a/common/ASC.Core.Common/Context/Impl/UserManager.cs b/common/ASC.Core.Common/Context/Impl/UserManager.cs index 5148fa6f1d..da0267c38b 100644 --- a/common/ASC.Core.Common/Context/Impl/UserManager.cs +++ b/common/ASC.Core.Common/Context/Impl/UserManager.cs @@ -32,6 +32,7 @@ using ASC.Core.Caching; using ASC.Core.Tenants; using ASC.Core.Users; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; namespace ASC.Core { @@ -52,21 +53,21 @@ namespace ASC.Core public class UserManager { - public IDictionary SystemUsers { get => UserManagerConstants.SystemUsers; } + private IDictionary SystemUsers { get => UserManagerConstants.SystemUsers; } - public IHttpContextAccessor Accessor { get; } - public IUserService UserService { get; } - public TenantManager TenantManager { get; } - public PermissionContext PermissionContext { get; } - public UserManagerConstants UserManagerConstants { get; } - public Constants Constants { get; } + private IHttpContextAccessor Accessor { get; } + private IUserService UserService { get; } + private TenantManager TenantManager { get; } + private PermissionContext PermissionContext { get; } + private UserManagerConstants UserManagerConstants { get; } + private Constants Constants { get; } private Tenant tenant; - public Tenant Tenant { get { return tenant ?? (tenant = TenantManager.GetCurrentTenant()); } } + private Tenant Tenant { get { return tenant ?? (tenant = TenantManager.GetCurrentTenant()); } } public UserManager( - IUserService service, - IHttpContextAccessor httpContextAccessor, + IUserService service, + IHttpContextAccessor httpContextAccessor, TenantManager tenantManager, PermissionContext permissionContext, UserManagerConstants userManagerConstants) @@ -609,5 +610,20 @@ namespace ASC.Core Sid = g.Sid }; } - } + } + + public static class UserManagerConfigFactory + { + public static IServiceCollection AddUserManagerService(this IServiceCollection services) + { + return services + .AddUserService() + .AddHttpContextAccessor() + .AddTenantManagerService() + .AddConstantsService() + .AddPermissionContextService() + .AddSingleton() + .AddScoped(); + } + } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Context/SecurityContext.cs b/common/ASC.Core.Common/Context/SecurityContext.cs index 4c49ce0f1a..3b5e293824 100644 --- a/common/ASC.Core.Common/Context/SecurityContext.cs +++ b/common/ASC.Core.Common/Context/SecurityContext.cs @@ -39,10 +39,12 @@ using ASC.Common.Security.Authorizing; using ASC.Core.Billing; using ASC.Core.Common.Security; using ASC.Core.Security.Authentication; +using ASC.Core.Security.Authorizing; using ASC.Core.Tenants; using ASC.Core.Users; using ASC.Security.Cryptography; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace ASC.Core @@ -80,7 +82,6 @@ namespace ASC.Core TenantCookieSettings tenantCookieSettings, TenantManager tenantManager, UserFormatter userFormatter, - InstanceCrypto instanceCrypto, CookieStorage cookieStorage, IOptionsMonitor options ) @@ -92,7 +93,6 @@ namespace ASC.Core TenantCookieSettings = tenantCookieSettings; TenantManager = tenantManager; UserFormatter = userFormatter; - InstanceCrypto = instanceCrypto; CookieStorage = cookieStorage; HttpContextAccessor = httpContextAccessor; } @@ -316,6 +316,8 @@ namespace ASC.Core public class AuthContext { + private IHttpContextAccessor HttpContextAccessor { get; } + public AuthContext(IHttpContextAccessor httpContextAccessor) { HttpContextAccessor = httpContextAccessor; @@ -331,8 +333,6 @@ namespace ASC.Core get { return CurrentAccount.IsAuthenticated; } } - public IHttpContextAccessor HttpContextAccessor { get; } - internal ClaimsPrincipal Principal { get => Thread.CurrentPrincipal as ClaimsPrincipal ?? HttpContextAccessor?.HttpContext?.User; @@ -343,4 +343,22 @@ namespace ASC.Core } } } + + public static class AuthContextConfigFactory + { + public static IServiceCollection AddAuthContextService(this IServiceCollection services) + { + return services + .AddHttpContextAccessor() + .AddScoped(); + } + + public static IServiceCollection AddPermissionContextService(this IServiceCollection services) + { + return services + .AddAuthContextService() + .AddPermissionResolverService() + .AddScoped(); + } + } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Data/DbAzService.cs b/common/ASC.Core.Common/Data/DbAzService.cs index a67bb25cef..2bd9d284bf 100644 --- a/common/ASC.Core.Common/Data/DbAzService.cs +++ b/common/ASC.Core.Common/Data/DbAzService.cs @@ -35,7 +35,7 @@ using ASC.Core.Tenants; namespace ASC.Core.Data { - public class DbAzService : DbBaseService, IAzService + class DbAzService : DbBaseService, IAzService { public DbAzService(DbOptionsManager dbOptionsManager) : base(dbOptionsManager, "tenant") diff --git a/common/ASC.Core.Common/Data/DbBaseService.cs b/common/ASC.Core.Common/Data/DbBaseService.cs index 6a5d417a8d..23b3377d16 100644 --- a/common/ASC.Core.Common/Data/DbBaseService.cs +++ b/common/ASC.Core.Common/Data/DbBaseService.cs @@ -25,30 +25,20 @@ using System; -using System.Collections.Generic; -using System.Configuration; +using System.Collections.Generic; using ASC.Common.Data; using ASC.Common.Data.Sql; namespace ASC.Core.Data { public abstract class DbBaseService - { - private readonly string dbid; + { + private DbOptionsManager DbOptionsManager { get; } - public DbRegistry DbRegistry { get; } - public DbOptionsManager DbOptionsManager { get; } protected string TenantColumn { get; private set; - } - - protected DbBaseService(ConnectionStringSettings connectionString, DbRegistry dbRegistry, string tenantColumn) - { - dbid = connectionString.Name; - DbRegistry = dbRegistry; - TenantColumn = tenantColumn; } protected DbBaseService(DbOptionsManager dbOptionsManager, string tenantColumn) diff --git a/common/ASC.Core.Common/Data/DbQuotaService.cs b/common/ASC.Core.Common/Data/DbQuotaService.cs index c594bb5486..f7a96ea8b5 100644 --- a/common/ASC.Core.Common/Data/DbQuotaService.cs +++ b/common/ASC.Core.Common/Data/DbQuotaService.cs @@ -34,7 +34,7 @@ using ASC.Core.Tenants; namespace ASC.Core.Data { - public class DbQuotaService : DbBaseService, IQuotaService + class DbQuotaService : DbBaseService, IQuotaService { private const string tenants_quota = "tenants_quota"; internal const string tenants_quotarow = "tenants_quotarow"; diff --git a/common/ASC.Core.Common/Data/DbSubscriptionService.cs b/common/ASC.Core.Common/Data/DbSubscriptionService.cs index f9278cf799..920ed97047 100644 --- a/common/ASC.Core.Common/Data/DbSubscriptionService.cs +++ b/common/ASC.Core.Common/Data/DbSubscriptionService.cs @@ -34,7 +34,7 @@ using ASC.Core.Tenants; namespace ASC.Core.Data { - public class DbSubscriptionService : DbBaseService, ISubscriptionService + class DbSubscriptionService : DbBaseService, ISubscriptionService { public DbSubscriptionService(DbOptionsManager dbOptionsManager) : base(dbOptionsManager, "tenant") diff --git a/common/ASC.Core.Common/Data/DbTenantService.cs b/common/ASC.Core.Common/Data/DbTenantService.cs index d652cd6a2d..55be114088 100644 --- a/common/ASC.Core.Common/Data/DbTenantService.cs +++ b/common/ASC.Core.Common/Data/DbTenantService.cs @@ -44,8 +44,8 @@ namespace ASC.Core.Data private static TimeZoneInfo defaultTimeZone; private List forbiddenDomains; - public TenantDomainValidator TenantDomainValidator { get; } - public TimeZoneConverter TimeZoneConverter { get; } + private TenantDomainValidator TenantDomainValidator { get; } + private TimeZoneConverter TimeZoneConverter { get; } public DbTenantService(DbOptionsManager dbOptionsManager, TenantDomainValidator tenantDomainValidator, TimeZoneConverter timeZoneConverter) : base(dbOptionsManager, null) diff --git a/common/ASC.Core.Common/Data/DbUserService.cs b/common/ASC.Core.Common/Data/DbUserService.cs index 25b9730066..71817a33ad 100644 --- a/common/ASC.Core.Common/Data/DbUserService.cs +++ b/common/ASC.Core.Common/Data/DbUserService.cs @@ -36,7 +36,7 @@ using ASC.Security.Cryptography; namespace ASC.Core.Data { - public class DbUserService : DbBaseService, IUserService + class DbUserService : DbBaseService, IUserService { public DbUserService(DbOptionsManager dbOptionsManager) : base(dbOptionsManager, "tenant") diff --git a/common/ASC.Core.Common/Security/Authorizing/AzManager.cs b/common/ASC.Core.Common/Security/Authorizing/AzManager.cs index 9349621db7..03fb6e45f2 100644 --- a/common/ASC.Core.Common/Security/Authorizing/AzManager.cs +++ b/common/ASC.Core.Common/Security/Authorizing/AzManager.cs @@ -26,6 +26,8 @@ using System; using System.Collections.Generic; +using ASC.Core.Security.Authorizing; +using Microsoft.Extensions.DependencyInjection; namespace ASC.Common.Security.Authorizing { @@ -143,5 +145,15 @@ namespace ASC.Common.Security.Authorizing } #endregion - } + } + + public static class AzManagerConfigFactory + { + public static IServiceCollection AddAzManagerService(this IServiceCollection services) + { + return services + .AddPermissionProviderService() + .AddRoleProviderService(); + } + } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Security/Authorizing/PermissionProvider.cs b/common/ASC.Core.Common/Security/Authorizing/PermissionProvider.cs index 3327fbdfa5..5367e4b240 100644 --- a/common/ASC.Core.Common/Security/Authorizing/PermissionProvider.cs +++ b/common/ASC.Core.Common/Security/Authorizing/PermissionProvider.cs @@ -28,19 +28,20 @@ using System; using System.Collections.Generic; using System.Linq; using ASC.Common.Security; -using ASC.Common.Security.Authorizing; - +using ASC.Common.Security.Authorizing; +using Microsoft.Extensions.DependencyInjection; + namespace ASC.Core.Security.Authorizing { - public class PermissionProvider : IPermissionProvider + class PermissionProvider : IPermissionProvider { + private AuthorizationManager AuthorizationManager { get; } + public PermissionProvider(AuthorizationManager authorizationManager) { AuthorizationManager = authorizationManager; } - public AuthorizationManager AuthorizationManager { get; } - public IEnumerable GetAcl(ISubject subject, IAction action, ISecurityObjectId objectId, ISecurityObjectProvider secObjProvider) { if (subject == null) throw new ArgumentNullException("subject"); @@ -50,5 +51,15 @@ namespace ASC.Core.Security.Authorizing .GetAcesWithInherits(subject.ID, action.ID, objectId, secObjProvider) .Select(r => new Ace(r.ActionId, r.Reaction)); } - } + } + + public static class PermissionProviderConfigFactory + { + public static IServiceCollection AddPermissionProviderService(this IServiceCollection services) + { + return services + .AddAuthorizationManagerService() + .AddScoped(typeof(IPermissionProvider), typeof(PermissionProvider)); + } + } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Security/Authorizing/PermissionResolver.cs b/common/ASC.Core.Common/Security/Authorizing/PermissionResolver.cs index 26ee02f45f..17b12930fc 100644 --- a/common/ASC.Core.Common/Security/Authorizing/PermissionResolver.cs +++ b/common/ASC.Core.Common/Security/Authorizing/PermissionResolver.cs @@ -29,12 +29,13 @@ using System.Collections.Generic; using System.Linq; using ASC.Common.Security; using ASC.Common.Security.Authentication; -using ASC.Common.Security.Authorizing; +using ASC.Common.Security.Authorizing; +using Microsoft.Extensions.DependencyInjection; using Constants = ASC.Core.Configuration.Constants; namespace ASC.Core.Security.Authorizing { - public class PermissionResolver : IPermissionResolver + class PermissionResolver : IPermissionResolver { private readonly AzManager azManager; @@ -119,5 +120,15 @@ namespace ASC.Core.Security.Authorizing DenyAction = denyAction; } } + } + + public static class PermissionResolverConfigFactory + { + public static IServiceCollection AddPermissionResolverService(this IServiceCollection services) + { + return services + .AddAzManagerService() + .AddScoped(typeof(IPermissionResolver), typeof(PermissionResolver)); + } } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Security/Authorizing/RoleProvider.cs b/common/ASC.Core.Common/Security/Authorizing/RoleProvider.cs index 3f81061119..d113a39696 100644 --- a/common/ASC.Core.Common/Security/Authorizing/RoleProvider.cs +++ b/common/ASC.Core.Common/Security/Authorizing/RoleProvider.cs @@ -30,15 +30,15 @@ using System.Linq; using ASC.Common.Security; using ASC.Common.Security.Authentication; using ASC.Common.Security.Authorizing; -using ASC.Core.Users; +using ASC.Core.Users; using Microsoft.Extensions.DependencyInjection; namespace ASC.Core.Security.Authorizing { - public class RoleProvider : IRoleProvider + class RoleProvider : IRoleProvider { //circ dep - public IServiceProvider ServiceProvider { get; } + private IServiceProvider ServiceProvider { get; } public RoleProvider(IServiceProvider serviceProvider) => (ServiceProvider) = (serviceProvider); public List GetRoles(ISubject account) @@ -81,5 +81,13 @@ namespace ASC.Core.Security.Authorizing } return roles; } - } + } + + public static class RoleProviderConfigFactory + { + public static IServiceCollection AddRoleProviderService(this IServiceCollection services) + { + return services.AddSingleton(typeof(IRoleProvider), typeof(RoleProvider)); + } + } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Tests/DbAzServiceTest.cs b/common/ASC.Core.Common/Tests/DbAzServiceTest.cs index 348a5320ee..f89e0ad9fc 100644 --- a/common/ASC.Core.Common/Tests/DbAzServiceTest.cs +++ b/common/ASC.Core.Common/Tests/DbAzServiceTest.cs @@ -34,7 +34,7 @@ namespace ASC.Core.Common.Tests using NUnit.Framework; [TestFixture] - public class DbAzServiceTest : DbBaseTest + class DbAzServiceTest : DbBaseTest { [SetUp] public void ClearData() diff --git a/common/ASC.Core.Common/Tests/DbQuotaServiceTest.cs b/common/ASC.Core.Common/Tests/DbQuotaServiceTest.cs index a1d364a630..6c195c94b9 100644 --- a/common/ASC.Core.Common/Tests/DbQuotaServiceTest.cs +++ b/common/ASC.Core.Common/Tests/DbQuotaServiceTest.cs @@ -39,7 +39,7 @@ namespace ASC.Core.Common.Tests using NUnit.Framework; [TestFixture] - public class DbQuotaServiceTest : DbBaseTest + class DbQuotaServiceTest : DbBaseTest { public DbOptionsManager DbOptionsManager { get; } diff --git a/common/ASC.Core.Common/Tests/DbSubscriptionServiceTest.cs b/common/ASC.Core.Common/Tests/DbSubscriptionServiceTest.cs index cbf05979a9..87f82af406 100644 --- a/common/ASC.Core.Common/Tests/DbSubscriptionServiceTest.cs +++ b/common/ASC.Core.Common/Tests/DbSubscriptionServiceTest.cs @@ -32,7 +32,7 @@ namespace ASC.Core.Common.Tests using NUnit.Framework; [TestFixture] - public class DbSubscriptionServiceTest : DbBaseTest + class DbSubscriptionServiceTest : DbBaseTest { [OneTimeSetUp] public void ClearData() diff --git a/common/ASC.Core.Common/Tests/DbUserServiceTest.cs b/common/ASC.Core.Common/Tests/DbUserServiceTest.cs index 7bdb310fbf..305e048c3b 100644 --- a/common/ASC.Core.Common/Tests/DbUserServiceTest.cs +++ b/common/ASC.Core.Common/Tests/DbUserServiceTest.cs @@ -35,7 +35,7 @@ namespace ASC.Core.Common.Tests using NUnit.Framework; [TestFixture] - public class DbUserServiceTest : DbBaseTest + class DbUserServiceTest : DbBaseTest { [OneTimeSetUp] public void ClearData() diff --git a/common/ASC.Core.Common/Users/Constants.cs b/common/ASC.Core.Common/Users/Constants.cs index b230e1f2bd..291701ee1c 100644 --- a/common/ASC.Core.Common/Users/Constants.cs +++ b/common/ASC.Core.Common/Users/Constants.cs @@ -26,6 +26,7 @@ using System; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Action = ASC.Common.Security.Authorizing.Action; using AuthConst = ASC.Common.Security.Authorizing.Constants; @@ -139,5 +140,14 @@ namespace ASC.Core.Users "Edit categories and groups"); #endregion + } + + public static class ConstantsConfigFactory + { + public static IServiceCollection AddConstantsService(this IServiceCollection services) + { + return services + .AddSingleton(); + } } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Users/UserFormatter.cs b/common/ASC.Core.Common/Users/UserFormatter.cs index 4cc280d648..0d6b99e1e5 100644 --- a/common/ASC.Core.Common/Users/UserFormatter.cs +++ b/common/ASC.Core.Common/Users/UserFormatter.cs @@ -28,8 +28,6 @@ using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading; - -using ASC.Common.Utils; using Microsoft.Extensions.Configuration; namespace ASC.Core.Users diff --git a/common/services/ASC.Notify/Program.cs b/common/services/ASC.Notify/Program.cs index d2a1da7fa2..f98674900d 100644 --- a/common/services/ASC.Notify/Program.cs +++ b/common/services/ASC.Notify/Program.cs @@ -1,8 +1,11 @@ using System.IO; using System.Threading.Tasks; + using ASC.Common.DependencyInjection; +using ASC.Common.Utils; using ASC.Notify.Config; using ASC.Web.Core; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/products/ASC.People/Server/Startup.cs b/products/ASC.People/Server/Startup.cs index 9538472f01..59c01d6a4a 100644 --- a/products/ASC.People/Server/Startup.cs +++ b/products/ASC.People/Server/Startup.cs @@ -8,7 +8,6 @@ using ASC.Common.Caching; using ASC.Common.Data; using ASC.Common.DependencyInjection; using ASC.Common.Logging; -using ASC.Common.Security; using ASC.Common.Security.Authorizing; using ASC.Common.Threading.Progress; using ASC.Common.Threading.Workers; @@ -21,7 +20,6 @@ using ASC.Core.Common.Settings; using ASC.Core.Data; using ASC.Core.Notify; using ASC.Core.Security.Authentication; -using ASC.Core.Security.Authorizing; using ASC.Core.Tenants; using ASC.Core.Users; using ASC.Data.Reassigns; @@ -143,46 +141,29 @@ namespace ASC.People }); services + .AddSubscriptionService() + .AddTenantManagerService() + .AddUserManagerService() .AddSingleton(typeof(ILog), typeof(LogNLog)) .AddStorage(Configuration) .AddWebItemManager() - .AddScoped() - .AddScoped() - .AddSingleton() - .AddScoped() - .AddScoped() - .AddSingleton() - .AddSingleton() - .AddScoped() - .AddScoped() - .AddSingleton() - .AddScoped() - .AddScoped() - .AddSingleton() - .AddScoped() - .AddScoped() - .AddScoped() + .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() - .AddScoped() - .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() - .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() - .AddScoped() - .AddScoped() .AddScoped() .AddScoped() .AddScoped() @@ -223,35 +204,26 @@ namespace ASC.People .AddScoped() .AddScoped() .AddScoped() - .AddScoped() - .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() - .AddScoped() .AddSingleton() .AddSingleton() - .AddSingleton() .AddSingleton() .AddScoped() .AddScoped() .AddScoped() .AddSingleton() - .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() .AddSingleton() .AddScoped() .AddScoped() .AddScoped() - .AddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>)) - .AddSingleton() .AddSingleton() - .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -260,7 +232,6 @@ namespace ASC.People .AddSingleton() .AddScoped() .AddScoped() - .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -269,9 +240,6 @@ namespace ASC.People .AddSingleton() .AddSingleton() .AddScoped(typeof(IRecipientProvider), typeof(RecipientProviderImpl)) - .AddSingleton(typeof(IRoleProvider), typeof(RoleProvider)) - .AddScoped(typeof(IPermissionResolver), typeof(PermissionResolver)) - .AddScoped(typeof(IPermissionProvider), typeof(PermissionProvider)) ; }