Merge branch 'develop' into feature/version-hostory-redesign

This commit is contained in:
Artem Tarasov 2020-11-16 17:35:43 +03:00
commit 8d56195705
415 changed files with 2114 additions and 6208 deletions

View File

@ -17,6 +17,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Api.Core.Auth
{
[Scope(Additional = typeof(ConfirmAuthHandlerExtension))]
public class ConfirmAuthHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{
public ConfirmAuthHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
@ -96,12 +97,11 @@ namespace ASC.Api.Core.Auth
}
}
public static class ConfirmAuthHandlerExtension
public class ConfirmAuthHandlerExtension
{
public static DIHelper AddConfirmAuthHandler(this DIHelper services)
public static void Register(DIHelper services)
{
return services
.AddSecurityContextService();
services.TryAdd<EmailValidationKeyModelHelper>();
}
}
}

View File

@ -3,7 +3,6 @@ using System.Security.Authentication;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using ASC.Common;
using ASC.Core;
using Microsoft.AspNetCore.Authentication;
@ -38,12 +37,4 @@ namespace ASC.Api.Core.Auth
);
}
}
public static class CookieAuthHandlerExtension
{
public static DIHelper AddCookieAuthHandler(this DIHelper services)
{
return services.AddSecurityContextService();
}
}
}

View File

@ -36,6 +36,7 @@ using Microsoft.AspNetCore.Http;
namespace ASC.Api.Core
{
[Scope]
public class ApiContext : ICloneable
{
public IHttpContextAccessor HttpContextAccessor { get; set; }
@ -268,19 +269,4 @@ namespace ASC.Api.Core
return context?.Fields == null || (context.Fields != null && context.Fields.Contains(field, StringComparer.InvariantCultureIgnoreCase));
}
}
public static class ApiContextConfigExtension
{
public static DIHelper AddApiContextService(this DIHelper services)
{
if (services.TryAddScoped<ApiContext>())
{
services
.AddTenantManagerService()
.AddSecurityContextService();
}
return services;
}
}
}

View File

@ -348,6 +348,7 @@ namespace ASC.Api.Core
}
}
[Scope]
public class ApiDateTimeHelper
{
private TenantManager TenantManager { get; }
@ -364,18 +365,4 @@ namespace ASC.Api.Core
return ApiDateTime.FromDate(TenantManager, TimeZoneConverter, from);
}
}
public static class ApiDateTimeHelperExtension
{
public static DIHelper AddApiDateTimeHelper(this DIHelper services)
{
if (services.TryAddScoped<ApiDateTimeHelper>())
{
return services
.AddTenantManagerService();
}
return services;
}
}
}

View File

@ -4,6 +4,7 @@ using ASC.Api.Core.Auth;
using ASC.Api.Core.Core;
using ASC.Api.Core.Middleware;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Common.Logging;
using Microsoft.AspNetCore.Authentication;
@ -63,12 +64,15 @@ namespace ASC.Api.Core
});
}
DIHelper
.AddCultureMiddleware()
.AddIpSecurityFilter()
.AddPaymentFilter()
.AddProductSecurityFilter()
.AddTenantStatusFilter();
DIHelper.TryAdd<DisposeMiddleware>();
DIHelper.TryAdd<CultureMiddleware>();
DIHelper.TryAdd<IpSecurityFilter>();
DIHelper.TryAdd<PaymentFilter>();
DIHelper.TryAdd<ProductSecurityFilter>();
DIHelper.TryAdd<TenantStatusFilter>();
DIHelper.TryAdd<ConfirmAuthHandler>();
DIHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
var builder = services.AddMvcCore(config =>
{
@ -86,7 +90,7 @@ namespace ASC.Api.Core
config.OutputFormatters.Add(new XmlOutputFormatter());
});
DIHelper.AddCookieAuthHandler();
var authBuilder = services.AddAuthentication("cookie")
.AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { });
@ -97,7 +101,7 @@ namespace ASC.Api.Core
if (LogParams != null)
{
DIHelper.AddNLogManager(LogParams);
LogNLogExtension.ConfigureLog(DIHelper, LogParams);
}
}

View File

@ -2,7 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
using ASC.Common;
using ASC.Core;
using Microsoft.AspNetCore.Builder;
@ -51,13 +50,5 @@ namespace ASC.Api.Core.Middleware
{
return builder.UseMiddleware<CultureMiddleware>();
}
public static DIHelper AddCultureMiddleware(this DIHelper services)
{
return services
.AddUserManagerService()
.AddTenantManagerService()
.AddAuthContextService();
}
}
}

View File

@ -3,7 +3,6 @@
using ASC.Common;
using ASC.Common.Logging;
using ASC.Core;
using ASC.Core.Common.Settings;
using ASC.IPSecurity;
using Microsoft.AspNetCore.Mvc;
@ -12,6 +11,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Api.Core.Middleware
{
[Scope]
public class IpSecurityFilter : IResourceFilter
{
private readonly ILog log;
@ -44,15 +44,4 @@ namespace ASC.Api.Core.Middleware
}
}
}
public static class IpSecurityFilterExtension
{
public static DIHelper AddIpSecurityFilter(this DIHelper services)
{
return services
.AddSettingsManagerService()
.AddAuthContextService()
.AddIPSecurityService();
}
}
}

View File

@ -14,6 +14,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Api.Core.Middleware
{
[Scope]
public class PaymentFilter : IResourceFilter
{
private readonly ILog log;
@ -49,13 +50,4 @@ namespace ASC.Api.Core.Middleware
}
}
}
public static class PaymentFilterExtension
{
public static DIHelper AddPaymentFilter(this DIHelper services)
{
return services
.AddTenantExtraService();
}
}
}

View File

@ -17,6 +17,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Api.Core.Middleware
{
[Scope]
public class ProductSecurityFilter : IResourceFilter
{
private static readonly IDictionary<string, Guid> products;
@ -116,14 +117,4 @@ namespace ASC.Api.Core.Middleware
return default;
}
}
public static class ProductSecurityFilterExtension
{
public static DIHelper AddProductSecurityFilter(this DIHelper services)
{
return services
.AddWebItemSecurity()
.AddAuthContextService();
}
}
}

View File

@ -11,6 +11,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Api.Core.Middleware
{
[Scope]
public class TenantStatusFilter : IResourceFilter
{
private readonly ILog log;
@ -45,13 +46,4 @@ namespace ASC.Api.Core.Middleware
}
}
}
public static class TenantStatusFilterExtension
{
public static DIHelper AddTenantStatusFilter(this DIHelper services)
{
return services
.AddTenantManagerService();
}
}
}

View File

@ -60,6 +60,7 @@ namespace ASC.Web.Api.Models
}
}
[Scope]
public class EmployeeWraperHelper
{
private ApiContext HttpContext { get; }
@ -124,21 +125,4 @@ namespace ASC.Web.Api.Models
return result;
}
}
public static class EmployeeWraperExtension
{
public static DIHelper AddEmployeeWraper(this DIHelper services)
{
if (services.TryAddScoped<EmployeeWraperHelper>())
{
return services
.AddApiContextService()
.AddDisplayUserSettingsService()
.AddUserPhotoManagerService()
.AddCommonLinkUtilityService();
}
return services;
}
}
}

View File

@ -131,6 +131,7 @@ namespace ASC.Web.Api.Models
}
}
[Scope]
public class EmployeeWraperFullHelper : EmployeeWraperHelper
{
private ApiContext Context { get; }
@ -288,22 +289,4 @@ namespace ASC.Web.Api.Models
}
}
}
public static class EmployeeWraperFullExtension
{
public static DIHelper AddEmployeeWraperFull(this DIHelper services)
{
if (services.TryAddScoped<EmployeeWraperFullHelper>())
{
return services
.AddTenantManagerService()
.AddWebItemSecurity()
.AddUserManagerService()
.AddEmployeeWraper()
.AddApiDateTimeHelper();
}
return services;
}
}
}

View File

@ -45,10 +45,12 @@
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.9" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.1.1" />
<!-- <PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.4">
<PrivateAssets>all</PrivateAssets>

View File

@ -34,6 +34,7 @@ using Google.Protobuf;
namespace ASC.Common.Caching
{
[Singletone]
public class AscCacheNotify
{
private ICacheNotify<AscCacheItem> CacheNotify { get; }

View File

@ -30,6 +30,7 @@ using Google.Protobuf;
namespace ASC.Common.Caching
{
[Singletone]
public interface ICacheNotify<T> where T : IMessage<T>, new()
{
void Publish(T obj, CacheNotifyAction action);

View File

@ -16,6 +16,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Common.Caching
{
[Singletone]
public class KafkaCache<T> : IDisposable, ICacheNotify<T> where T : IMessage<T>, new()
{
private ClientConfig ClientConfig { get; set; }
@ -238,14 +239,4 @@ namespace ASC.Common.Caching
return $"{typeof(T).Name}{cacheNotifyAction}";
}
}
public static class KafkaExtention
{
public static DIHelper AddKafkaService(this DIHelper services)
{
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
return services;
}
}
}

View File

@ -1,27 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ASC.Common.Threading.Progress;
using ASC.Common.Threading.Workers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace ASC.Common
{
public enum DIAttributeEnum
{
Singletone,
Scope,
Transient
}
public class TransientAttribute : DIAttribute
{
public override DIAttributeEnum DIAttributeEnum { get => DIAttributeEnum.Transient; }
public TransientAttribute() { }
public TransientAttribute(Type service) : base(service) { }
public TransientAttribute(Type service, Type implementation) : base(service, implementation) { }
public override void TryAdd(IServiceCollection services, Type service, Type implementation = null)
{
if (implementation != null)
{
services.AddTransient(service, implementation);
}
else
{
services.AddTransient(service);
}
}
}
public class ScopeAttribute : DIAttribute
{
public override DIAttributeEnum DIAttributeEnum { get => DIAttributeEnum.Scope; }
public ScopeAttribute() { }
public ScopeAttribute(Type service) : base(service) { }
public ScopeAttribute(Type service, Type implementation) : base(service, implementation) { }
public override void TryAdd(IServiceCollection services, Type service, Type implementation = null)
{
if (implementation != null)
{
services.AddScoped(service, implementation);
}
else
{
services.AddScoped(service);
}
}
}
public class SingletoneAttribute : DIAttribute
{
public override DIAttributeEnum DIAttributeEnum { get => DIAttributeEnum.Singletone; }
public SingletoneAttribute() { }
public SingletoneAttribute(Type service) : base(service) { }
public SingletoneAttribute(Type service, Type implementation) : base(service, implementation) { }
public override void TryAdd(IServiceCollection services, Type service, Type implementation = null)
{
if (implementation != null)
{
services.AddSingleton(service, implementation);
}
else
{
services.AddSingleton(service);
}
}
}
public abstract class DIAttribute : Attribute
{
public abstract DIAttributeEnum DIAttributeEnum { get; }
public Type Implementation { get; }
public Type Service { get; }
public Type Additional { get; set; }
public DIAttribute() { }
public DIAttribute(Type service)
{
Service = service;
}
public DIAttribute(Type service, Type implementation)
{
Implementation = implementation;
Service = service;
}
public abstract void TryAdd(IServiceCollection services, Type service, Type implementation = null);
}
public class DIHelper
{
public List<string> Singleton { get; set; }
public List<string> Scoped { get; set; }
public List<string> Transient { get; set; }
public Dictionary<DIAttributeEnum, List<string>> Services { get; set; }
public List<string> Added { get; set; }
public List<string> Configured { get; set; }
public IServiceCollection ServiceCollection { get; private set; }
public DIHelper()
{
Singleton = new List<string>();
Scoped = new List<string>();
Transient = new List<string>();
Services = new Dictionary<DIAttributeEnum, List<string>>()
{
{ DIAttributeEnum.Singletone, new List<string>() },
{ DIAttributeEnum.Scope, new List<string>() },
{ DIAttributeEnum.Transient, new List<string>() }
};
Added = new List<string>();
Configured = new List<string>();
}
@ -35,129 +142,242 @@ namespace ASC.Common
ServiceCollection = serviceCollection;
}
public bool TryAddScoped<TService>() where TService : class
public bool TryAdd<TService>() where TService : class
{
var serviceName = $"{typeof(TService)}";
if (!Scoped.Contains(serviceName))
{
Scoped.Add(serviceName);
ServiceCollection.TryAddScoped<TService>();
return true;
}
return false;
return TryAdd(typeof(TService));
}
public bool TryAddScoped<TService, TImplementation>() where TService : class where TImplementation : class, TService
public bool TryAdd<TService, TImplementation>() where TService : class
{
var serviceName = $"{typeof(TService)}{typeof(TImplementation)}";
if (!Scoped.Contains(serviceName))
return TryAdd(typeof(TService), typeof(TImplementation));
}
public bool TryAdd(Type service, Type implementation = null)
{
if (service.IsInterface && service.IsGenericType && implementation == null &&
(service.GetGenericTypeDefinition() == typeof(IOptionsSnapshot<>) ||
service.GetGenericTypeDefinition() == typeof(IOptions<>) ||
service.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>)
))
{
Scoped.Add(serviceName);
ServiceCollection.TryAddScoped<TService, TImplementation>();
service = service.GetGenericArguments().FirstOrDefault();
if (service == null)
{
return false;
}
}
var serviceName = $"{service}{implementation}";
if (Added.Contains(serviceName)) return false;
Added.Add(serviceName);
var di = service.IsGenericType && (
service.GetGenericTypeDefinition() == typeof(IConfigureOptions<>) ||
service.GetGenericTypeDefinition() == typeof(IPostConfigureOptions<>) ||
service.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>)
) && implementation != null ? implementation.GetCustomAttribute<DIAttribute>() : service.GetCustomAttribute<DIAttribute>();
var isnew = false;
if (di != null)
{
if (di.Additional != null)
{
var m = di.Additional.GetMethod("Register", BindingFlags.Public | BindingFlags.Static);
m.Invoke(null, new[] { this });
}
if (!service.IsInterface || implementation != null)
{
isnew = implementation != null ? Register(service, implementation) : Register(service);
if (!isnew) return false;
}
if (service.IsInterface && implementation == null || !service.IsInterface)
{
if (di.Service != null)
{
var a = di.Service.GetInterfaces().FirstOrDefault(x => x.IsGenericType && (
x.GetGenericTypeDefinition() == typeof(IConfigureOptions<>) ||
x.GetGenericTypeDefinition() == typeof(IPostConfigureOptions<>) ||
x.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>)
));
if (a != null)
{
if (!a.ContainsGenericParameters)
{
var b = a.GetGenericArguments();
foreach (var g in b)
{
if (g != service)
{
TryAdd(g);
if (service.IsInterface && di.Implementation == null)
{
TryAdd(service, g);
}
}
}
TryAdd(a, di.Service);
}
else
{
Type c = null;
var a1 = a.GetGenericTypeDefinition();
var b = a.GetGenericArguments().FirstOrDefault();
if (b != null && b.IsGenericType)
{
var b1 = b.GetGenericTypeDefinition().MakeGenericType(service.GetGenericArguments());
TryAdd(b1);
c = a1.MakeGenericType(b1);
}
else
{
c = a1.MakeGenericType(service.GetGenericArguments());
}
TryAdd(c, di.Service.MakeGenericType(service.GetGenericArguments()));
//a, di.Service
}
}
else
{
if (di.Implementation == null)
{
isnew = Register(service, di.Service);
TryAdd(di.Service);
}
else
{
Register(di.Service);
}
}
}
if (di.Implementation != null)
{
var a = di.Implementation.GetInterfaces().FirstOrDefault(x => x.IsGenericType &&
(x.GetGenericTypeDefinition() == typeof(IConfigureOptions<>) ||
x.GetGenericTypeDefinition() == typeof(IPostConfigureOptions<>) ||
x.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>))
);
if (a != null)
{
if (!a.ContainsGenericParameters)
{
var b = a.GetGenericArguments();
foreach (var g in b)
{
if (g != service)
{
//TryAdd(g);
if (service.IsInterface && implementation == null)
{
TryAdd(service, g);
}
}
}
TryAdd(a, di.Implementation);
}
else
{
Type c = null;
var a1 = a.GetGenericTypeDefinition();
var b = a.GetGenericArguments().FirstOrDefault();
if (b != null && b.IsGenericType)
{
var b1 = b.GetGenericTypeDefinition().MakeGenericType(service.GetGenericArguments());
TryAdd(b1);
c = a1.MakeGenericType(b1);
}
else
{
c = a1.MakeGenericType(service.GetGenericArguments());
}
TryAdd(c, di.Implementation.MakeGenericType(service.GetGenericArguments()));
//a, di.Service
}
}
else
{
isnew = TryAdd(service, di.Implementation);
}
}
}
}
if (isnew)
{
ConstructorInfo[] props = null;
if (!service.IsInterface)
{
props = service.GetConstructors();
}
else if (implementation != null)
{
props = implementation.GetConstructors();
}
else if (di.Service != null)
{
props = di.Service.GetConstructors();
}
if (props != null)
{
var par = props.SelectMany(r => r.GetParameters()).Distinct();
foreach (var p1 in par)
{
TryAdd(p1.ParameterType);
}
}
}
return isnew;
}
private bool Register(Type service, Type implementation = null)
{
if (service.IsSubclassOf(typeof(ControllerBase))|| service.GetInterfaces().Contains(typeof(IResourceFilter)) || service.GetInterfaces().Contains(typeof(IDictionary<string, string>))) return true;
var c = service.IsGenericType && (
service.GetGenericTypeDefinition() == typeof(IConfigureOptions<>) ||
service.GetGenericTypeDefinition() == typeof(IPostConfigureOptions<>) ||
service.GetGenericTypeDefinition() == typeof(IOptionsMonitor<>)
) && implementation != null ? implementation.GetCustomAttribute<DIAttribute>() : service.GetCustomAttribute<DIAttribute>();
var serviceName = $"{service}{implementation}";
if (!Services[c.DIAttributeEnum].Contains(serviceName))
{
c.TryAdd(ServiceCollection, service, implementation);
Services[c.DIAttributeEnum].Add(serviceName);
return true;
}
return false;
}
public bool TryAddScoped<TService, TImplementation>(TService tservice, TImplementation tImplementation) where TService : Type where TImplementation : Type
{
var serviceName = $"{tservice}{tImplementation}";
if (!Scoped.Contains(serviceName))
{
Scoped.Add(serviceName);
ServiceCollection.TryAddScoped(tservice, tImplementation);
return true;
}
return false;
}
public DIHelper TryAddSingleton<TService>() where TService : class
{
var serviceName = $"{typeof(TService)}";
if (!Singleton.Contains(serviceName))
{
Singleton.Add(serviceName);
ServiceCollection.TryAddSingleton<TService>();
}
return this;
}
public DIHelper TryAddSingleton<TService>(Func<IServiceProvider, TService> implementationFactory) where TService : class
{
var serviceName = $"{typeof(TService)}";
if (!Singleton.Contains(serviceName))
if (!Services[DIAttributeEnum.Singletone].Contains(serviceName))
{
Singleton.Add(serviceName);
Services[DIAttributeEnum.Singletone].Add(serviceName);
ServiceCollection.TryAddSingleton(implementationFactory);
}
return this;
}
public DIHelper TryAddSingleton<TService>(TService t) where TService : class
{
var serviceName = $"{typeof(TService)}";
if (!Singleton.Contains(serviceName))
{
Singleton.Add(serviceName);
ServiceCollection.TryAddSingleton(t);
}
return this;
}
public DIHelper TryAddSingleton<TService, TImplementation>() where TService : class where TImplementation : class, TService
{
var serviceName = $"{typeof(TService)}{typeof(TImplementation)}";
if (!Singleton.Contains(serviceName))
{
Singleton.Add(serviceName);
ServiceCollection.TryAddSingleton<TService, TImplementation>();
}
return this;
}
public DIHelper AddSingleton<TService, TImplementation>() where TService : class where TImplementation : class, TService
{
var serviceName = $"{typeof(TService)}{typeof(TImplementation)}";
if (!Singleton.Contains(serviceName))
{
Singleton.Add(serviceName);
ServiceCollection.AddSingleton<TService, TImplementation>();
}
return this;
}
public DIHelper TryAddSingleton<TService, TImplementation>(TService tservice, TImplementation tImplementation) where TService : Type where TImplementation : Type
{
var serviceName = $"{tservice}{tImplementation}";
if (!Singleton.Contains(serviceName))
{
Singleton.Add(serviceName);
ServiceCollection.TryAddSingleton(tservice, tImplementation);
}
return this;
}
public DIHelper TryAddTransient<TService>() where TService : class
{
var serviceName = $"{typeof(TService)}";
if (!Transient.Contains(serviceName))
{
Transient.Add(serviceName);
ServiceCollection.TryAddTransient<TService>();
}
return this;
}
public DIHelper Configure<TOptions>(Action<TOptions> configureOptions) where TOptions : class
{
var serviceName = $"{typeof(TOptions)}";
@ -191,6 +411,7 @@ namespace ASC.Common
AddToConfigured($"{typeof(WorkerQueue<T1>)}", (Action<WorkerQueue<T1>>)action);
return this;
}
public DIHelper AddProgressQueue<T1>(int workerCount, int waitInterval, bool removeAfterCompleted, bool stopAfterFinsih, int errorCount) where T1 : class, IProgressItem
{
void action(ProgressQueue<T1> a)
@ -204,6 +425,7 @@ namespace ASC.Common
AddToConfigured($"{typeof(ProgressQueue<T1>)}", (Action<ProgressQueue<T1>>)action);
return this;
}
public DIHelper Configure<TOptions>(string name, Action<TOptions> configureOptions) where TOptions : class
{
var serviceName = $"{typeof(TOptions)}{name}";

View File

@ -6,6 +6,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Common.Logging
{
[Scope]
public class EFLoggerFactory : ILoggerFactory
{
Dictionary<string, ILogger> Loggers { get; set; }
@ -34,6 +35,7 @@ namespace ASC.Common.Logging
}
}
[Scope]
public class EFLoggerProvider : ILoggerProvider
{
private IOptionsMonitor<ILog> Option { get; }
@ -122,17 +124,4 @@ namespace ASC.Common.Logging
string.Empty;
}
}
public static class LoggerExtension
{
public static DIHelper AddLoggerService(this DIHelper services)
{
if (services.TryAddScoped<EFLoggerFactory>())
{
services.TryAddScoped<EFLoggerProvider>();
}
return services;
}
}
}

View File

@ -40,7 +40,8 @@ using Microsoft.Extensions.Options;
using NLog;
namespace ASC.Common.Logging
{
{
[Singletone(typeof(ConfigureLogNLog), Additional = typeof(LogNLogExtension))]
public interface ILog
{
bool IsDebugEnabled { get; }
@ -371,7 +372,8 @@ namespace ASC.Common.Logging
public string Name { get; set; }
public string Dir { get; set; }
}
[Singletone]
public class ConfigureLogNLog : IConfigureNamedOptions<LogNLog>
{
public ConfigureLogNLog(IConfiguration configuration)
@ -851,7 +853,8 @@ namespace ASC.Common.Logging
public string Name { get; set; }
}
[Singletone]
public class LogManager<T> : OptionsMonitor<T> where T : class, ILog, new()
{
public LogManager(IOptionsFactory<T> factory, IEnumerable<IOptionsChangeTokenSource<T>> sources, IOptionsMonitorCache<T> cache) : base(factory, sources, cache)
@ -871,30 +874,32 @@ namespace ASC.Common.Logging
}
}
public static class StudioNotifyHelperExtension
public class LoggerExtension<T> where T : class, ILog, new()
{
public static DIHelper AddLogManager<T>(this DIHelper services, params string[] additionalLoggers) where T : class, ILog, new()
public static void RegisterLog(DIHelper services)
{
const string baseName = "ASC";
var baseSqlName = $"{baseName}.SQL";
services.Configure<T>(r => r.Name = baseName);
services.Configure<T>(baseName, r => r.Name = baseName);
services.Configure<T>(baseSqlName, r => r.Name = baseSqlName);
services.Configure<T>(baseSqlName, r => r.Name = baseSqlName);
services.TryAdd(typeof(IOptionsMonitor<ILog>), typeof(LogManager<T>));
}
public static void ConfigureLog(DIHelper services, params string[] additionalLoggers)
{
foreach (var l in additionalLoggers)
{
services.Configure<T>(l, r => r.Name = l);
}
services.TryAddSingleton(typeof(IOptionsMonitor<ILog>), typeof(LogManager<T>));
return services;
}
public static DIHelper AddNLogManager(this DIHelper services, params string[] additionalLoggers)
{
services.TryAddSingleton<IConfigureNamedOptions<LogNLog>, ConfigureLogNLog>();
services.TryAddSingleton<IConfigureOptions<LogNLog>, ConfigureLogNLog>();
return services.AddLogManager<LogNLog>(additionalLoggers);
}
}
public class LogNLogExtension : LoggerExtension<LogNLog>
{
public static void Register(DIHelper services)
{
RegisterLog(services);
}
}
}

View File

@ -33,6 +33,7 @@ using ASC.Common;
namespace ASC.Security.Cryptography
{
[Singletone]
public class InstanceCrypto
{
private MachinePseudoKeys MachinePseudoKeys { get; }
@ -86,14 +87,4 @@ namespace ASC.Security.Cryptography
return MachinePseudoKeys.GetMachineConstant(32);
}
}
public static class InstanceCryptoExtension
{
public static DIHelper AddInstanceCryptoService(this DIHelper services)
{
services.TryAddSingleton<InstanceCrypto>();
return services
.AddMachinePseudoKeysService();
}
}
}

View File

@ -36,6 +36,7 @@ using Microsoft.Extensions.Configuration;
namespace ASC.Security.Cryptography
{
[Singletone]
public class MachinePseudoKeys
{
private readonly byte[] confkey = null;
@ -76,13 +77,4 @@ namespace ASC.Security.Cryptography
return buff;
}
}
public static class MachinePseudoKeysExtension
{
public static DIHelper AddMachinePseudoKeysService(this DIHelper services)
{
services.TryAddSingleton<MachinePseudoKeys>();
return services;
}
}
}

View File

@ -34,6 +34,7 @@ using Microsoft.Extensions.Configuration;
namespace ASC.Security.Cryptography
{
[Singletone]
public class PasswordHasher
{
public PasswordHasher(IConfiguration configuration, MachinePseudoKeys machinePseudoKeys)
@ -95,14 +96,5 @@ namespace ASC.Security.Cryptography
return hash;
}
}
public static class PasswordHasherExtension
{
public static DIHelper AddPasswordHasherService(this DIHelper services)
{
services.TryAddSingleton<PasswordHasher>();
return services.AddMachinePseudoKeysService();
}
}
}

View File

@ -36,6 +36,7 @@ using ASC.Common.Caching;
namespace ASC.Common.Threading
{
[Singletone]
public class DistributedTaskCacheNotify
{
public ConcurrentDictionary<string, CancellationTokenSource> Cancelations { get; }

View File

@ -33,14 +33,16 @@ using ASC.Common.Threading.Workers;
using Microsoft.Extensions.Options;
namespace ASC.Common.Threading.Progress
{
{
[Singletone(typeof(ConfigureProgressQueue<>))]
public class ProgressQueueOptionsManager<T> : OptionsManager<ProgressQueue<T>> where T : class, IProgressItem
{
public ProgressQueueOptionsManager(IOptionsFactory<ProgressQueue<T>> factory) : base(factory)
{
}
}
[Singletone]
public class ConfigureProgressQueue<T> : IPostConfigureOptions<ProgressQueue<T>> where T : class, IProgressItem
{
public ConfigureProgressQueue(IOptionsMonitor<ILog> log)
@ -56,7 +58,8 @@ namespace ASC.Common.Threading.Progress
queue.Start(x => x.RunJob());
}
}
[Singletone]
public class ProgressQueue<T> : WorkerQueue<T> where T : class, IProgressItem
{
public bool removeAfterCompleted;

View File

@ -34,14 +34,16 @@ using ASC.Common.Logging;
using Microsoft.Extensions.Options;
namespace ASC.Common.Threading.Workers
{
{
[Singletone(typeof(ConfigureWorkerQueue<>))]
public class WorkerQueueOptionsManager<T> : OptionsManager<WorkerQueue<T>>
{
public WorkerQueueOptionsManager(IOptionsFactory<WorkerQueue<T>> factory) : base(factory)
{
}
}
[Singletone]
public class ConfigureWorkerQueue<T> : IConfigureOptions<WorkerQueue<T>>
{
public ConfigureWorkerQueue(IOptionsMonitor<ILog> log)
@ -56,7 +58,8 @@ namespace ASC.Common.Threading.Workers
queue.log = Log.Get("ASC.WorkerQueue");
}
}
[Singletone]
public class WorkerQueue<T>
{
internal ILog log;

View File

@ -36,6 +36,7 @@ using Newtonsoft.Json;
namespace ASC.Common.Utils
{
[Singletone]
public class Signature
{
public Signature(MachinePseudoKeys machinePseudoKeys)
@ -91,13 +92,4 @@ namespace ASC.Common.Utils
return Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(str)));
}
}
public static class SignatureExtension
{
public static DIHelper AddSignatureService(this DIHelper services)
{
services.TryAddSingleton<Signature>();
return services.AddMachinePseudoKeysService();
}
}
}

View File

@ -40,7 +40,8 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
namespace ASC.Common.Utils
{
{
[Singletone]
public class TimeZoneConverter
{
private TimeZoneInfo defaultTimeZone;

View File

@ -38,12 +38,14 @@ using Microsoft.Extensions.Options;
namespace ASC.Core.Common
{
[Singletone]
public class CommonLinkUtilitySettings
{
public string ServerUri { get; set; }
}
[Scope]
public class BaseCommonLinkUtility
{
private const string LOCALHOST = "localhost";
@ -243,21 +245,4 @@ namespace ASC.Core.Common
_vpath = "/" + uri.AbsolutePath.Trim('/');
}
}
public static class BaseCommonLinkUtilityExtension
{
public static DIHelper AddBaseCommonLinkUtilityService(this DIHelper services)
{
if (services.TryAddScoped<BaseCommonLinkUtility>())
{
services.TryAddScoped<CommonLinkUtilitySettings>();
return services
.AddCoreBaseSettingsService()
.AddCoreSettingsService()
.AddTenantManagerService();
}
return services;
}
}
}

View File

@ -35,6 +35,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ASC.Common;
using ASC.Common.Logging;
using Microsoft.Extensions.Options;
@ -42,7 +43,8 @@ using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace ASC.Core.Common.Billing
{
{
[Singletone]
public class CouponManager
{
private IEnumerable<AvangateProduct> Products { get; set; }

View File

@ -25,10 +25,13 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using ASC.Common;
namespace ASC.Core.Billing
{
{
[Scope(typeof(ConfigureTariffService))]
public interface ITariffService
{
Tariff GetTariff(int tenantId, bool withRequestToPaymentSystem = true);

View File

@ -37,7 +37,8 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
namespace ASC.Core.Billing
{
{
[Scope]
public class LicenseReader
{
private readonly ILog Log;
@ -340,21 +341,4 @@ namespace ASC.Core.Billing
private CoreSettings CoreSettings { get; }
private IConfiguration Configuration { get; }
}
public static class LicenseReaderExtension
{
public static DIHelper AddLicenseReaderService(this DIHelper services)
{
if (services.TryAddScoped<LicenseReader>())
{
return services
.AddUserManagerService()
.AddPaymentManagerService()
.AddTenantManagerService()
.AddCoreSettingsService();
}
return services;
}
}
}

View File

@ -42,7 +42,8 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
namespace ASC.Core.Billing
{
{
[Singletone]
public class TariffServiceStorage
{
public ICache Cache { get; }
@ -75,7 +76,8 @@ namespace ASC.Core.Billing
}*/
}
}
[Scope]
class ConfigureTariffService : IConfigureNamedOptions<TariffService>
{
public ConfigureTariffService(
@ -686,19 +688,4 @@ namespace ASC.Core.Billing
}
}
}
public static class TariffConfigExtension
{
public static DIHelper AddTariffService(this DIHelper services)
{
if (services.TryAddScoped<ITariffService, TariffService>())
{
services.AddCoreDbContextService();
services.TryAddSingleton<TariffServiceStorage>();
services.TryAddScoped<IConfigureOptions<TariffService>, ConfigureTariffService>();
}
return services;
}
}
}

View File

@ -29,11 +29,11 @@ using System.Collections.Generic;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Core.Common.EF;
using ASC.Core.Data;
namespace ASC.Core.Caching
{
{
[Singletone]
class AzServiceCache
{
internal ICache Cache { get; }
@ -72,7 +72,8 @@ namespace ASC.Core.Caching
return "acl" + tenant.ToString();
}
}
[Scope]
class CachedAzService : IAzService
{
private readonly IAzService service;
@ -118,20 +119,4 @@ namespace ASC.Core.Caching
cacheNotify.Publish(r, CacheNotifyAction.Remove);
}
}
public static class AzConfigExtension
{
public static DIHelper AddAzService(this DIHelper services)
{
if (services.TryAddScoped<DbAzService>())
{
services.TryAddScoped<IAzService, CachedAzService>();
services.TryAddSingleton<AzServiceCache>();
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
services.AddCoreDbContextService();
}
return services;
}
}
}

View File

@ -30,7 +30,6 @@ using System.Linq;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Core.Common.EF;
using ASC.Core.Data;
using ASC.Core.Tenants;
@ -38,7 +37,8 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
namespace ASC.Core.Caching
{
{
[Singletone]
class QuotaServiceCache
{
internal const string KEY_QUOTA = "quota";
@ -78,7 +78,8 @@ namespace ASC.Core.Caching
}, CacheNotifyAction.Any);
}
}
[Scope]
class ConfigureCachedQuotaService : IConfigureNamedOptions<CachedQuotaService>
{
private IOptionsSnapshot<DbQuotaService> Service { get; }
@ -106,7 +107,8 @@ namespace ASC.Core.Caching
options.CacheNotify = QuotaServiceCache.CacheNotify;
}
}
[Scope]
class CachedQuotaService : IQuotaService
{
internal IQuotaService Service { get; set; }
@ -237,25 +239,4 @@ namespace ASC.Core.Caching
}
}
}
public static class QuotaConfigExtension
{
public static DIHelper AddQuotaService(this DIHelper services)
{
if (services.TryAddScoped<DbQuotaService>())
{
services.TryAddScoped<IQuotaService, CachedQuotaService>();
services.TryAddScoped<IConfigureOptions<DbQuotaService>, ConfigureDbQuotaService>();
services.TryAddScoped<IConfigureOptions<CachedQuotaService>, ConfigureCachedQuotaService>();
services.AddCoreDbContextService();
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
services.TryAddSingleton<QuotaServiceCache>();
}
return services;
}
}
}

View File

@ -30,11 +30,11 @@ using System.Linq;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Core.Common.EF;
using ASC.Core.Data;
namespace ASC.Core.Caching
{
[Singletone]
class SubscriptionServiceCache
{
internal ICache Cache { get; }
@ -102,6 +102,7 @@ namespace ASC.Core.Caching
}
}
[Scope]
class CachedSubscriptionService : ISubscriptionService
{
private readonly ISubscriptionService service;
@ -285,20 +286,4 @@ namespace ASC.Core.Caching
methodsByRec = methods.GroupBy(r => r.RecipientId).ToDictionary(g => g.Key, g => g.ToList());
}
}
public static class SubscriptionConfigExtension
{
public static DIHelper AddSubscriptionService(this DIHelper services)
{
if (services.TryAddScoped<DbSubscriptionService>())
{
services.TryAddScoped<ISubscriptionService, CachedSubscriptionService>();
services.TryAddSingleton<SubscriptionServiceCache>();
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
services.AddUserDbContextService();
}
return services;
}
}
}

View File

@ -29,15 +29,14 @@ using System.Collections.Generic;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Common.Utils;
using ASC.Core.Common.EF.Context;
using ASC.Core.Data;
using ASC.Core.Tenants;
using Microsoft.Extensions.Options;
namespace ASC.Core.Caching
{
{
[Singletone]
class TenantServiceCache
{
private const string KEY = "tenants";
@ -151,7 +150,8 @@ namespace ASC.Core.Caching
}
}
}
[Scope]
class ConfigureCachedTenantService : IConfigureNamedOptions<CachedTenantService>
{
private IOptionsSnapshot<DbTenantService> Service { get; }
@ -179,7 +179,8 @@ namespace ASC.Core.Caching
options.CacheNotifySettings = TenantServiceCache.CacheNotifySettings;
}
}
[Scope]
class CachedTenantService : ITenantService
{
internal ITenantService Service { get; set; }
@ -302,29 +303,4 @@ namespace ASC.Core.Caching
CacheNotifySettings.Publish(new TenantSetting { Key = cacheKey }, CacheNotifyAction.Remove);
}
}
public static class TenantConfigExtension
{
public static DIHelper AddTenantService(this DIHelper services)
{
if (services.TryAddScoped<DbTenantService>())
{
services.TryAddScoped<ITenantService, CachedTenantService>();
services.TryAddScoped<IConfigureOptions<DbTenantService>, ConfigureDbTenantService>();
services.TryAddScoped<IConfigureOptions<CachedTenantService>, ConfigureCachedTenantService>();
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
services.TryAddSingleton<TenantDomainValidator>();
services.TryAddSingleton<TimeZoneConverter>();
services.TryAddSingleton<TenantServiceCache>();
return services
.AddCoreBaseSettingsService()
.AddTenantDbContextService();
}
return services;
}
}
}

View File

@ -32,17 +32,16 @@ using System.Threading;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Common.Logging;
using ASC.Core.Common.EF;
using ASC.Core.Data;
using ASC.Core.Tenants;
using ASC.Core.Users;
using ASC.Security.Cryptography;
using Microsoft.Extensions.Options;
namespace ASC.Core.Caching
{
{
[Singletone]
public class UserServiceCache
{
public const string USERS = "users";
@ -138,6 +137,7 @@ namespace ASC.Core.Caching
}
}
[Scope]
class ConfigureCachedUserService : IConfigureNamedOptions<CachedUserService>
{
internal IOptionsSnapshot<EFUserService> Service { get; }
@ -173,7 +173,8 @@ namespace ASC.Core.Caching
options.TrustInterval = UserServiceCache.TrustInterval;
}
}
[Scope]
public class CachedUserService : IUserService, ICachedService
{
internal IUserService Service { get; set; }
@ -520,28 +521,4 @@ namespace ASC.Core.Caching
public string Key { get; set; }
}
}
public static class UserConfigExtension
{
public static DIHelper AddUserService(this DIHelper services)
{
if (services.TryAddScoped<EFUserService>())
{
services.TryAddScoped<IUserService, CachedUserService>();
services.TryAddScoped<IConfigureOptions<EFUserService>, ConfigureEFUserService>();
services.TryAddScoped<IConfigureOptions<CachedUserService>, ConfigureCachedUserService>();
services.TryAddSingleton<UserServiceCache>();
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
services
.AddCoreSettingsService()
.AddLoggerService()
.AddUserDbContextService()
.AddPasswordHasherService();
}
return services;
}
}
}

View File

@ -377,7 +377,8 @@ namespace ASC.Core.Common.Configuration
return new DataStoreConsumer(TenantManager, CoreBaseSettings, CoreSettings, Configuration, Cache, ConsumerFactory, Name, Order, Props.ToDictionary(r => r.Key, r => r.Value), Additional.ToDictionary(r => r.Key, r => r.Value));
}
}
[Scope]
public class ConsumerFactory : IDisposable
{
public ILifetimeScope Builder { get; set; }
@ -432,13 +433,4 @@ namespace ASC.Core.Common.Configuration
Builder.Dispose();
}
}
public static class ConsumerFactoryExtension
{
public static DIHelper AddConsumerFactoryService(this DIHelper services)
{
services.TryAddScoped<ConsumerFactory>();
return services;
}
}
}

View File

@ -29,13 +29,13 @@ using System.Linq;
using ASC.Common;
using ASC.Common.Security.Authentication;
using ASC.Core.Caching;
using ASC.Core.Security.Authentication;
using ASC.Core.Tenants;
using ASC.Core.Users;
namespace ASC.Core
{
{
[Scope]
public class AuthManager
{
private readonly IUserService userService;
@ -83,19 +83,4 @@ namespace ASC.Core
return new UserAccount(u, tenantId, UserFormatter);
}
}
public static class AuthManagerExtension
{
public static DIHelper AddAuthManager(this DIHelper services)
{
if (services.TryAddScoped<AuthManager>())
{
return services
.AddUserService()
.AddUserFormatter()
.AddUserManagerService();
}
return services;
}
}
}

View File

@ -34,7 +34,8 @@ using ASC.Common.Security.Authorizing;
using ASC.Core.Caching;
namespace ASC.Core
{
{
[Scope]
public class AuthorizationManager
{
private readonly IAzService service;
@ -128,19 +129,4 @@ namespace ASC.Core
aces.Where(a => (a.SubjectId == subjectId || subjectId == Guid.Empty) && (a.ActionId == actionId || actionId == Guid.Empty) && a.ObjectId == objId);
}
}
public static class AuthorizationManagerConfigExtension
{
public static DIHelper AddAuthorizationManagerService(this DIHelper services)
{
if (services.TryAddScoped<AuthorizationManager>())
{
return services
.AddAzService()
.AddTenantManagerService();
}
return services;
}
}
}

View File

@ -39,7 +39,8 @@ using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace ASC.Core
{
{
[Singletone]
public class CoreBaseSettings
{
private bool? standalone;
@ -103,7 +104,8 @@ namespace ASC.Core
options.TenantService = TenantService.Value;
}
}
[Scope(typeof(ConfigureCoreSettings))]
public class CoreSettings
{
private string basedomain;
@ -242,7 +244,8 @@ namespace ASC.Core
return null;
}
}
[Scope]
public class CoreConfiguration
{
private long? personalMaxSpace;
@ -373,35 +376,4 @@ namespace ASC.Core
#endregion
}
public static class CoreSettingsConfigExtension
{
public static DIHelper AddCoreBaseSettingsService(this DIHelper services)
{
services.TryAddSingleton<CoreBaseSettings>();
return services;
}
public static DIHelper AddCoreSettingsService(this DIHelper services)
{
if (services.TryAddScoped<CoreSettings>())
{
services.TryAddScoped<CoreConfiguration>();
services.TryAddScoped<IConfigureOptions<CoreSettings>, ConfigureCoreSettings>();
return services
.AddCoreBaseSettingsService()
.AddTenantService();
}
return services;
}
public static DIHelper AddCoreConfigurationService(this DIHelper services)
{
services.TryAddScoped<CoreConfiguration>();
return services
.AddTenantManagerService()
.AddCoreSettingsService();
}
}
}

View File

@ -36,7 +36,6 @@ using System.Web;
using ASC.Common;
using ASC.Core.Billing;
using ASC.Core.Caching;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Configuration;
@ -45,7 +44,8 @@ using Newtonsoft.Json;
namespace ASC.Core
{
{
[Scope]
public class PaymentManager
{
private readonly ITariffService tariffService;
@ -182,20 +182,4 @@ namespace ASC.Core
public string stackTrace = null;
}
}
public static class PaymentManagerExtension
{
public static DIHelper AddPaymentManagerService(this DIHelper services)
{
if (services.TryAddScoped<PaymentManager>())
{
return services
.AddTenantManagerService()
.AddQuotaService()
.AddTariffService();
}
return services;
}
}
}

View File

@ -28,10 +28,10 @@ using System;
using System.Linq;
using ASC.Common;
using ASC.Core.Caching;
namespace ASC.Core
{
{
[Scope]
public class SubscriptionManager
{
private readonly ISubscriptionService service;
@ -148,19 +148,4 @@ namespace ASC.Core
return TenantManager.GetCurrentTenant().TenantId;
}
}
public static class SubscriptionConfigExtension
{
public static DIHelper AddSubscriptionManagerService(this DIHelper services)
{
if (services.TryAddScoped<SubscriptionManager>())
{
return services
.AddSubscriptionService()
.AddTenantManagerService();
}
return services;
}
}
}

View File

@ -41,7 +41,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
namespace ASC.Core
{
{
[Scope]
class ConfigureTenantManager : IConfigureNamedOptions<TenantManager>
{
private IOptionsSnapshot<CachedTenantService> TenantService { get; }
@ -88,7 +89,8 @@ namespace ASC.Core
options.TariffService = TariffService.Value;
}
}
[Scope(typeof(ConfigureTenantManager))]
public class TenantManager
{
private Tenant CurrentTenant { get; set; }
@ -352,24 +354,4 @@ namespace ASC.Core
return QuotaService.FindTenantQuotaRows(query).ToList();
}
}
public static class TenantManagerConfigExtension
{
public static DIHelper AddTenantManagerService(this DIHelper services)
{
if (services.TryAddScoped<TenantManager>())
{
services.TryAddScoped<IConfigureOptions<TenantManager>, ConfigureTenantManager>();
return services
.AddTenantService()
.AddQuotaService()
.AddTariffService()
.AddCoreBaseSettingsService()
.AddCoreSettingsService();
}
return services;
}
}
}

View File

@ -39,7 +39,8 @@ using ASC.Core.Users;
using Microsoft.AspNetCore.Http;
namespace ASC.Core
{
{
[Singletone]
public class UserManagerConstants
{
public IDictionary<Guid, UserInfo> SystemUsers { get; }
@ -54,7 +55,8 @@ namespace ASC.Core
Constants = constants;
}
}
[Scope]
public class UserManager
{
private IDictionary<Guid, UserInfo> SystemUsers { get => UserManagerConstants.SystemUsers; }
@ -652,23 +654,4 @@ namespace ASC.Core
};
}
}
public static class UserManagerConfigExtension
{
public static DIHelper AddUserManagerService(this DIHelper services)
{
if (services.TryAddScoped<UserManager>())
{
services.TryAddSingleton<UserManagerConstants>();
return services
.AddUserService()
.AddTenantManagerService()
.AddConstantsService()
.AddPermissionContextService();
}
return services;
}
}
}

View File

@ -41,7 +41,6 @@ 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;
@ -50,6 +49,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Core
{
[Scope]
public class SecurityContext
{
private readonly ILog log;
@ -290,6 +290,7 @@ namespace ASC.Core
}
}
[Scope]
public class PermissionContext
{
public IPermissionResolver PermissionResolver { get; set; }
@ -332,6 +333,7 @@ namespace ASC.Core
}
}
[Scope]
public class AuthContext
{
private IHttpContextAccessor HttpContextAccessor { get; }
@ -371,41 +373,4 @@ namespace ASC.Core
}
}
}
public static class AuthContextConfigExtension
{
public static DIHelper AddSecurityContextService(this DIHelper services)
{
if (services.TryAddScoped<SecurityContext>())
{
return services
.AddCookieStorageService()
.AddTenantCookieSettingsService()
.AddAuthManager()
.AddUserFormatter()
.AddAuthContextService()
.AddUserManagerService()
.AddTenantManagerService();
}
return services;
}
public static DIHelper AddAuthContextService(this DIHelper services)
{
services.TryAddScoped<AuthContext>();
return services;
}
public static DIHelper AddPermissionContextService(this DIHelper services)
{
if (services.TryAddScoped<PermissionContext>())
{
return services
.AddAuthContextService()
.AddPermissionResolverService();
}
return services;
}
}
}

View File

@ -27,7 +27,8 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Common.Logging;
using ASC.Core.Common.Notify;
@ -103,14 +104,13 @@ namespace ASC.Core
var configuration = serviceProvider.GetService<IConfiguration>();
var cacheNotify = serviceProvider.GetService<ICacheNotify<NotifyMessage>>();
var cacheInvoke = serviceProvider.GetService<ICacheNotify<NotifyInvoke>>();
var options = serviceProvider.GetService<IOptionsMonitor<ILog>>();
var telegramHelper = serviceProvider.GetService<TelegramHelper>();
var options = serviceProvider.GetService<IOptionsMonitor<ILog>>();
NotifyContext = new NotifyContext(serviceProvider);
INotifySender jabberSender = new NotifyServiceSender(cacheNotify, cacheInvoke);
INotifySender emailSender = new NotifyServiceSender(cacheNotify, cacheInvoke);
INotifySender telegramSender = new TelegramSender(options, telegramHelper);
INotifySender telegramSender = new TelegramSender(options, serviceProvider);
var postman = configuration["core:notify:postman"];
@ -169,5 +169,15 @@ namespace ASC.Core
tenantManager.SetCurrentTenant(tenant);
}
}
}
public class WorkContextExtension
{
public static void Register(DIHelper dIHelper)
{
dIHelper.TryAdd<TelegramHelper>();
dIHelper.TryAdd<EmailSenderSinkScope>();
dIHelper.TryAdd<JabberSenderSinkScope>();
}
}
}

View File

@ -277,7 +277,8 @@ namespace TMResourceData
}
}
}
[Singletone]
public class WhiteLabelHelper
{
private readonly ILog log;
@ -366,13 +367,4 @@ namespace TMResourceData
return resourceValue;
}
}
public static class WhiteLabelHelperExtension
{
public static DIHelper AddWhiteLabelHelperService(this DIHelper services)
{
services.TryAddSingleton<WhiteLabelHelper>();
return services;
}
}
}

View File

@ -25,10 +25,15 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using ASC.Common;
using ASC.Core.Caching;
using ASC.Core.Data;
namespace ASC.Core
{
{
[Scope(typeof(DbAzService), typeof(CachedAzService))]
public interface IAzService
{
IEnumerable<AzRecord> GetAces(int tenant, DateTime from);

View File

@ -26,10 +26,14 @@
using System.Collections.Generic;
using ASC.Common;
using ASC.Core.Caching;
using ASC.Core.Data;
using ASC.Core.Tenants;
namespace ASC.Core
{
{
[Scope(typeof(ConfigureDbQuotaService), typeof(ConfigureCachedQuotaService))]
public interface IQuotaService
{
IEnumerable<TenantQuota> GetTenantQuotas();

View File

@ -24,10 +24,15 @@
*/
using System.Collections.Generic;
using System.Collections.Generic;
using ASC.Common;
using ASC.Core.Caching;
using ASC.Core.Data;
namespace ASC.Core
{
{
[Scope(typeof(DbSubscriptionService), typeof(CachedSubscriptionService))]
public interface ISubscriptionService
{
IEnumerable<SubscriptionRecord> GetSubscriptions(int tenant, string sourceId, string actionId);

View File

@ -27,10 +27,14 @@
using System;
using System.Collections.Generic;
using ASC.Common;
using ASC.Core.Caching;
using ASC.Core.Data;
using ASC.Core.Tenants;
namespace ASC.Core
{
{
[Scope(typeof(ConfigureDbTenantService), typeof(ConfigureCachedTenantService))]
public interface ITenantService
{
void ValidateDomain(string domain);

View File

@ -29,11 +29,15 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ASC.Common;
using ASC.Core.Caching;
using ASC.Core.Common.EF;
using ASC.Core.Data;
using ASC.Core.Users;
namespace ASC.Core
{
{
[Scope(typeof(ConfigureEFUserService), typeof(ConfigureCachedUserService))]
public interface IUserService
{
IDictionary<Guid, UserInfo> GetUsers(int tenant, DateTime from);

View File

@ -29,11 +29,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ASC.Common;
using ASC.Core.Common.EF;
using ASC.Core.Tenants;
namespace ASC.Core.Data
{
{
[Scope]
class DbAzService : IAzService
{
public Expression<Func<Acl, AzRecord>> FromAclToAzRecord { get; set; }

View File

@ -29,13 +29,15 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ASC.Common;
using ASC.Core.Common.EF;
using ASC.Core.Tenants;
using Microsoft.Extensions.Options;
namespace ASC.Core.Data
{
{
[Scope]
class ConfigureDbQuotaService : IConfigureNamedOptions<DbQuotaService>
{
private DbContextManager<CoreDbContext> DbContextManager { get; }
@ -56,7 +58,8 @@ namespace ASC.Core.Data
options.LazyCoreDbContext = new Lazy<CoreDbContext>(() => DbContextManager.Value);
}
}
[Scope]
class DbQuotaService : IQuotaService
{
private Expression<Func<DbQuota, TenantQuota>> FromDbQuotaToTenantQuota { get; set; }

View File

@ -41,7 +41,8 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace ASC.Core.Data
{
{
[Singletone]
public class DbSettingsManagerCache
{
public ICache Cache { get; }
@ -59,7 +60,8 @@ namespace ASC.Core.Data
Notify.Publish(new SettingsCacheItem { Key = key }, CacheNotifyAction.Remove);
}
}
[Scope]
class ConfigureDbSettingsManager : IConfigureNamedOptions<DbSettingsManager>
{
private IServiceProvider ServiceProvider { get; }
@ -105,7 +107,8 @@ namespace ASC.Core.Data
options.LazyWebstudioDbContext = new Lazy<WebstudioDbContext>(() => DbContextManager.Value);
}
}
[Scope(typeof(ConfigureDbSettingsManager))]
public class DbSettingsManager
{
private readonly TimeSpan expirationTimeout = TimeSpan.FromMinutes(5);
@ -330,20 +333,4 @@ namespace ASC.Core.Data
}
}
public static class DbSettingsManagerExtension
{
public static DIHelper AddDbSettingsManagerService(this DIHelper services)
{
if (services.TryAddScoped<DbSettingsManager>())
{
services.TryAddScoped<IConfigureOptions<DbSettingsManager>, ConfigureDbSettingsManager>();
services.TryAddSingleton<DbSettingsManagerCache>();
return services.AddWebstudioDbContextService();
}
return services;
}
}
}

View File

@ -29,11 +29,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ASC.Common;
using ASC.Core.Common.EF;
using ASC.Core.Tenants;
namespace ASC.Core.Data
{
{
[Scope]
class DbSubscriptionService : ISubscriptionService
{
private Expression<Func<Subscription, SubscriptionRecord>> FromSubscriptionToSubscriptionRecord { get; set; }

View File

@ -30,6 +30,7 @@ using System.Linq;
using System.Linq.Expressions;
using System.Text;
using ASC.Common;
using ASC.Core.Common.EF;
using ASC.Core.Common.EF.Context;
using ASC.Core.Common.EF.Model;
@ -41,7 +42,8 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace ASC.Core.Data
{
{
[Scope]
public class ConfigureDbTenantService : IConfigureNamedOptions<DbTenantService>
{
private TenantDomainValidator TenantDomainValidator { get; }
@ -68,6 +70,7 @@ namespace ASC.Core.Data
}
}
[Scope]
public class DbTenantService : ITenantService
{
private List<string> forbiddenDomains;

View File

@ -30,6 +30,7 @@ using System.Linq;
using System.Linq.Expressions;
using System.Text;
using ASC.Common;
using ASC.Core.Common.EF;
using ASC.Core.Tenants;
using ASC.Core.Users;
@ -38,7 +39,8 @@ using ASC.Security.Cryptography;
using Microsoft.Extensions.Options;
namespace ASC.Core.Data
{
{
[Scope]
public class ConfigureEFUserService : IConfigureNamedOptions<EFUserService>
{
private DbContextManager<UserDbContext> DbContextManager { get; }
@ -63,7 +65,7 @@ namespace ASC.Core.Data
}
}
[Scope]
public class EFUserService : IUserService
{
public Expression<Func<User, UserInfo>> FromUserToUserInfo { get; set; }

View File

@ -1,6 +1,7 @@
using System;
using System.Linq;
using ASC.Common;
using ASC.Common.Logging;
using ASC.Common.Utils;
@ -9,7 +10,8 @@ using Microsoft.Extensions.Options;
namespace ASC.Core.Common.EF
{
public class ConfigureDbContext : IConfigureNamedOptions<BaseDbContext>
[Scope]
public class ConfigureDbContext<T> : IConfigureNamedOptions<T> where T : BaseDbContext, new()
{
public const string baseName = "default";
private EFLoggerFactory LoggerFactory { get; }
@ -21,13 +23,13 @@ namespace ASC.Core.Common.EF
Configuration = configuration;
}
public void Configure(string name, BaseDbContext context)
public void Configure(string name, T context)
{
context.LoggerFactory = LoggerFactory;
context.ConnectionStringSettings = Configuration.GetConnectionStrings(name) ?? Configuration.GetConnectionStrings(baseName);
}
public void Configure(BaseDbContext context)
public void Configure(T context)
{
Configure(baseName, context);
}

View File

@ -1,12 +1,11 @@

using ASC.Common;
using System;
using System.Collections.Generic;
using ASC.Core.Common.EF.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
namespace ASC.Core.Common.EF
{
public class MySqlCoreDbContext : CoreDbContext { }
@ -40,13 +39,4 @@ namespace ASC.Core.Common.EF
.AddDbTariff();
}
}
public static class CoreDbExtension
{
public static DIHelper AddCoreDbContextService(this DIHelper services)
{
return services.AddDbContextManagerService<CoreDbContext>();
}
}
}

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using ASC.Common;
using ASC.Common.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
@ -66,6 +65,7 @@ namespace ASC.Core.Common.EF
}
}
[Scope(typeof(ConfigureDbContext<>))]
public class DbContextManager<T> : BaseDbContextManager<T> where T : BaseDbContext, new()
{
public DbContextManager(IOptionsFactory<T> factory, IConfiguration configuration) : base(factory, configuration)
@ -84,13 +84,9 @@ namespace ASC.Core.Common.EF
{
public static DIHelper AddDbContextManagerService<T>(this DIHelper services) where T : BaseDbContext, new()
{
if (services.TryAddScoped<DbContextManager<T>>())
{
services.TryAddScoped<MultiRegionalDbContextManager<T>>();
services.TryAddScoped<IConfigureOptions<T>, ConfigureDbContext>();
services.TryAddScoped<IConfigureOptions<MultiRegionalDbContext<T>>, ConfigureMultiRegionalDbContext<T>>();
return services.AddLoggerService();
}
//TODO
//services.TryAddScoped<MultiRegionalDbContextManager<T>>();
//services.TryAddScoped<IConfigureOptions<MultiRegionalDbContext<T>>, ConfigureMultiRegionalDbContext<T>>();
return services;
}
}

View File

@ -103,7 +103,8 @@ namespace ASC.Core
hostedSolution.CoreSettings = CoreSettings.Get(name);
}
}
[Scope(typeof(ConfigureHostedSolution))]
public class HostedSolution
{
internal ITenantService TenantService { get; set; }
@ -283,27 +284,5 @@ namespace ASC.Core
}
return tenant;
}
}
public static class HostedSolutionExtension
{
public static DIHelper AddHostedSolutionService(this DIHelper services)
{
if (services.TryAddScoped<IConfigureOptions<HostedSolution>, ConfigureHostedSolution>())
{
return services
.AddUserFormatter()
.AddTenantService()
.AddUserService()
.AddQuotaService()
.AddTariffService()
.AddTenantManagerService()
.AddTenantUtilService()
.AddDbSettingsManagerService()
.AddCoreSettingsService();
}
return services;
}
}
}

View File

@ -41,7 +41,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Core.Notify
{
class EmailSenderSink : Sink
public class EmailSenderSink : Sink
{
private static readonly string senderName = ASC.Core.Configuration.Constants.NotifyEMailSenderSysName;
private readonly INotifySender sender;
@ -166,7 +166,8 @@ namespace ASC.Core.Notify
return m;
}
}
[Scope]
public class EmailSenderSinkScope
{
private TenantManager TenantManager { get; }
@ -185,13 +186,4 @@ namespace ASC.Core.Notify
(tenantManager, coreConfiguration, optionsMonitor) = (TenantManager, CoreConfiguration, Options);
}
}
public static class EmailSenderSinkExtension
{
public static DIHelper AddEmailSenderSinkService(this DIHelper services)
{
services.TryAddScoped<EmailSenderSinkScope>();
return services;
}
}
}

View File

@ -23,8 +23,12 @@
*
*/
using ASC.Common;
using ASC.Core.Notify;
namespace ASC.Notify.Recipients
{
{
[Scope(typeof(RecipientProviderImpl))]
public interface IRecipientProvider
{
IRecipient GetRecipient(string id);

View File

@ -32,7 +32,8 @@ using ASC.Common;
using ASC.Core.Common.Notify.Jabber;
namespace ASC.Core.Notify.Jabber
{
{
[Scope]
public class JabberServiceClient
{
private static readonly TimeSpan Timeout = TimeSpan.FromMinutes(2);
@ -239,20 +240,4 @@ namespace ASC.Core.Notify.Jabber
return new JabberServiceClientWcf();
}
}
public static class JabberServiceClientExtension
{
public static DIHelper AddJabberServiceClient(this DIHelper services)
{
if (services.TryAddScoped<JabberServiceClient>())
{
return services
.AddUserManagerService()
.AddAuthContextService()
.AddTenantManagerService();
}
return services;
}
}
}

View File

@ -88,7 +88,8 @@ namespace ASC.Core.Notify
}
}
}
[Scope]
public class JabberSenderSinkScope
{
private UserManager UserManager { get; }
@ -104,14 +105,5 @@ namespace ASC.Core.Notify
{
(userManager, tenantManager) = (UserManager, TenantManager);
}
}
public static class JabberSenderSinkExtension
{
public static DIHelper AddJabberSenderSinkService(this DIHelper services)
{
services.TryAddScoped<JabberSenderSinkScope>();
return services;
}
}
}

View File

@ -24,12 +24,14 @@
*/
using ASC.Common;
using ASC.Common.Caching;
using ASC.Notify;
using ASC.Notify.Messages;
namespace ASC.Core.Notify
{
{
[Scope]
public class NotifyServiceClient : INotifyService
{
private readonly ICacheNotify<NotifyMessage> СacheNotify;

View File

@ -26,9 +26,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using ASC.Common;
using ASC.Core.Users;
using ASC.Notify.Recipients;
@ -158,15 +157,4 @@ namespace ASC.Core.Notify
return false;
}
}
public static class RecipientProviderImplExtension
{
public static DIHelper AddRecipientProviderImplService(this DIHelper services)
{
services.TryAddScoped(typeof(IRecipientProvider), typeof(RecipientProviderImpl));
return services
.AddUserManagerService();
}
}
}

View File

@ -45,8 +45,9 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace ASC.Core.Notify.Senders
{
class AWSSender : SmtpSender
{
[Singletone(Additional = typeof(AWSSenderExtension))]
public class AWSSender : SmtpSender
{
private readonly object locker = new object();
private AmazonSimpleEmailServiceClient ses;
@ -229,7 +230,8 @@ namespace ASC.Core.Notify.Senders
return quota == null || (DateTime.UtcNow - lastRefresh) > refreshTimeout;
}
}
[Scope]
public class AWSSenderScope
{
private TenantManager TenantManager { get; }
@ -247,15 +249,11 @@ namespace ASC.Core.Notify.Senders
}
}
public static class AWSSenderExtension
public class AWSSenderExtension
{
public static DIHelper AddAWSSenderService(this DIHelper services)
public static void Register(DIHelper services)
{
services.TryAddSingleton<AWSSender>();
services.TryAddScoped<AWSSenderScope>();
return services
.AddTenantManagerService()
.AddCoreSettingsService();
services.TryAdd<AWSSenderScope>();
}
}
}

View File

@ -37,7 +37,8 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace ASC.Core.Notify.Senders
{
{
[Singletone(Additional = typeof(JabberSenderExtension))]
public class JabberSender : INotifySender
{
private readonly ILog log;
@ -75,14 +76,13 @@ namespace ASC.Core.Notify.Senders
}
return NoticeSendResult.OK;
}
}
public static class JabberSenderExtension
}
public class JabberSenderExtension
{
public static DIHelper AddJabberSenderService(this DIHelper services)
public static void Register(DIHelper services)
{
services.TryAddSingleton<JabberSender>();
return services.AddJabberServiceClient();
services.TryAdd<JabberServiceClient>();
}
}
}

View File

@ -45,8 +45,9 @@ using Microsoft.Extensions.Options;
using MimeKit;
namespace ASC.Core.Notify.Senders
{
internal class SmtpSender : INotifySender
{
[Singletone(Additional = typeof(SmtpSenderExtension))]
public class SmtpSender : INotifySender
{
private const string HTML_FORMAT =
@"<!DOCTYPE html PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"">
@ -321,7 +322,8 @@ namespace ASC.Core.Notify.Senders
}
}
}
[Scope]
public class SmtpSenderScope
{
private TenantManager TenantManager { get; }
@ -339,15 +341,11 @@ namespace ASC.Core.Notify.Senders
}
}
public static class SmtpSenderExtension
public class SmtpSenderExtension
{
public static DIHelper AddSmtpSenderService(this DIHelper services)
public static void Register(DIHelper services)
{
services.TryAddSingleton<SmtpSender>();
services.TryAddScoped<SmtpSenderScope>();
return services
.AddTenantManagerService()
.AddCoreSettingsService();
services.TryAdd<SmtpSenderScope>();
}
}
}

View File

@ -31,6 +31,7 @@ using ASC.Common.Logging;
using ASC.Core.Common.Notify;
using ASC.Notify.Messages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace ASC.Core.Notify.Senders
@ -38,14 +39,14 @@ namespace ASC.Core.Notify.Senders
public class TelegramSender : INotifySender
{
private readonly ILog log;
private TelegramHelper TelegramHelper { get; }
public TelegramSender(IOptionsMonitor<ILog> options, TelegramHelper telegramHelper)
public TelegramSender(IOptionsMonitor<ILog> options, IServiceProvider serviceProvider)
{
log = options.Get("ASC");
TelegramHelper = telegramHelper;
ServiceProvider = serviceProvider;
}
public IServiceProvider ServiceProvider { get; }
public void Init(IDictionary<string, string> properties)
{
@ -59,7 +60,9 @@ namespace ASC.Core.Notify.Senders
m.Content = Regex.Replace(m.Content, "\n{3,}", "\n\n");
}
try
{
{
using var scope = ServiceProvider.CreateScope();
var TelegramHelper = scope.ServiceProvider.GetService<TelegramHelper>();
TelegramHelper.SendMessage(m);
}
catch (Exception e)

View File

@ -43,7 +43,8 @@ using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace ASC.Core.Notify.Signalr
{
{
[Scope]
public class ConfigureSignalrServiceClient : IConfigureNamedOptions<SignalrServiceClient>
{
internal TenantManager TenantManager { get; }
@ -100,7 +101,8 @@ namespace ASC.Core.Notify.Signalr
Configure("default", options);
}
}
[Scope(typeof(ConfigureSignalrServiceClient))]
public class SignalrServiceClient
{
private static readonly TimeSpan Timeout;
@ -394,22 +396,4 @@ namespace ASC.Core.Notify.Signalr
return string.Format("ASC {0}:{1}:{2}", pkey, now, hash);
}
}
public static class SignalrServiceClientExtension
{
public static DIHelper AddSignalrServiceClient(this DIHelper services)
{
if (services.TryAddScoped<SignalrServiceClient>())
{
services.TryAddScoped<IConfigureNamedOptions<SignalrServiceClient>, ConfigureSignalrServiceClient>();
return services
.AddTenantManagerService()
.AddCoreSettingsService()
.AddMachinePseudoKeysService();
}
return services;
}
}
}

View File

@ -30,7 +30,6 @@ using System.Linq;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Core.Common.EF.Context;
using ASC.Core.Common.EF.Model;
using Microsoft.Extensions.Options;
@ -62,7 +61,8 @@ namespace ASC.Core.Common.Notify.Telegram
options.SingleKeyFormat = "tgUser:{0}";
}
}
[Scope(typeof(ConfigureCachedTelegramDao))]
public class CachedTelegramDao
{
public TelegramDao TgDao { get; set; }
@ -116,24 +116,5 @@ namespace ASC.Core.Common.Notify.Telegram
var key = string.Format(PairKeyFormat, userId, tenantId);
Cache.Insert(key, new TelegramUser { PortalUserId = userId, TenantId = tenantId, TelegramUserId = telegramId }, Expiration);
}
}
public static class CachedTelegramDaoExtension
{
public static DIHelper AddCachedTelegramDaoService(this DIHelper services)
{
if (services.TryAddScoped<TelegramDao>())
{
services.TryAddScoped<IConfigureOptions<TelegramDao>, ConfigureTelegramDaoService>();
services.TryAddScoped<IConfigureOptions<CachedTelegramDao>, ConfigureCachedTelegramDao>();
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
return services.AddTelegramDbContextService();
}
return services;
}
}
}

View File

@ -28,6 +28,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using ASC.Common;
using ASC.Core.Common.EF;
using ASC.Core.Common.EF.Context;
using ASC.Core.Common.EF.Model;
@ -58,6 +59,7 @@ namespace ASC.Core.Common.Notify.Telegram
}
}
[Scope(typeof(ConfigureTelegramDaoService))]
public class TelegramDao
{
public TelegramDbContext TelegramDbContext { get; set; }

View File

@ -40,7 +40,8 @@ using Microsoft.Extensions.Options;
using Telegram.Bot;
namespace ASC.Core.Common.Notify
{
{
[Scope]
public class TelegramHelper
{
public enum RegStatus
@ -169,18 +170,5 @@ namespace ASC.Core.Common.Notify
{
return string.IsNullOrEmpty(proxy) ? new TelegramBotClient(token) : new TelegramBotClient(token, new WebProxy(proxy));
}
}
public static class TelegramHelperExtension
{
public static DIHelper AddTelegramHelperSerivce(this DIHelper services)
{
if (services.TryAddScoped<TelegramHelper>())
{
return services.AddTelegramServiceClient()
.AddCachedTelegramDaoService();
}
return services;
}
}
}

View File

@ -31,7 +31,8 @@ using ASC.Common.Caching;
using ASC.Notify.Messages;
namespace ASC.Core.Common.Notify
{
{
[Singletone]
public class TelegramServiceClient : ITelegramService
{
private ICacheNotify<NotifyMessage> CacheMessage { get; }
@ -95,13 +96,4 @@ namespace ASC.Core.Common.Notify
return "Token" + userId + tenantId;
}
}
public static class TelegramServiceClientExtension
{
public static DIHelper AddTelegramServiceClient(this DIHelper services)
{
services.TryAddSingleton<TelegramServiceClient>();
return services;
}
}
}

View File

@ -38,6 +38,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Core.Security.Authentication
{
[Scope]
public class CookieStorage
{
private const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss,fff";
@ -141,19 +142,4 @@ namespace ASC.Core.Security.Authentication
return Hasher.Base64Hash(data ?? string.Empty, HashAlg.SHA256);
}
}
public static class CookieStorageExtension
{
public static DIHelper AddCookieStorageService(this DIHelper services)
{
if (services.TryAddScoped<CookieStorage>())
{
return services
.AddTenantCookieSettingsService()
.AddInstanceCryptoService();
}
return services;
}
}
}

View File

@ -26,11 +26,10 @@
using System;
using System.Collections.Generic;
using ASC.Core.Security.Authorizing;
namespace ASC.Common.Security.Authorizing
{
{
[Scope]
public class AzManager
{
private readonly IPermissionProvider permissionProvider;
@ -146,19 +145,4 @@ namespace ASC.Common.Security.Authorizing
#endregion
}
public static class AzManagerConfigExtension
{
public static DIHelper AddAzManagerService(this DIHelper services)
{
if (services.TryAddScoped<AzManager>())
{
return services
.AddPermissionProviderService()
.AddRoleProviderService();
}
return services;
}
}
}

View File

@ -27,9 +27,11 @@
using System.Collections.Generic;
using ASC.Common.Security.Authorizing;
using ASC.Core.Security.Authorizing;
namespace ASC.Common.Security
{
{
[Scope(typeof(PermissionProvider))]
public interface IPermissionProvider
{
IEnumerable<Ace> GetAcl(ISubject subject, IAction action, ISecurityObjectId objectId, ISecurityObjectProvider secObjProvider);

View File

@ -25,9 +25,11 @@
using ASC.Common.Security.Authorizing;
using ASC.Core.Security.Authorizing;
namespace ASC.Common.Security
{
{
[Scope(typeof(PermissionResolver))]
public interface IPermissionResolver
{
bool Check(ISubject subject, params IAction[] actions);

View File

@ -26,9 +26,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using ASC.Common;
using ASC.Common.Security;
using ASC.Common.Security.Authorizing;
@ -53,13 +52,4 @@ namespace ASC.Core.Security.Authorizing
.Select(r => new Ace(r.ActionId, r.Reaction));
}
}
public static class PermissionProviderConfigExtension
{
public static DIHelper AddPermissionProviderService(this DIHelper services)
{
services.TryAddScoped(typeof(IPermissionProvider), typeof(PermissionProvider));
return services.AddAuthorizationManagerService();
}
}
}

View File

@ -36,7 +36,8 @@ using ASC.Common.Security.Authorizing;
using Constants = ASC.Core.Configuration.Constants;
namespace ASC.Core.Security.Authorizing
{
{
[Scope]
class PermissionResolver : IPermissionResolver
{
private readonly AzManager azManager;
@ -123,13 +124,4 @@ namespace ASC.Core.Security.Authorizing
}
}
}
public static class PermissionResolverConfigExtention
{
public static DIHelper AddPermissionResolverService(this DIHelper services)
{
services.TryAddScoped(typeof(IPermissionResolver), typeof(PermissionResolver));
return services.AddAzManagerService();
}
}
}

View File

@ -37,7 +37,8 @@ using ASC.Core.Users;
using Microsoft.Extensions.DependencyInjection;
namespace ASC.Core.Security.Authorizing
{
{
[Scope]
class RoleProvider : IRoleProvider
{
//circ dep
@ -85,13 +86,4 @@ namespace ASC.Core.Security.Authorizing
return roles;
}
}
public static class RoleProviderConfigExtention
{
public static DIHelper AddRoleProviderService(this DIHelper services)
{
services.TryAddScoped(typeof(IRoleProvider), typeof(RoleProvider));
return services;
}
}
}

View File

@ -41,7 +41,8 @@ using Microsoft.Extensions.Options;
using static ASC.Security.Cryptography.EmailValidationKeyProvider;
namespace ASC.Security.Cryptography
{
{
[Scope]
public class EmailValidationKeyProvider
{
public enum ValidationResult
@ -164,6 +165,7 @@ namespace ASC.Security.Cryptography
}
}
[Transient]
public class EmailValidationKeyModelHelper
{
private IHttpContextAccessor HttpContextAccessor { get; }
@ -272,21 +274,4 @@ namespace ASC.Security.Cryptography
return checkKeyResult;
}
}
public static class EmailValidationKeyProviderExtension
{
public static DIHelper AddEmailValidationKeyProviderService(this DIHelper services)
{
if (services.TryAddScoped<EmailValidationKeyProvider>())
{
services.TryAddTransient<EmailValidationKeyModelHelper>();
return services
.AddTenantManagerService()
.AddMachinePseudoKeysService();
}
return services;
}
}
}

View File

@ -27,9 +27,11 @@
using System.Collections.Generic;
using ASC.Common.Security.Authorizing;
using ASC.Core.Security.Authorizing;
namespace ASC.Common.Security
{
{
[Scope(typeof(RoleProvider))]
public interface IRoleProvider
{
List<IRole> GetRoles(ISubject account);

View File

@ -35,7 +35,8 @@ using ASC.Core.Data;
using Microsoft.Extensions.Options;
namespace ASC.Core.Common.Settings
{
{
[Scope]
public class SettingsManager : DbSettingsManager
{
public SettingsManager(
@ -50,19 +51,4 @@ namespace ASC.Core.Common.Settings
}
}
public static class SettingsManagerExtention
{
public static DIHelper AddSettingsManagerService(this DIHelper services)
{
if (services.TryAddScoped<SettingsManager>())
{
return services
.AddAuthContextService()
.AddDbSettingsManagerService();
}
return services;
}
}
}

View File

@ -65,6 +65,7 @@ namespace ASC.Core.Tenants
}
}
[Scope]
public class TenantCookieSettingsHelper
{
public bool IsVisibleSettings { get; internal set; }
@ -119,18 +120,5 @@ namespace ASC.Core.Tenants
var expires = settingsTenant.IsDefault() ? DateTime.UtcNow.AddYears(1) : DateTime.UtcNow.AddMinutes(settingsTenant.LifeTime);
return expires;
}
}
public static class TenantCookieSettingsExtention
{
public static DIHelper AddTenantCookieSettingsService(this DIHelper services)
{
if (services.TryAddScoped<TenantCookieSettingsHelper>())
{
return services.AddSettingsManagerService();
}
return services;
}
}
}

View File

@ -27,10 +27,13 @@
using System;
using System.Text.RegularExpressions;
using ASC.Common;
using Microsoft.Extensions.Configuration;
namespace ASC.Core.Tenants
{
{
[Singletone]
public class TenantDomainValidator
{
private static readonly Regex ValidDomain = new Regex("^[a-z0-9]([a-z0-9-]){1,98}[a-z0-9]$",

View File

@ -32,7 +32,8 @@ using ASC.Common.Utils;
using Microsoft.Extensions.Options;
namespace ASC.Core.Tenants
{
{
[Scope]
class ConfigureTenantUtil : IConfigureNamedOptions<TenantUtil>
{
private IOptionsSnapshot<TenantManager> TenantManager { get; }
@ -59,7 +60,8 @@ namespace ASC.Core.Tenants
options.TenantManager = TenantManager.Value;
}
}
[Scope(typeof(ConfigureTenantUtil))]
public class TenantUtil
{
internal TenantManager TenantManager { get; set; }
@ -146,18 +148,4 @@ namespace ASC.Core.Tenants
return DateTimeNow(TimeZoneConverter.GetTimeZone(timeZone));
}
}
public static class TenantUtilExtention
{
public static DIHelper AddTenantUtilService(this DIHelper services)
{
if (services.TryAddScoped<TenantUtil>())
{
services.TryAddScoped<IConfigureOptions<TenantUtil>, ConfigureTenantUtil>();
return services.AddTenantManagerService();
}
return services;
}
}
}

View File

@ -34,7 +34,8 @@ using Action = ASC.Common.Security.Authorizing.Action;
using AuthConst = ASC.Common.Security.Authorizing.Constants;
namespace ASC.Core.Users
{
{
[Singletone]
public sealed class Constants
{
public Constants(IConfiguration configuration)
@ -144,13 +145,4 @@ namespace ASC.Core.Users
#endregion
}
public static class ConstantsConfigFactory
{
public static DIHelper AddConstantsService(this DIHelper services)
{
services.TryAddSingleton<Constants>();
return services;
}
}
}

View File

@ -56,6 +56,7 @@ namespace ASC.Web.Core.Users
}
}
[Scope]
public class DisplayUserSettingsHelper
{
private readonly string RemovedProfileName;
@ -89,7 +90,7 @@ namespace ASC.Web.Core.Users
{
try
{
var resourceType = Type.GetType("Resources.Resource, ASC.Web.Studio");
var resourceType = Type.GetType("ASC.Web.Core.PublicResources.Resources.Resource, ASC.Web.Core");
var resourceProperty = resourceType.GetProperty("ProfileRemoved", BindingFlags.Static | BindingFlags.Public);
var resourceValue = (string)resourceProperty.GetValue(null);
@ -108,19 +109,4 @@ namespace ASC.Web.Core.Users
return !string.IsNullOrEmpty(str) ? HttpUtility.HtmlEncode(str) : str;
}
}
public static class DisplayUserSettingsExtention
{
public static DIHelper AddDisplayUserSettingsService(this DIHelper services)
{
if (services.TryAddScoped<DisplayUserSettingsHelper>())
{
return services
.AddUserFormatter()
.AddUserManagerService();
}
return services;
}
}
}

View File

@ -34,7 +34,8 @@ using ASC.Common;
using Microsoft.Extensions.Configuration;
namespace ASC.Core.Users
{
{
[Singletone]
public class UserFormatter : IComparer<UserInfo>
{
private readonly DisplayUserNameFormat format;
@ -147,12 +148,4 @@ namespace ASC.Core.Users
return UserNameRegex.IsMatch(firstName + lastName);
}
}
public static class UserFormatterExtension
{
public static DIHelper AddUserFormatter(this DIHelper services)
{
services.TryAddSingleton<UserFormatter>();
return services;
}
}
}

View File

@ -100,7 +100,8 @@ namespace ASC.Web.Core.WhiteLabel
return GetDefault(serviceProvider.GetService<IConfiguration>());
}
}
[Singletone]
public class MailWhiteLabelSettingsHelper
{
public MailWhiteLabelSettingsHelper(IConfiguration configuration)
@ -155,13 +156,4 @@ namespace ASC.Web.Core.WhiteLabel
private IConfiguration Configuration { get; }
}
public static class MailWhiteLabelSettingsExtention
{
public static DIHelper AddMailWhiteLabelSettingsService(this DIHelper services)
{
services.TryAddSingleton<MailWhiteLabelSettingsHelper>();
return services.AddSettingsManagerService();
}
}
}

View File

@ -105,6 +105,7 @@ namespace ASC.Data.Reassigns
}
}
[Scope(Additional = typeof(ReassignProgressItemExtension))]
public class QueueWorkerReassign : QueueWorker<ReassignProgressItem>
{
private QueueWorkerRemove QueueWorkerRemove { get; }
@ -123,6 +124,8 @@ namespace ASC.Data.Reassigns
return Start(tenantId, fromUserId, () => new ReassignProgressItem(ServiceProvider, HttpContextAccessor.HttpContext, this, QueueWorkerRemove, tenantId, fromUserId, toUserId, currentUserId, deleteProfile)) as ReassignProgressItem;
}
}
[Scope(Additional = typeof(RemoveProgressItemExtension))]
public class QueueWorkerRemove : QueueWorker<RemoveProgressItem>
{
public QueueWorkerRemove(
@ -138,28 +141,4 @@ namespace ASC.Data.Reassigns
return Start(tenantId, user.ID, () => new RemoveProgressItem(ServiceProvider, HttpContextAccessor.HttpContext, this, tenantId, user, currentUserId, notify)) as RemoveProgressItem;
}
}
public static class QueueExtension
{
public static DIHelper AddQueueWorkerRemoveService(this DIHelper services)
{
if (services.TryAddScoped<QueueWorkerRemove>())
{
services.AddRemoveProgressItemService();
}
return services;
}
public static DIHelper AddQueueWorkerReassignService(this DIHelper services)
{
if (services.TryAddScoped<QueueWorkerReassign>())
{
return services
.AddReassignProgressItemService()
.AddQueueWorkerRemoveService();
}
return services;
}
}
}

View File

@ -206,7 +206,8 @@ namespace ASC.Data.Reassigns
messageService.Send(MessageAction.UserDeleted, messageTarget.Create(FromUser), userName);
}
}
[Scope]
public class ReassignProgressItemScope
{
private TenantManager TenantManager { get; }
@ -267,18 +268,12 @@ namespace ASC.Data.Reassigns
}
}
public static class ReassignProgressItemExtension
public class ReassignProgressItemExtension
{
public static DIHelper AddReassignProgressItemService(this DIHelper services)
public static void Register(DIHelper services)
{
if (services.TryAddScoped<ReassignProgressItemScope>())
{
services.TryAddSingleton<ProgressQueueOptionsManager<ReassignProgressItem>>();
services.TryAddSingleton<ProgressQueue<ReassignProgressItem>>();
services.AddSingleton<IPostConfigureOptions<ProgressQueue<ReassignProgressItem>>, ConfigureProgressQueue<ReassignProgressItem>>();
}
return services;
services.TryAdd<ReassignProgressItemScope>();
services.AddProgressQueue<ReassignProgressItem>(1, (int)TimeSpan.FromMinutes(5).TotalMilliseconds, true, false, 0);
}
}
}

View File

@ -245,7 +245,8 @@ namespace ASC.Data.Reassigns
studioNotifyService.SendMsgRemoveUserDataFailed(_currentUserId, User, userName, errorMessage);
}
}
[Scope]
public class RemoveProgressItemScope
{
private TenantManager TenantManager { get; }
@ -313,13 +314,10 @@ namespace ASC.Data.Reassigns
public static class RemoveProgressItemExtension
{
public static DIHelper AddRemoveProgressItemService(this DIHelper services)
public static void Register(DIHelper services)
{
services.TryAddSingleton<ProgressQueueOptionsManager<RemoveProgressItem>>();
services.TryAddSingleton<ProgressQueue<RemoveProgressItem>>();
services.TryAddScoped<RemoveProgressItemScope>();
services.AddSingleton<IPostConfigureOptions<ProgressQueue<RemoveProgressItem>>, ConfigureProgressQueue<RemoveProgressItem>>();
return services;
services.TryAdd<RemoveProgressItemScope>();
services.AddProgressQueue<RemoveProgressItem>(1, (int)TimeSpan.FromMinutes(5).TotalMilliseconds, true, false, 0);
}
}
}

View File

@ -12,13 +12,13 @@ namespace ASC.Data.Storage.Configuration
{
public static class StorageConfigExtension
{
public static DIHelper AddStorage(this DIHelper services)
public static void Register(DIHelper services)
{
services.TryAddSingleton(r => r.GetService<IConfiguration>().GetSetting<Storage>("Storage"));
return services;
}
}
public class Storage
{
public IEnumerable<Appender> Appender { get; set; }

View File

@ -40,6 +40,7 @@ using Microsoft.Extensions.Options;
namespace ASC.Data.Storage.Configuration
{
[Singletone(Additional = typeof(StorageSettingsExtension))]
public class BaseStorageSettingsListener
{
private IServiceProvider ServiceProvider { get; }
@ -112,6 +113,7 @@ namespace ASC.Data.Storage.Configuration
}
}
[Scope]
[Serializable]
public class CdnStorageSettings : BaseStorageSettings<CdnStorageSettings>
{
@ -123,6 +125,7 @@ namespace ASC.Data.Storage.Configuration
public override Func<DataStoreConsumer, DataStoreConsumer> Switch { get { return d => d.Cdn; } }
}
[Scope]
public class StorageSettingsHelper
{
private StorageFactoryConfig StorageFactoryConfig { get; }
@ -224,6 +227,7 @@ namespace ASC.Data.Storage.Configuration
}
}
[Scope]
public class BaseStorageSettingsListenerScope
{
private StorageSettingsHelper StorageSettingsHelper { get; }
@ -245,24 +249,11 @@ namespace ASC.Data.Storage.Configuration
}
}
public static class StorageSettingsExtension
public class StorageSettingsExtension
{
public static DIHelper AddStorageSettingsService(this DIHelper services)
public static void Register(DIHelper services)
{
if (services.TryAddScoped<StorageSettingsHelper>())
{
services.TryAddSingleton<BaseStorageSettingsListener>();
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
services.TryAddScoped<BaseStorageSettingsListenerScope>();
services.TryAddScoped<CdnStorageSettings>();
return services
.AddSettingsManagerService()
.AddConsumerFactoryService()
.AddStorageFactoryConfigService()
.AddPathUtilsService();
}
return services;
services.TryAdd<BaseStorageSettingsListenerScope>();
}
}
}

Some files were not shown because too many files have changed in this diff Show More