From d5e4687a6fda304b2e15c79abe9de76dd8367f58 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 11 Oct 2018 20:11:22 +0300 Subject: [PATCH] Sample cleanup #2405 (#199) --- build/dependencies.props | 1 + samples/SessionSample/SessionSample.csproj | 1 + samples/SessionSample/Startup.cs | 25 ++++++++++++++++++---- samples/SessionSample/appsettings.json | 5 +++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 samples/SessionSample/appsettings.json diff --git a/build/dependencies.props b/build/dependencies.props index 80173983b0..4f39e7ac45 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -13,6 +13,7 @@ 3.0.0-alpha1-10584 3.0.0-alpha1-10584 3.0.0-alpha1-10584 + 3.0.0-alpha1-10584 3.0.0-alpha1-10584 3.0.0-alpha1-10584 3.0.0-alpha1-10584 diff --git a/samples/SessionSample/SessionSample.csproj b/samples/SessionSample/SessionSample.csproj index 103dffc357..b85e7c5fd1 100644 --- a/samples/SessionSample/SessionSample.csproj +++ b/samples/SessionSample/SessionSample.csproj @@ -14,6 +14,7 @@ + diff --git a/samples/SessionSample/Startup.cs b/samples/SessionSample/Startup.cs index 41fcb566c5..4c4c5d572c 100644 --- a/samples/SessionSample/Startup.cs +++ b/samples/SessionSample/Startup.cs @@ -5,6 +5,7 @@ using System; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -12,16 +13,32 @@ namespace SessionSample { public class Startup { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json"); + + if (env.IsDevelopment()) + { + builder.AddUserSecrets(); + } + + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; set; } + public void ConfigureServices(IServiceCollection services) { - // Adds a default in-memory implementation of IDistributedCache + // Uncomment the following line to use the in-memory implementation of IDistributedCache services.AddDistributedMemoryCache(); - + // 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 => + //services.AddDistributedSqlServerCache(o => //{ - // o.ConnectionString = "Server=.;Database=ASPNET5SessionState;Trusted_Connection=True;"; + // o.ConnectionString = Configuration["AppSettings:ConnectionString"]; // o.SchemaName = "dbo"; // o.TableName = "Sessions"; //}); diff --git a/samples/SessionSample/appsettings.json b/samples/SessionSample/appsettings.json new file mode 100644 index 0000000000..aecaf5a74b --- /dev/null +++ b/samples/SessionSample/appsettings.json @@ -0,0 +1,5 @@ +{ + "AppSettings": { + "ConnectionString": "Server=.;Database=SessionStateCache;Trusted_Connection=True;" + } +}