Exemple #1
0
        public static IServiceCollection AddCached(this IServiceCollection services, Type svcType, Type impType)
        {
            // TODO Add lifetime
            Type proxy = new CachedGenerator(svcType, impType).Type;

            services.AddTransient(svcType, proxy);
            services.AddTransient(typeof(NonCached <>).MakeGenericType(new[] { impType }));
            services.AddTransient(impType);
            return(services);
        }
Exemple #2
0
        public static IServiceCollection AddCached <TService, TImplementation>(this IServiceCollection services)
            where TService : class
            where TImplementation : class, TService
        {
            // TODO Add lifetime
            Type proxy = new CachedGenerator <TService, TImplementation>().Type;

            services.AddTransient(typeof(TService), proxy);
            services.AddTransient(typeof(NonCached <TImplementation>));
            services.AddTransient(typeof(TImplementation));
            return(services);
        }