/// <summary> /// Register proxy without target /// </summary> /// <typeparam name="T"></typeparam> /// <param name="services"></param> /// <param name="lifetime"></param> public static void AddProxyWithoutTarget <T>(this IServiceCollection services, ServiceLifetime lifetime) where T : class { Func <IServiceProvider, T> implementationFactory = serviceProvider => MethodInterceptor <T> .Create( null, serviceProvider.GetRequiredService <IContextProvider>(), serviceProvider.GetRequiredService <IAttributeProvider>()); var serviceDescriptor = new ServiceDescriptor(typeof(T), implementationFactory, lifetime); services.Add(serviceDescriptor); }
/// <summary> /// Register a proxy with attribute interceptors /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TImpl"></typeparam> /// <param name="services"></param> /// <param name="targetResolver"></param> /// <param name="lifetime"></param> public static void RegisterWithMethodFilters <T, TImpl>(this IServiceCollection services, Func <IServiceProvider, TImpl> targetResolver, ServiceLifetime lifetime) where TImpl : class, T where T : class { Func <IServiceProvider, T> implementationFactory = serviceProvider => MethodInterceptor <T> .Create( targetResolver(serviceProvider), serviceProvider.GetRequiredService <IContextProvider>(), serviceProvider.GetRequiredService <IAttributeProvider>()); var serviceDescriptor = new ServiceDescriptor(typeof(T), implementationFactory, lifetime); services.Add(serviceDescriptor); }