Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }