DI: refactoring
This commit is contained in:
parent
726ca634e4
commit
8ca3a63e24
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -67,9 +67,9 @@ namespace ASC.Common.Data
|
||||
}
|
||||
public class ConfigureDbManager : IConfigureNamedOptions<DbManager>
|
||||
{
|
||||
public DbRegistry DbRegistry { get; }
|
||||
public IOptionsMonitor<LogNLog> Option { get; }
|
||||
public IHttpContextAccessor HttpContextAccessor { get; }
|
||||
private DbRegistry DbRegistry { get; }
|
||||
private IOptionsMonitor<LogNLog> Option { get; }
|
||||
private IHttpContextAccessor HttpContextAccessor { get; }
|
||||
|
||||
public ConfigureDbManager(DbRegistry dbRegistry, IOptionsMonitor<LogNLog> option)
|
||||
{
|
||||
|
@ -45,8 +45,8 @@ namespace ASC.Common.Utils
|
||||
|
||||
private Dictionary<string, string> _translations;
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
public ILog Log { get; }
|
||||
private IConfiguration Configuration { get; }
|
||||
private ILog Log { get; }
|
||||
|
||||
public TimeZoneConverter(IConfiguration configuration, IOptionsMonitor<LogNLog> option)
|
||||
{
|
||||
|
@ -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<TariffServiceStorage>()
|
||||
.AddScoped<ITariffService, TariffService>();
|
||||
}
|
||||
}
|
||||
}
|
@ -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<AzRecordCache> CacheNotify { get; }
|
||||
internal ICache Cache { get; }
|
||||
internal ICacheNotify<AzRecordCache> CacheNotify { get; }
|
||||
|
||||
public AzServiceCache(ICacheNotify<AzRecordCache> cacheNotify)
|
||||
{
|
||||
@ -70,15 +71,15 @@ namespace ASC.Core.Caching
|
||||
}
|
||||
}
|
||||
|
||||
public class CachedAzService : IAzService
|
||||
class CachedAzService : IAzService
|
||||
{
|
||||
private readonly IAzService service;
|
||||
|
||||
private readonly ICacheNotify<AzRecordCache> 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<DbAzService>()
|
||||
.AddScoped<IAzService, CachedAzService>()
|
||||
.AddSingleton<AzServiceCache>()
|
||||
.AddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
}
|
||||
}
|
||||
}
|
@ -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<QuotaCacheItem> CacheNotify { get; }
|
||||
internal TrustInterval Interval { get; set; }
|
||||
internal ICache Cache { get; }
|
||||
internal ICacheNotify<QuotaCacheItem> CacheNotify { get; }
|
||||
|
||||
public bool QuotaCacheEnabled { get; }
|
||||
internal bool QuotaCacheEnabled { get; }
|
||||
|
||||
public QuotaServiceCache(IConfiguration Configuration, ICacheNotify<QuotaCacheItem> 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<QuotaCacheItem> 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<QuotaServiceCache>()
|
||||
.AddScoped<DbQuotaService>()
|
||||
.AddScoped<IQuotaService, CachedQuotaService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<SubscriptionRecord> NotifyRecord { get; }
|
||||
public ICacheNotify<SubscriptionMethodCache> NotifyMethod { get; }
|
||||
internal ICache Cache { get; }
|
||||
internal ICacheNotify<SubscriptionRecord> NotifyRecord { get; }
|
||||
internal ICacheNotify<SubscriptionMethodCache> NotifyMethod { get; }
|
||||
|
||||
public SubscriptionServiceCache(ICacheNotify<SubscriptionRecord> notifyRecord, ICacheNotify<SubscriptionMethodCache> 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<SubscriptionRecord> notifyRecord;
|
||||
private readonly ICacheNotify<SubscriptionMethodCache> 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<DbSubscriptionService>()
|
||||
.AddScoped<ISubscriptionService, CachedSubscriptionService>()
|
||||
.AddSingleton<SubscriptionServiceCache>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<TenantCacheItem> CacheNotifyItem { get; }
|
||||
public ICacheNotify<TenantSetting> CacheNotifySettings { get; }
|
||||
private TimeSpan CacheExpiration { get; set; }
|
||||
internal ICache Cache { get; }
|
||||
internal ICacheNotify<TenantCacheItem> CacheNotifyItem { get; }
|
||||
internal ICacheNotify<TenantSetting> CacheNotifySettings { get; }
|
||||
|
||||
public TenantServiceCache(CoreBaseSettings coreBaseSettings, ICacheNotify<TenantCacheItem> cacheNotifyItem, ICacheNotify<TenantSetting> 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<TenantSetting> cacheNotifySettings;
|
||||
private readonly ICacheNotify<TenantCacheItem> 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<TenantDomainValidator>()
|
||||
.AddSingleton<TimeZoneConverter>()
|
||||
.AddSingleton<TenantServiceCache>()
|
||||
.AddScoped<DbTenantService>()
|
||||
.AddScoped<ITenantService, CachedTenantService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<UserInfoCacheItem> CacheUserInfoItem { get; }
|
||||
public ICacheNotify<UserPhotoCacheItem> CacheUserPhotoItem { get; }
|
||||
public ICacheNotify<GroupCacheItem> CacheGroupCacheItem { get; }
|
||||
public ICacheNotify<UserGroupRefCacheItem> 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<UserInfoCacheItem> CacheUserInfoItem { get; }
|
||||
private ICacheNotify<UserPhotoCacheItem> CacheUserPhotoItem { get; }
|
||||
private ICacheNotify<GroupCacheItem> CacheGroupCacheItem { get; }
|
||||
private ICacheNotify<UserGroupRefCacheItem> 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<DbUserService>()
|
||||
.AddScoped<IUserService, CachedUserService>()
|
||||
.AddSingleton<UserServiceCache>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<AuthorizationManager>();
|
||||
}
|
||||
}
|
||||
}
|
@ -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<CoreBaseSettings>();
|
||||
}
|
||||
|
||||
public static IServiceCollection AddCoreSettingsService(this IServiceCollection services)
|
||||
{
|
||||
return services
|
||||
.AddCoreBaseSettingsService()
|
||||
.AddTenantService()
|
||||
.AddScoped<CoreSettings>()
|
||||
.AddScoped<CoreConfiguration>();
|
||||
}
|
||||
public static IServiceCollection AddCoreConfigurationService(this IServiceCollection services)
|
||||
{
|
||||
return services
|
||||
.AddCoreSettingsService()
|
||||
.AddScoped<CoreConfiguration>();
|
||||
}
|
||||
}
|
||||
}
|
@ -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<string> thisCompAddresses = new List<string>();
|
||||
|
||||
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<TenantManager>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Guid, UserInfo> SystemUsers { get => UserManagerConstants.SystemUsers; }
|
||||
private IDictionary<Guid, UserInfo> 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<UserManagerConstants>()
|
||||
.AddScoped<UserManager>();
|
||||
}
|
||||
}
|
||||
}
|
@ -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<LogNLog> 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<AuthContext>();
|
||||
}
|
||||
|
||||
public static IServiceCollection AddPermissionContextService(this IServiceCollection services)
|
||||
{
|
||||
return services
|
||||
.AddAuthContextService()
|
||||
.AddPermissionResolverService()
|
||||
.AddScoped<PermissionContext>();
|
||||
}
|
||||
}
|
||||
}
|
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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";
|
||||
|
@ -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")
|
||||
|
@ -44,8 +44,8 @@ namespace ASC.Core.Data
|
||||
private static TimeZoneInfo defaultTimeZone;
|
||||
private List<string> 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)
|
||||
|
@ -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")
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Ace> 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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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<IRole> 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));
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ namespace ASC.Core.Common.Tests
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class DbAzServiceTest : DbBaseTest<DbAzService>
|
||||
class DbAzServiceTest : DbBaseTest<DbAzService>
|
||||
{
|
||||
[SetUp]
|
||||
public void ClearData()
|
||||
|
@ -39,7 +39,7 @@ namespace ASC.Core.Common.Tests
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class DbQuotaServiceTest : DbBaseTest<DbQuotaService>
|
||||
class DbQuotaServiceTest : DbBaseTest<DbQuotaService>
|
||||
{
|
||||
public DbOptionsManager DbOptionsManager { get; }
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace ASC.Core.Common.Tests
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class DbSubscriptionServiceTest : DbBaseTest<DbSubscriptionService>
|
||||
class DbSubscriptionServiceTest : DbBaseTest<DbSubscriptionService>
|
||||
{
|
||||
[OneTimeSetUp]
|
||||
public void ClearData()
|
||||
|
@ -35,7 +35,7 @@ namespace ASC.Core.Common.Tests
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class DbUserServiceTest : DbBaseTest<DbUserService>
|
||||
class DbUserServiceTest : DbBaseTest<DbUserService>
|
||||
{
|
||||
[OneTimeSetUp]
|
||||
public void ClearData()
|
||||
|
@ -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<Constants>();
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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<DbSubscriptionService>()
|
||||
.AddScoped<ISubscriptionService, CachedSubscriptionService>()
|
||||
.AddSingleton<SubscriptionServiceCache>()
|
||||
.AddScoped<DbAzService>()
|
||||
.AddScoped<IAzService, CachedAzService>()
|
||||
.AddSingleton<AzServiceCache>()
|
||||
.AddSingleton<UserServiceCache>()
|
||||
.AddScoped<DbUserService>()
|
||||
.AddScoped<IUserService, CachedUserService>()
|
||||
.AddSingleton<TenantServiceCache>()
|
||||
.AddScoped<DbTenantService>()
|
||||
.AddScoped<ITenantService, CachedTenantService>()
|
||||
.AddSingleton<QuotaServiceCache>()
|
||||
.AddScoped<DbQuotaService>()
|
||||
.AddScoped<IQuotaService, CachedQuotaService>()
|
||||
.AddScoped<ITariffService, TariffService>()
|
||||
.AddScoped<SecurityContext>()
|
||||
.AddScoped<ApiContext>()
|
||||
.AddScoped<StudioNotifyService>()
|
||||
.AddScoped<UserManagerWrapper>()
|
||||
.AddScoped<MessageService>()
|
||||
.AddScoped<QueueWorkerReassign>()
|
||||
.AddScoped<QueueWorkerRemove>()
|
||||
.AddScoped<TenantManager>()
|
||||
.AddScoped<UserManager>()
|
||||
.AddScoped<StudioNotifyHelper>()
|
||||
.AddScoped<StudioNotifySource>()
|
||||
.AddScoped<StudioNotifyServiceHelper>()
|
||||
.AddScoped<AuthManager>()
|
||||
.AddScoped<TenantExtra>()
|
||||
.AddScoped<TenantStatisticsProvider>()
|
||||
.AddScoped<SecurityContext>()
|
||||
.AddScoped<AzManager>()
|
||||
.AddScoped<WebItemSecurity>()
|
||||
.AddScoped<UserPhotoManager>()
|
||||
.AddScoped<CookiesManager>()
|
||||
.AddScoped<PermissionContext>()
|
||||
.AddScoped<AuthContext>()
|
||||
.AddScoped<MessageFactory>()
|
||||
.AddScoped<WebImageSupplier>()
|
||||
.AddScoped<UserPhotoThumbnailSettings>()
|
||||
@ -223,35 +204,26 @@ namespace ASC.People
|
||||
.AddScoped<EmailValidationKeyProvider>()
|
||||
.AddScoped<TenantUtil>()
|
||||
.AddScoped<PaymentManager>()
|
||||
.AddScoped<AuthorizationManager>()
|
||||
.AddScoped<CoreConfiguration>()
|
||||
.AddScoped<BaseCommonLinkUtility>()
|
||||
.AddScoped<CommonLinkUtility>()
|
||||
.AddScoped<FilesLinkUtility>()
|
||||
.AddScoped<FileUtility>()
|
||||
.AddScoped<LicenseReader>()
|
||||
.AddScoped<ApiSystemHelper>()
|
||||
.AddScoped<CoreSettings>()
|
||||
.AddSingleton<WebPathSettings>()
|
||||
.AddSingleton<BaseStorageSettingsListener>()
|
||||
.AddSingleton<CoreBaseSettings>()
|
||||
.AddSingleton<SetupInfo>()
|
||||
.AddScoped<FileSizeComment>()
|
||||
.AddScoped<SubscriptionManager>()
|
||||
.AddScoped<IPSecurity.IPSecurity>()
|
||||
.AddSingleton<PathUtils>()
|
||||
.AddSingleton<TenantDomainValidator>()
|
||||
.AddSingleton<DbMessageSender>()
|
||||
.AddSingleton<UrlShortener>()
|
||||
.AddSingleton<UserManagerConstants>()
|
||||
.AddSingleton<MessagePolicy>()
|
||||
.AddScoped<DisplayUserSettings>()
|
||||
.AddScoped<SmsSender>()
|
||||
.AddScoped<CookieStorage>()
|
||||
.AddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>))
|
||||
.AddSingleton<ASC.Core.Users.Constants>()
|
||||
.AddSingleton<UserFormatter>()
|
||||
.AddSingleton<TimeZoneConverter>()
|
||||
.AddSingleton<MachinePseudoKeys>()
|
||||
.AddSingleton<Signature>()
|
||||
.AddSingleton<InstanceCrypto>()
|
||||
@ -260,7 +232,6 @@ namespace ASC.People
|
||||
.AddSingleton<IPRestrictionsServiceCache>()
|
||||
.AddScoped<IPRestrictionsService>()
|
||||
.AddScoped<IPRestrictionsRepository>()
|
||||
.AddSingleton<TariffServiceStorage>()
|
||||
.AddSingleton<DbSettingsManagerCache>()
|
||||
.AddSingleton<AccountLinkerStorage>()
|
||||
.AddSingleton<SmsKeyStorageCache>()
|
||||
@ -269,9 +240,6 @@ namespace ASC.People
|
||||
.AddSingleton<AscCacheNotify>()
|
||||
.AddSingleton<MessageTarget>()
|
||||
.AddScoped(typeof(IRecipientProvider), typeof(RecipientProviderImpl))
|
||||
.AddSingleton(typeof(IRoleProvider), typeof(RoleProvider))
|
||||
.AddScoped(typeof(IPermissionResolver), typeof(PermissionResolver))
|
||||
.AddScoped(typeof(IPermissionProvider), typeof(PermissionProvider))
|
||||
;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user