本文整理汇总了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();
}
}
示例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>();
}
示例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>();
}
示例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();
}
示例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();
}
示例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);
}
示例7: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSession();
services.AddCaching();
services.Configure<SessionOptions>(x => x.IdleTimeout = System.TimeSpan.FromSeconds(120));
}
示例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>();
}
示例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);
}
示例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);
});
}
示例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);
}
示例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);
});
}
示例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());
}
示例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());
});
}
示例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>();
}