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


C# IServiceCollection.AddCaching方法代码示例

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


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

示例1: ConfigureServices

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddCaching();
            services.AddSession();

            services.AddMvc();
            services.AddSingleton<PassThroughAttribute>();
            services.AddSingleton<UserNameService>();
            services.AddTransient<ITestService, TestService>();

            services.ConfigureMvc(options =>
            {
                options.Filters.Add(typeof(PassThroughAttribute), order: 17);
                options.AddXmlDataContractSerializerFormatter();
                options.Filters.Add(new FormatFilterAttribute());
            });

#if DNX451
            // Fully-qualify configuration path to avoid issues in functional tests. Just "config.json" would be fine
            // but Configuration uses CallContextServiceLocator.Locator.ServiceProvider to get IApplicationEnvironment.
            // Functional tests update that service but not in the static provider.
            var applicationEnvironment = services.BuildServiceProvider().GetRequiredService<IApplicationEnvironment>();
            var configurationPath = Path.Combine(applicationEnvironment.ApplicationBasePath, "config.json");

            // Set up configuration sources.
            var configuration = new Configuration()
                .AddJsonFile(configurationPath)
                .AddEnvironmentVariables();
            string diSystem;
            if (configuration.TryGet("DependencyInjection", out diSystem) &&
                diSystem.Equals("AutoFac", StringComparison.OrdinalIgnoreCase))
            {
                _autoFac = true;
                services.ConfigureRazorViewEngine(options =>
                {
                    var expander = new LanguageViewLocationExpander(
                        context => context.HttpContext.Request.Query["language"]);
                    options.ViewLocationExpanders.Insert(0, expander);
                });

                // Create the autofac container
                var builder = new ContainerBuilder();

                // Create the container and use the default application services as a fallback
                AutofacRegistration.Populate(
                    builder,
                    services);

                builder.RegisterModule<MonitoringModule>();

                var container = builder.Build();

                return container.Resolve<IServiceProvider>();
            }
            else
#endif
            {
                return services.BuildServiceProvider();
            }
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:60,代码来源:Startup.cs

示例2: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

            services.AddIdentity<ApplicationUser, ApplicationRole>()
                .AddUserStore<MyUserStore>()
                .AddUserManager<MyUserManager>()
                .AddRoleManager<MyRoleManager>()
                .AddRoleStore<MyRoleStore>()
                //.AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            services.AddScoped<SignInManager<ApplicationUser>, MySignInManager>();

            services.AddMvc();

            services.AddCaching();
            services.AddSession(options => {
                options.IdleTimeout = TimeSpan.FromHours(23);
            });

            // Add application services.
            //services.AddTransient<IEmailSender, AuthMessageSender>();
            //services.AddTransient<ISmsSender, AuthMessageSender>();
        }
开发者ID:dborzikh,项目名称:Prime.App,代码行数:32,代码来源:Startup.cs

示例3: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            var connection = @"Server=dataserver;Database=TechLiquid;Trusted_Connection=True;MultipleActiveResultSets = True";
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<TechLiquidDbContext>(options => options.UseSqlServer(connection));


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

            // Register the service and implementation for the database context
            //services.AddScoped<ITechLiquidDbContext>(provider => provider.GetService<TechLiquidDbContext>());

            services.AddMvc();
            services.AddCaching(); // Adds a default in-memory implementation of IDistributedCache

            services.AddSession(o =>
            {
                o.IdleTimeout = TimeSpan.FromSeconds(10);
            });

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();
        }
开发者ID:eatonjd,项目名称:TLAuctionv5,代码行数:29,代码来源:Startup.cs

示例4: ConfigureServices

        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {

            // Add Entity Framework services to the services container.
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<CenterContext>(options =>
                    options.UseSqlServer(Configuration["Database:ConnectionString"]));

            services.AddCaching();  // 这两个必须同时添加,因为Session依赖于Caching
            services.AddSession(x => x.IdleTimeout = TimeSpan.FromMinutes(20));

            services.Configure<IdentityDbContextOptions>(options =>
            {
                options.DefaultAdminUserName = Configuration["DefaultAdminUsername"];
                options.DefaultAdminPassword = Configuration["DefaultAdminPassword"];
            });

            services.AddIdentity<User, Role>(x =>
            {
                x.Password.RequireDigit = false;
                x.Password.RequiredLength = 0;
                x.Password.RequireLowercase = false;
                x.Password.RequireNonLetterOrDigit = false;
                x.Password.RequireUppercase = false;
            })
                .AddEntityFrameworkStores<CenterContext, long>()
                .AddDefaultTokenProviders();


            services.AddMvc();
            services.AddLogging();
        }
开发者ID:applenele,项目名称:CSTAMS,代码行数:34,代码来源:Startup.cs

示例5: ConfigureServices

        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddEntityFramework()
                .AddSqlServer()
                .AddInMemoryDatabase()
                .AddDbContext<ApplicationContext>(options => {
                    options.UseInMemoryDatabase();
                })
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

            // Add Identity services to the services container.
            services.AddIdentity<ApplicationUser, IdentityRole>(options =>
            {
                //options.Cookies.ApplicationCookieAuthenticationScheme = "ServerCookie";
            })
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            services.Configure<SharedAuthenticationOptions>(options => {
                options.SignInScheme = "ServerCookie";
            });

            services.AddOpenIdConnectServer();

            services.AddAuthentication();
            services.AddCaching();
            services.AddMvc();
        }
开发者ID:Fosol,项目名称:Example.Oauth,代码行数:30,代码来源:Startup.cs

示例6: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var useInMemoryStore = !_Platform.IsRunningOnWindows || _Platform.IsRunningOnMono || _Platform.IsRunningOnNanoServer;

            services.ConfigureDataContext(Configuration, useInMemoryStore);

            // Register dependencies
            services.ConfigureDependencies();

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

            services.AddApplicationInsightsTelemetry(Configuration);

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

            services.AddCaching();

            services.AddSession();

            services.AddAuthorization(Policies.Configuration);
        }
开发者ID:Sirikon,项目名称:HealthClinic.biz,代码行数:26,代码来源:Startup.cs

示例7: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc();
     services.AddSession();
     services.AddCaching();
     services.Configure<SessionOptions>(x => x.IdleTimeout = System.TimeSpan.FromSeconds(120));
 }
开发者ID:ThePlatinumTaco,项目名称:Project,代码行数:7,代码来源:Startup.cs

示例8: ConfigureServices

        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCaching();

            services.AddTransient<ITimeService, TimeService>();
            services.AddTransient<IGreetingService, GreetingService>();
        }
开发者ID:ChujianA,项目名称:aspnetcore-doc-cn,代码行数:8,代码来源:Startup.cs

示例9: 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)
        {
            var builder = new ConfigurationBuilder()
               .SetBasePath(this.appEnv.ApplicationBasePath)
               .AddJsonFile("config.json")
               .AddEnvironmentVariables();

            var configRoot = builder.Build();
            this.env.Initialize(this.appEnv.ApplicationBasePath, configRoot);
            services.AddInstance(configRoot);
            services.AddInstance(new Configuration(configRoot));

            DatabaseConfiguration.ConfigureIdentity(services, this.env);
            DatabaseConfiguration.ConfigureEntityFramework(services, configRoot, this.env, IsWindows);
            this.AddMvcServiceSetup(services);
            services.AddCaching();
            services.AddSession();

            services.AddLogging();

            services.AddAntiforgery();
            services.AddSingleton<IAntiforgeryTokenStore, AntiforgeryTokenStore>();

            services.AddTransient<ISeedData, SeedData>();
            services.AddScoped<ViewModelValidator>();
            RepositoryConfiguration.ConfigureRepositories(services);
        }
开发者ID:Sefirosu,项目名称:accounting,代码行数:29,代码来源:Startup.cs

示例10: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            // Uncomment the following line to use the Microsoft SQL Server implementation of IDistributedCache.
            // Note that this would require setting up the session state database.
            //services.AddSqlServerCache(o =>
            //{
            //    o.ConnectionString = "Server=.;Database=ASPNET5SessionState;Trusted_Connection=True;";
            //    o.SchemaName = "dbo";
            //    o.TableName = "Sessions";
            //});

            // Uncomment the following line to use the Redis implementation of IDistributedCache.
            // This will override any previously registered IDistributedCache service.
            //services.AddTransient<IDistributedCache, RedisCache>();

            // Adds a default in-memory implementation of IDistributedCache
            services.AddCaching();

            services.AddSession();

            services.ConfigureSession(o =>
            {
                o.IdleTimeout = TimeSpan.FromSeconds(10);
            });
        }
开发者ID:MetTeam,项目名称:Session,代码行数:25,代码来源: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)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

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

            services.AddMvc();

            //Chris Add
            services.AddCaching();
            services.AddSession();

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

            // Alex Add
            services.Configure<AuthMessageSenderOptions>(Configuration);
        }
开发者ID:mjheller,项目名称:Folio,代码行数:28,代码来源: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)
        {
            // Add framework services.
            services.AddEntityFramework()
                .AddSqlite()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlite(Configuration["Data:DefaultConnection:ConnectionString"]));

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

            services.AddMvc();

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();
            
            // Add sessions
            services.AddCaching();
            services.AddSession(options =>
            {
                   options.CookieName = ".CoffeeScience.Session";
                   options.IdleTimeout = TimeSpan.FromSeconds(10);
            });
        }
开发者ID:philljeff,项目名称:CoffeeScience,代码行数:27,代码来源:Startup.cs

示例13: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();
            services.AddCaching();
            services.AddSession();

            // Configuration
            services.Configure<EncryptionConfig>(Configuration.GetSection("Encryption"));
            services.Configure<EmailConfig>(Configuration.GetSection("Email"));
            services.Configure<RedisConfig>(Configuration.GetSection("Redis"));

            // Dependency Injection
            services.AddSingleton<IRedisService, RedisService>();
            services.AddSingleton<IEncryptionService, BasicEncryption>();
            services.AddSingleton<ISchedulerService, SchedulerService>();
            services.AddSingleton<IEmailService, EmailService>();
            services.AddTransient<IMojangService, MojangService>();
            services.AddTransient<IUserService, UserService>();
            services.AddTransient<IUsernameService, UsernameService>();

            // Automapper
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperProfile());
            });
            services.AddSingleton(sp => config.CreateMapper());
        }
开发者ID:AMerkuri,项目名称:MCNotifier,代码行数:29,代码来源:Startup.cs

示例14: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            // Add EF services to the services container
            services.AddEntityFramework()
                    .AddSqlServer()
                    .AddDbContext<MusicStoreContext>(options =>
                            options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")));

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

            //Add all SignalR related services to IoC.
            services.AddSignalR();

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

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

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

示例15: ConfigureServices

    public virtual void ConfigureServices(IServiceCollection services)
    {
      IEnumerable<Assembly> assemblies = AssemblyManager.GetAssemblies(
        this.applicationBasePath.Substring(0, this.applicationBasePath.LastIndexOf("src")) + "artifacts\\bin\\Extensions",
        this.assemblyLoaderContainer,
        this.assemblyLoadContextAccessor,
        this.libraryManager
      );

      ExtensionManager.SetAssemblies(assemblies);
      services.AddCaching();
      services.AddSession();
      services.AddMvc().AddPrecompiledRazorViews(ExtensionManager.Assemblies.ToArray());
      services.Configure<RazorViewEngineOptions>(options =>
        {
          options.FileProvider = this.GetFileProvider(this.applicationBasePath);
        }
      );

      foreach (IExtension extension in ExtensionManager.Extensions)
      {
        extension.SetConfigurationRoot(this.configurationRoot);
        extension.ConfigureServices(services);
      }

      services.AddTransient<DefaultAssemblyProvider>();
      services.AddTransient<IAssemblyProvider, ExtensionAssemblyProvider>();
    }
开发者ID:leo9223,项目名称:ExtCore,代码行数:28,代码来源:Startup.cs


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