本文整理汇总了C#中IServiceCollection.AddSession方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddSession方法的具体用法?C# IServiceCollection.AddSession怎么用?C# IServiceCollection.AddSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddSession方法的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
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSession();
services.AddCaching();
services.Configure<SessionOptions>(x => x.IdleTimeout = System.TimeSpan.FromSeconds(120));
}
示例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.
services.AddMvc();
//services.AddCaching();
services.AddSession();
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
});
}
示例7: 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);
});
}
示例8: ConfigureSessionServices
private static void ConfigureSessionServices(IServiceCollection services)
{
services.AddSession();
// Configure Auth
services.AddSingleton<ISessionAuthorizeFilter, SessionAuthorizeFilter>();
}
示例9: 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());
}
示例10: 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");
});
});
}
示例11: 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());
});
}
示例12: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
IConfiguration Configuration;
services.AddConfiguration(out Configuration);
var appEnv = services.BuildServiceProvider().GetRequiredService<IApplicationEnvironment>();
var connStr = "Data source=" + appEnv.ApplicationBasePath + "/" + Configuration["DBFile"] + ";";
if (connStr.IndexOf('\\') >= 0)
connStr = connStr.Replace("/", "\\");
services.AddSmartCookies();
services.AddJsonLocalization()
.AddCookieCulture();
services.AddEntityFramework()
.AddSqlite()
.AddDbContext<BlogContext>(options =>
options.UseSqlite(connStr));
services.AddCaching();
services.AddSession(x => x.IdleTimeout = TimeSpan.FromMinutes(20));
services.AddMvc()
.AddTemplate()
.AddCookieTemplateProvider();
}
示例13: RegisterServices
public void RegisterServices(IServiceCollection services)
{
services.AddMvcGrid();
services.AddSession();
services.AddSingleton(Config);
services.AddTransient<DbContext, Context>();
services.AddTransient<IUnitOfWork, UnitOfWork>();
services.AddSingleton<ILogger, Logger>();
services.AddSingleton<IHasher, BCrypter>();
services.AddSingleton<IMailClient, SmtpMailClient>();
services.AddSingleton<IValidationAttributeAdapterProvider, ValidationAdapterProvider>();
services.AddSingleton<ILanguages, Languages>();
services.AddSingleton<IAuthorizationProvider>(provider =>
new AuthorizationProvider(typeof(BaseController).Assembly, provider));
services.AddSingleton<IMvcSiteMapParser, MvcSiteMapParser>();
services.AddSingleton<IMvcSiteMapProvider, MvcSiteMapProvider>();
services.AddTransientImplementations<IService>();
services.AddTransientImplementations<IValidator>();
}
示例14: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddCaching();
services.AddSession();
services.AddSwaggerGen();
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
services.Configure<MvcOptions>(options =>
{
//options.RespectBrowserAcceptHeader = true;
});
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<ApplicationDbContext>(options => { options.UseInMemoryDatabase(); });
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddUserStore<ApplicationUserStore<ApplicationUser>>()
.AddDefaultTokenProviders();
services.AddTransient<ApplicationUserManager>();
services.AddTransient<ApplicationSignInManager>();
services.AddTransient<IUserImageProvider, GravatarProvider>();
services.AddAuthentication();
// https://github.com/aspnet/Entropy/blob/dev/samples/Logging.Elm/Startup.cs
services.AddElm();
}
示例15: 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);
}