Scope: refactoring
This commit is contained in:
parent
6f25e2e83e
commit
3ddb202c56
@ -66,13 +66,14 @@ namespace ASC.Api.Core
|
||||
});
|
||||
}
|
||||
|
||||
DIHelper.TryAdd<DisposeMiddleware>();
|
||||
DIHelper.TryAdd<CultureMiddleware>();
|
||||
DIHelper.TryAdd<IpSecurityFilter>();
|
||||
DIHelper.TryAdd<PaymentFilter>();
|
||||
DIHelper.TryAdd<ProductSecurityFilter>();
|
||||
DIHelper.TryAdd<TenantStatusFilter>();
|
||||
|
||||
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
DIHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
||||
|
||||
var builder = services.AddMvcCore(config =>
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Web.Api.Routing;
|
||||
using ASC.Web.Studio.Utility;
|
||||
@ -13,6 +14,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Api.Core.Middleware
|
||||
{
|
||||
[Scope]
|
||||
public class PaymentFilter : IResourceFilter
|
||||
{
|
||||
private readonly ILog log;
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Notify.Engine;
|
||||
using ASC.Core;
|
||||
@ -16,6 +17,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Api.Core.Middleware
|
||||
{
|
||||
[Scope]
|
||||
public class ProductSecurityFilter : IResourceFilter
|
||||
{
|
||||
private static readonly IDictionary<string, Guid> products;
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Net;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Tenants;
|
||||
@ -10,6 +11,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Api.Core.Middleware
|
||||
{
|
||||
[Scope]
|
||||
public class TenantStatusFilter : IResourceFilter
|
||||
{
|
||||
private readonly ILog log;
|
||||
|
@ -45,6 +45,7 @@
|
||||
<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" />
|
||||
|
@ -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);
|
||||
|
@ -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; }
|
||||
|
@ -6,6 +6,8 @@ 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;
|
||||
@ -268,6 +270,7 @@ namespace ASC.Common
|
||||
|
||||
private bool Register(Type service)
|
||||
{
|
||||
if (service.IsSubclassOf(typeof(ControllerBase)) || service.GetInterfaces().Contains(typeof(IResourceFilter))) return true;
|
||||
var c = service.GetCustomAttribute<DIAttribute>();
|
||||
var serviceName = $"{service}";
|
||||
if (c is ScopeAttribute)
|
||||
@ -303,6 +306,7 @@ namespace ASC.Common
|
||||
|
||||
private bool Register(Type service, Type implementation)
|
||||
{
|
||||
if (service.IsSubclassOf(typeof(ControllerBase)) || service.GetInterfaces().Contains(typeof(IResourceFilter))) return true;
|
||||
var c = service.IsGenericType && service.GetGenericTypeDefinition() == typeof(IConfigureOptions<>) && implementation != null ? implementation.GetCustomAttribute<DIAttribute>() : service.GetCustomAttribute<DIAttribute>();
|
||||
var serviceName = $"{service}{implementation}";
|
||||
if (c is ScopeAttribute)
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@ -35,7 +36,8 @@ namespace ASC.Files
|
||||
|
||||
DIHelper.TryAdd<FilesController>();
|
||||
|
||||
var a = 0;
|
||||
var a = $"{string.Join(",", DIHelper.Singleton.OrderBy(r => r).ToArray())},{string.Join(",", DIHelper.Scoped.OrderBy(r => r).ToArray())},{string.Join(",", DIHelper.Transient.OrderBy(r => r).ToArray())}";
|
||||
var b = 0;
|
||||
}
|
||||
|
||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
|
Loading…
Reference in New Issue
Block a user