/// <summary> /// Configures caching for the application. Registers the <see cref="IDistributedCache"/> and /// <see cref="IMemoryCache"/> types with the services collection or IoC container. The /// <see cref="IDistributedCache"/> is intended to be used in cloud hosted scenarios where there is a shared /// cache, which is shared between multiple instances of the application. Use the <see cref="IMemoryCache"/> /// otherwise. /// </summary> /// <param name="services">The services collection or IoC container.</param> public static IServiceCollection AddCaching(this IServiceCollection services) { return services // Adds IMemoryCache which is a simple in-memory cache. .AddMemoryCache(); // Adds IDistributedCache which is a distributed cache shared between multiple servers. This adds a // default implementation of IDistributedCache which is not distributed. See below: // .AddDistributedMemoryCache(); // Uncomment the following line to use the Redis implementation of IDistributedCache. This will // override any previously registered IDistributedCache service. // Redis is a very fast cache provider and the recommended distributed cache provider. // .AddDistributedRedisCache( // options => // { // }); // Uncomment the following line to use the Microsoft SQL Server implementation of IDistributedCache. // Note that this would require setting up the session state database. // Redis is the preferred cache implementation but you can use SQL Server if you don't have an alternative. // .AddSqlServerCache( // x => // { // x.ConnectionString = "Server=.;Database=ASPNET5SessionState;Trusted_Connection=True;"; // x.SchemaName = "dbo"; // x.TableName = "Sessions"; // }); }
public static IServiceCollection AddPomeloLocalization(this IServiceCollection self, Action<MemoryCultureSet> InitCultureSource = null) { var set = new MemoryCultureSet(); InitCultureSource?.Invoke(set); self.AddMemoryCache(); self.AddContextAccessor(); self.AddSingleton<ICultureSet>(set); self.AddScoped<ICultureProvider, DefaultCultureProvider>(); self.AddScoped<IStringReader, DefaultStringReader>(); self.AddSingleton<ITranslator, NonTranslator>(); self.AddSingleton<ITranslatedCaching, MemoryTranslatedCaching>(); self.AddScoped<ITranslatorDisabler, DefaultTranslatorDisabler>(); self.AddScoped<IEntityStateListener, LocalizationEntityStateListener>(); self.Configure<MvcOptions>(x => x.Filters.Add(typeof(LocalizationFilter))); self.Configure<MvcOptions>(x => x.Filters.Add(typeof(DbContextModelBindingFilter))); return self; }
public static void AddCaching(this IServiceCollection services) { services.AddMemoryCache(); services.TryAddSingleton<ILocalCache, MemoryLocalCache>(); services.TryAddSingleton<IDistributedCache, DistributedCacheEmulator>(); }
private static IServiceCollection AddQuery(this IServiceCollection serviceCollection) => serviceCollection .AddMemoryCache() .AddSingleton(_ => MethodInfoBasedNodeTypeRegistry.CreateFromRelinqAssembly()) .AddScoped<ICompiledQueryCache, CompiledQueryCache>() .AddScoped<IAsyncQueryProvider, EntityQueryProvider>() .AddScoped<IQueryCompiler, QueryCompiler>() .AddScoped<IQueryAnnotationExtractor, QueryAnnotationExtractor>() .AddScoped<IQueryOptimizer, QueryOptimizer>() .AddScoped<IEntityTrackingInfoFactory, EntityTrackingInfoFactory>() .AddScoped<ISubQueryMemberPushDownExpressionVisitor, SubQueryMemberPushDownExpressionVisitor>() .AddScoped<ITaskBlockingExpressionVisitor, TaskBlockingExpressionVisitor>() .AddScoped<IEntityResultFindingExpressionVisitorFactory, EntityResultFindingExpressionVisitorFactory>() .AddScoped<IMemberAccessBindingExpressionVisitorFactory, MemberAccessBindingExpressionVisitorFactory>() .AddScoped<INavigationRewritingExpressionVisitorFactory, NavigationRewritingExpressionVisitorFactory>() .AddScoped<IOrderingExpressionVisitorFactory, OrderingExpressionVisitorFactory>() .AddScoped<IQuerySourceTracingExpressionVisitorFactory, QuerySourceTracingExpressionVisitorFactory>() .AddScoped<IRequiresMaterializationExpressionVisitorFactory, RequiresMaterializationExpressionVisitorFactory>() .AddScoped<CompiledQueryCacheKeyGenerator>() .AddScoped<ExpressionPrinter>() .AddScoped<ResultOperatorHandler>() .AddScoped<QueryCompilationContextFactory>() .AddScoped<ProjectionExpressionVisitorFactory>() .AddScoped(p => GetProviderServices(p).QueryContextFactory) .AddScoped(p => GetProviderServices(p).QueryCompilationContextFactory) .AddScoped(p => GetProviderServices(p).CompiledQueryCacheKeyGenerator) .AddScoped(p => GetProviderServices(p).EntityQueryModelVisitorFactory) .AddScoped(p => GetProviderServices(p).EntityQueryableExpressionVisitorFactory) .AddScoped(p => GetProviderServices(p).ExpressionPrinter) .AddScoped(p => GetProviderServices(p).ResultOperatorHandler) .AddScoped(p => GetProviderServices(p).ProjectionExpressionVisitorFactory);