private static void AddWithProxy <TService, TImplementation>(IServiceCollection services, ServiceLifetime serviceLifetime) { object instance = Activator.CreateInstance(typeof(TImplementation)); var service = new ServiceDescriptor(typeof(TService), DecoratedFactory, serviceLifetime); services.Add(service); object DecoratedFactory(IServiceProvider serviceProvider) { var implementation = PhoenixProxyDispatcher <TService> .Resolve((TService)instance); return(implementation); } }
private static void AddWithProxy <TService, TImplementation>(IServiceCollection services, ServiceLifetime serviceLifetime) { var descriptor = ServiceDescriptor.Describe( typeof(TService), sp => { return(PhoenixProxyDispatcher <TService> .Resolve( (TService)ActivatorUtilities.GetServiceOrCreateInstance(sp, typeof(TImplementation)) )); }, serviceLifetime); services.Add(descriptor); }