forked from dotnetcore/AspectCore-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
70 lines (59 loc) · 3.1 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
70 lines (59 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using AspectCore.Configuration;
using AspectCore.DependencyInjection;
using AspectCore.DynamicProxy;
using AspectCore.DynamicProxy.Parameters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using System.Linq;
namespace AspectCore.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
[Obsolete("Use ConfigureDynamicProxy")]
public static IServiceCollection AddDynamicProxy(this IServiceCollection services, Action<IAspectConfiguration> configure = null)
{
return ConfigureDynamicProxy(services, configure);
}
public static IServiceCollection ConfigureDynamicProxy(this IServiceCollection services, Action<IAspectConfiguration> configure = null)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
var configurationService = services.LastOrDefault(x => x.ServiceType == typeof(IAspectConfiguration) && x.ImplementationInstance != null);
var configuration = (IAspectConfiguration) configurationService?.ImplementationInstance ?? new AspectConfiguration();
configure?.Invoke(configuration);
if (configurationService == null)
{
services.AddSingleton(configuration);
}
return services;
}
internal static IServiceCollection TryAddDynamicProxyServices(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.ConfigureDynamicProxy();
services.TryAddTransient(typeof(IManyEnumerable<>), typeof(ManyEnumerable<>));
services.TryAddScoped<IServiceResolver, MsdiServiceResolver>();
services.TryAddScoped<IScopeResolverFactory, MsdiScopeResolverFactory>();
services.TryAddScoped<IPropertyInjectorFactory, PropertyInjectorFactory>();
services.TryAddScoped<IAspectContextFactory, AspectContextFactory>();
services.TryAddScoped<IAspectActivatorFactory, AspectActivatorFactory>();
services.TryAddScoped<IProxyGenerator, ProxyGenerator>();
services.TryAddScoped<IParameterInterceptorSelector, ParameterInterceptorSelector>();
services.TryAddScoped<IInterceptorCollector, InterceptorCollector>();
services.TryAddScoped<IAspectBuilderFactory, AspectBuilderFactory>();
services.TryAddSingleton<IAspectValidatorBuilder, AspectValidatorBuilder>();
services.TryAddSingleton<IProxyTypeGenerator, ProxyTypeGenerator>();
services.TryAddSingleton<IAspectCachingProvider, AspectCachingProvider>();
services.AddSingleton<IInterceptorSelector, ConfigureInterceptorSelector>();
services.AddSingleton<IInterceptorSelector, AttributeInterceptorSelector>();
services.AddSingleton<IAdditionalInterceptorSelector, AttributeAdditionalInterceptorSelector>();
return services;
}
}
}