Adding environment based config to the music store project with a Config.json file for local.

If the same set of values (those present in config.json) is present in the environment variables
then ones from environment variables be picked up. This will be the antares scenario where the portal variables
flow in as environment variables with a specific prefix.
This commit is contained in:
Praburaj 2014-04-08 14:21:19 -07:00
parent c0250392b2
commit ccc257f8fc
3 changed files with 12 additions and 31 deletions

View File

@ -0,0 +1,4 @@
{
"DefaultAdminUsername": "Administrator",
"DefaultAdminPassword": "YouShouldChangeThisPassword"
}

View File

@ -1,6 +1,7 @@
using Microsoft.AspNet;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.ConfigurationModel;
using Microsoft.AspNet.Configuration.Json;
using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.DependencyInjection.Fallback;
using Microsoft.AspNet.DependencyInjection.NestedProviders;
@ -47,39 +48,14 @@ public class Startup
SampleData.InitializeMusicStoreDatabase();
}
//Bug: We need EF to integrate with SQL server. Until then we will use in memory store
//private async void CreateAdminUser()
//{
// string _username = ConfigurationManager.AppSettings["DefaultAdminUsername"];
// string _password = ConfigurationManager.AppSettings["DefaultAdminPassword"];
// string _role = "Administrator";
// var context = new ApplicationDbContext();
// var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
// var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
// var role = new IdentityRole(_role);
// var result = await roleManager.RoleExistsAsync(_role);
// if (result == false)
// {
// await roleManager.CreateAsync(role);
// }
// var user = await userManager.FindByNameAsync(_username);
// if (user == null)
// {
// user = new ApplicationUser { UserName = _username };
// await userManager.CreateAsync(user, _password);
// await userManager.AddToRoleAsync(user.Id, _role);
// }
//}
private async void CreateAdminUser()
{
//How to read from local appSettings?
var configuration = new Configuration();
string _username = "Administrator"; // configuration.Get("DefaultAdminUsername");
string _password = "YouShouldChangeThisPassword"; // configuration.Get("DefaultAdminPassword");
configuration.AddEnvironmentVariables(); //If configuration flows through environment we should pick that first
configuration.AddJsonFile("Config.json");
string _username = configuration.Get("DefaultAdminUsername");
string _password = configuration.Get("DefaultAdminPassword");
string _role = "Administrator";
var userManager = new UserManager<ApplicationUser>(new InMemoryUserStore<ApplicationUser>());

View File

@ -25,7 +25,8 @@
"Microsoft.Data.InMemory": "0.1-alpha-*",
"Microsoft.AspNet.Diagnostics": "0.1-alpha-*",
"Microsoft.AspNet.Hosting": "0.1-alpha-*",
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-*"
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-*",
"Microsoft.AspNet.Configuration.Json": "0.1-alpha-*"
},
"commands": {
"web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001"