当前位置: 首页>>代码示例>>C#>>正文


C# IServiceCollection.AddDistributedMemoryCache方法代码示例

本文整理汇总了C#中IServiceCollection.AddDistributedMemoryCache方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddDistributedMemoryCache方法的具体用法?C# IServiceCollection.AddDistributedMemoryCache怎么用?C# IServiceCollection.AddDistributedMemoryCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceCollection的用法示例。


在下文中一共展示了IServiceCollection.AddDistributedMemoryCache方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));

            var useInMemoryStore = !_platform.IsRunningOnWindows
                || _platform.IsRunningOnMono
                || _platform.IsRunningOnNanoServer;

            // Add EF services to the services container
            if (useInMemoryStore)
            {
                services.AddDbContext<MusicStoreContext>(options =>
                            options.UseInMemoryDatabase());
            }
            else
            {
                services.AddDbContext<MusicStoreContext>(options =>
                            options.UseSqlServer(Configuration[StoreConfig.ConnectionStringKey.Replace("__",":")]));
            }

            // Add Identity services to the services container
            services.AddIdentity<ApplicationUser, IdentityRole>(options =>
                    {
                        options.Cookies.ApplicationCookie.AccessDeniedPath = "/Home/AccessDenied";
                    })
                    .AddEntityFrameworkStores<MusicStoreContext>()
                    .AddDefaultTokenProviders();


            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder =>
                {
                    builder.WithOrigins("http://example.com");
                });
            });

            // Add MVC services to the services container
            services.AddMvc();

            // Add memory cache services
            services.AddMemoryCache();
            services.AddDistributedMemoryCache();

            // Add session related services.
            services.AddSession();

            // Add the system clock service
            services.AddSingleton<ISystemClock, SystemClock>();

            // Configure Auth
            services.AddAuthorization(options =>
            {
                options.AddPolicy(
                    "ManageStore",
                    authBuilder => {
                        authBuilder.RequireClaim("ManageStore", "Allowed");
                    });
            });
        }
开发者ID:masterMuTou,项目名称:MusicStore,代码行数:60,代码来源:Startup.cs

示例2: ConfigureCachingServices

        /// <summary>
        /// Configures caching for the application. Registers the <see cref="IDistrbutedCache"/> and
        /// <see cref="IMemoryCache"/> types with the services collection or IoC container. The
        /// <see cref="IDistrbutedCache"/> 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>
        private static void ConfigureCachingServices(IServiceCollection services)
        {
            // Adds IMemoryCache which is a simple in-memory cache.
            services.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.
            services.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.
            // services.AddTransient<IDistributedCache, RedisCache>();

            // 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.
            // services.AddSqlServerCache(
            //     x =>
            //     {
            //         x.ConnectionString = "Server=.;Database=ASPNET5SessionState;Trusted_Connection=True;";
            //         x.SchemaName = "dbo";
            //         x.TableName = "Sessions";
            //     });
        }
开发者ID:tzerb,项目名称:Learning,代码行数:33,代码来源:Startup.Caching.cs

示例3: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<ISampleService, DefaultSampleService>();
            services.AddTransient<HomeController>();
            services.AddDistributedMemoryCache();
            services.AddSession(options =>
                options.IdleTimeout = TimeSpan.FromMinutes(10));

        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:11,代码来源:Startup.cs

示例4: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDistributedMemoryCache();

            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromSeconds(10);
            });
        }
开发者ID:ColinDabritz,项目名称:Docs,代码行数:9,代码来源:Startup.cs

示例5: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDistributedMemoryCache();
            
            services.AddSession(options => {
                options.IdleTimeout = TimeSpan.FromMinutes(30);
                options.CookieName = ".Cloud.Server.Web.Hosting";
            });

            // Add framework services.
            services.AddMvc();
        }
开发者ID:gencebay,项目名称:CloudBuilder,代码行数:13,代码来源:Startup.cs

示例6: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));

            // Add EF services to the services container
            if (_platform.UseInMemoryStore)
            {
                services.AddDbContext<MusicStoreContext>(options =>
                            options.UseInMemoryDatabase());
            }
            else
            {
                services.AddDbContext<MusicStoreContext>(options =>
                            options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
            }

            // Add Identity services to the services container
            services.AddIdentity<ApplicationUser, IdentityRole>()
                    .AddEntityFrameworkStores<MusicStoreContext>()
                    .AddDefaultTokenProviders();

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder =>
                {
                    builder.WithOrigins("http://example.com");
                });
            });

            // Add MVC services to the services container
            services.AddMvc();

            // Add memory cache services
            services.AddMemoryCache();
            services.AddDistributedMemoryCache();

            // Add session related services.
            services.AddSession();

            // Add the system clock service
            services.AddSingleton<ISystemClock, SystemClock>();

            // Configure Auth
            services.AddAuthorization(options =>
            {
                options.AddPolicy(
                    "ManageStore",
                    authBuilder =>
                    {
                        authBuilder.RequireClaim("ManageStore", "Allowed");
                    });
            });
        }
开发者ID:CarlSosaDev,项目名称:MusicStore,代码行数:53,代码来源:StartupOpenIdConnect.cs

示例7: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));

            //Sql client not available on mono
            var useInMemoryStore = !_runtimeEnvironment.OperatingSystem.Equals("Windows", StringComparison.OrdinalIgnoreCase);

            // Add EF services to the services container
            if (useInMemoryStore)
            {
                services.AddDbContext<MusicStoreContext>(options =>
                            options.UseInMemoryDatabase());
            }
            else
            {
                services.AddDbContext<MusicStoreContext>(options =>
                            options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
            }

            // Add Identity services to the services container
            services.AddIdentity<ApplicationUser, IdentityRole>()
                    .AddEntityFrameworkStores<MusicStoreContext>()
                    .AddDefaultTokenProviders();

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder =>
                {
                    builder.WithOrigins("http://example.com");
                });
            });

            // Add MVC services to the services container
            services.AddMvc();

            //Add InMemoryCache
            services.AddSingleton<IMemoryCache, MemoryCache>();

            // Add session related services.
            services.AddMemoryCache();
            services.AddDistributedMemoryCache();
            services.AddSession();

            // Add the system clock service
            services.AddSingleton<ISystemClock, SystemClock>();

            // Configure Auth
            services.Configure<AuthorizationOptions>(options =>
            {
                options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
            });
        }
开发者ID:masterMuTou,项目名称:MusicStore,代码行数:52,代码来源:StartupOpenIdConnectTesting.cs

示例8: ConfigureServices

        // Set up application services
        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddMvc(
                    options => { options.Conventions.Add(new ApplicationDescription("This is a basic website.")); })
                .AddXmlDataContractSerializerFormatters();

            services.AddLogging();
            services.AddSingleton<IActionDescriptorProvider, ActionDescriptorCreationCounter>();
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped<RequestIdService>();
            services.AddMemoryCache();
            services.AddDistributedMemoryCache();
            services.AddSession();
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:16,代码来源:Startup.cs

示例9: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDistributedMemoryCache();
     services.AddSession();
 }
开发者ID:Websilk,项目名称:Home,代码行数:5,代码来源:Startup.cs

示例10: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();

            services.AddSingleton<IConfigurationRoot>(Configuration);
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

            services.AddAuthentication(Configuration);
            services.Configure<PayPalClientSettings>(Configuration.GetSection("PayPalClientSettings"));
            services.AddSingleton<PayPalClient>();
            services.AddLogging();
            services.AddMvc();

            // register document store
            var store = DocumentStore.For(_ =>
            {
                _.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate;
                _.Connection(Configuration.GetConnectionString("HopeNB"));

                AsyncSessionFactory.Register(_);
            });

            store.Schema.ApplyAllConfiguredChangesToDatabase();

            services.AddSingleton<IDocumentStore>(store);

            AsyncSessionFactory.DocumentStore = store;

            services.AddDistributedMemoryCache();

            services.AddMultitenancy<Organization, CachingOrganizationResolver>();
        }
开发者ID:HopeNB,项目名称:web,代码行数:32,代码来源:Startup.cs

示例11: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
                .AddJsonOptions(jsonOptions =>
                {
                    jsonOptions.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                })
                .AddViewLocalization()
                .AddDataAnnotationsLocalization();
            services.AddCors();
            // Add framework services.
            services.AddDbContext<iBalekaDBContext>(options =>
                    options.UseSqlServer(Configuration.GetConnectionString("ServerConnection")));

            services.AddIdentity<ApplicationUser, IdentityRole>(i => {
                     i.SecurityStampValidationInterval = TimeSpan.FromDays(7);
                    })
                .AddEntityFrameworkStores<iBalekaDBContext>()
                .AddDefaultTokenProviders();
            services.AddDistributedMemoryCache();
            services.AddSession();

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();

            //repos
            services.AddSingleton<IUnitOfWork, UnitOfWork>();
            services.AddScoped<IApiClient, ApiClient>();
            services.AddScoped<IMapClient, MapClient>();
            services.AddScoped<IClubClient, ClubClient>();
            services.AddScoped<IClubMemberClient, ClubMemberClient>();
            services.AddScoped<IEventClient, EventClient>();
            services.AddScoped<IEventRegistration, EventRegistrationClient>();
            //services

            services.Configure<MvcOptions>(options =>
            {
                options.Filters.Add(new RequireHttpsAttribute());
            });
        }
开发者ID:Xabisohila,项目名称:iBalekaWeb,代码行数:42,代码来源:Startup.cs

示例12: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ReferenceLoopHandling =
                        Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                    options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
                    options.SerializerSettings.ContractResolver =
                        new CamelCasePropertyNamesContractResolver();
                });

            // Add session related services.
            services.AddSession();

            // Add memory cache services
            services.AddMemoryCache();
            services.AddDistributedMemoryCache();

            //services.ConfigureIdentity(Configuration.GetConfigurationSection("Identity"));

            //services.ConfigureIdentity(options =>
            //{
            //    options.Password.RequireDigit = bool.Parse(Configuration["Identity:Password:RequireDigit"].ToString());
            //    options.Password.RequiredLength = int.Parse(Configuration["Identity:Password:RequiredLength"].ToString());
            //    options.Password.RequireLowercase = bool.Parse(Configuration["Identity:Password:RequireLowercase"].ToString());
            //    options.Password.RequireNonLetterOrDigit = bool.Parse(Configuration["Identity:Password:RequireNonLetterOrDigit"].ToString());
            //    options.Password.RequireUppercase = bool.Parse(Configuration["Identity:Password:RequireUppercase"].ToString());
            //});

            services.AddAuthorization(options =>
            {
                options.AddPolicy(
                    "Manager",
                    authBuilder =>
                    {
                        authBuilder.RequireClaim("Manager", "Allowed");
                    });
            });

            // Add framework services.
            services.AddDbContext<GraduationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<GraduationDbContext>()
                .AddDefaultTokenProviders();

            AutoMapperConfiguration.Configure();

            services.AddMvc();

            // Repositories
            services.AddScoped<ICardRepository, CardRepository>();
            services.AddScoped<ICateRepository, CateRepository>();
            services.AddScoped<IBlogRepository, BlogRepository>();

            services.AddScoped<ICateBlogRepository, CateBlogRepository>();
            services.AddScoped<ILoggingRepository, LoggingRepository>();
            services.AddScoped<ICommentRepository, CommentRepository>();
            services.AddScoped<IContactRepository, ContactRepository>();
            services.AddScoped<ISliderRepository, SliderRepository>();

            services.AddScoped<IViewRepository, ViewRepository>();

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();
        }
开发者ID:XcodeFi,项目名称:Project-MVC6-angular2,代码行数:70,代码来源:Startup.cs

示例13: ConfigureDevelopmentServices

 /// <summary>
 /// Use LocalCache (Memory) in Development
 /// </summary>
 /// <param name="services"></param>
 public void ConfigureDevelopmentServices(IServiceCollection services)
 {
     services.AddDistributedMemoryCache();
 }
开发者ID:ColinDabritz,项目名称:Docs,代码行数:8,代码来源:Startup.cs

示例14: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));

            // Sql client not available on mono
            var useInMemoryStore = _platform.IsRunningOnMono;

            // Add EF services to the services container
            if (useInMemoryStore)
            {
                services.AddDbContext<MusicStoreContext>(options =>
                            options.UseInMemoryDatabase());
            }
            else
            {
                services.AddDbContext<MusicStoreContext>(options =>
                            options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
            }

            // Add Identity services to the services container
            services.AddIdentity<ApplicationUser, IdentityRole>(options =>
                    {
                        options.Cookies.ApplicationCookie.AccessDeniedPath = new PathString("/Home/AccessDenied");
                    })
                    .AddEntityFrameworkStores<MusicStoreContext>()
                    .AddDefaultTokenProviders();

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder =>
                {
                    builder.WithOrigins("http://example.com");
                });
            });

            // Add MVC services to the services container
            services.AddMvc();

            //Add InMemoryCache
            services.AddSingleton<IMemoryCache, MemoryCache>();

            // Add session related services.
            services.AddMemoryCache();
            services.AddDistributedMemoryCache();
            services.AddSession();

            // Add the system clock service
            services.AddSingleton<ISystemClock, SystemClock>();

            // Configure Auth
            services.AddAuthorization(options =>
            {
                options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
            });
        }
开发者ID:Corays,项目名称:MusicStore,代码行数:55,代码来源:StartupSocialTesting.cs


注:本文中的IServiceCollection.AddDistributedMemoryCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。