From 65d4057132ef4833fac5b7b61a17dc260506a9b4 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Thu, 1 May 2014 16:47:01 -0700 Subject: [PATCH] Injecting ApplicationUserManager in AccountController Injecting IConfiguration to MusicStoreContext --- src/MusicStore/Controllers/AccountController.cs | 9 +++++---- src/MusicStore/Models/MusicStoreContext.cs | 14 ++++++-------- src/MusicStore/Models/SampleData.cs | 7 ++++--- src/MusicStore/lkg.cmd | 1 - 4 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 src/MusicStore/lkg.cmd diff --git a/src/MusicStore/Controllers/AccountController.cs b/src/MusicStore/Controllers/AccountController.cs index b0ab8e4715..b2866d3a0e 100644 --- a/src/MusicStore/Controllers/AccountController.cs +++ b/src/MusicStore/Controllers/AccountController.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.Security; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.ModelBinding; @@ -12,11 +11,13 @@ namespace MusicStore.Controllers [Authorize] public class AccountController : Controller { - public UserManager UserManager + public AccountController(ApplicationUserManager userManager) { - get { return Context.ApplicationServices.GetService(); } + UserManager = userManager; } + public UserManager UserManager { get; private set; } + private SignInManager _signInManager; public SignInManager SignInManager { diff --git a/src/MusicStore/Models/MusicStoreContext.cs b/src/MusicStore/Models/MusicStoreContext.cs index 38ca6a39a3..5b15e60ac7 100644 --- a/src/MusicStore/Models/MusicStoreContext.cs +++ b/src/MusicStore/Models/MusicStoreContext.cs @@ -1,21 +1,20 @@ -using System; +using Microsoft.AspNet.ConfigurationModel; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Metadata; using Microsoft.Data.InMemory; using Microsoft.Data.SqlServer; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.ConfigurationModel; +using System; namespace MusicStore.Models { public class MusicStoreContext : DbContext { - private readonly IServiceProvider _serviceProvider; + private readonly IConfiguration _configuration; - public MusicStoreContext(IServiceProvider serviceProvider) + public MusicStoreContext(IServiceProvider serviceProvider, IConfiguration configuration) : base(serviceProvider) { - _serviceProvider = serviceProvider; + _configuration = configuration; } public DbSet Albums { get; set; } @@ -27,9 +26,8 @@ namespace MusicStore.Models protected override void OnConfiguring(EntityConfigurationBuilder builder) { - var configuration = _serviceProvider.GetService(); #if NET45 - builder.SqlServerConnectionString(configuration.Get("Data:DefaultConnection:ConnectionString")); + builder.SqlServerConnectionString(_configuration.Get("Data:DefaultConnection:ConnectionString")); #else builder.UseInMemoryStore(persist: true); #endif diff --git a/src/MusicStore/Models/SampleData.cs b/src/MusicStore/Models/SampleData.cs index 72a55f554a..9636e2ad75 100644 --- a/src/MusicStore/Models/SampleData.cs +++ b/src/MusicStore/Models/SampleData.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Data.Entity; using Microsoft.Data.SqlServer; +using Microsoft.AspNet.DependencyInjection; namespace MusicStore.Models { @@ -13,7 +14,7 @@ namespace MusicStore.Models public static async Task InitializeMusicStoreDatabaseAsync(IServiceProvider serviceProvider) { - using (var db = new MusicStoreContext(serviceProvider)) + using (var db = serviceProvider.GetService()) { var sqlServerDataStore = db.Configuration.DataStore as SqlServerDataStore; if (sqlServerDataStore != null) @@ -48,12 +49,12 @@ namespace MusicStore.Models { // Query in a separate context so that we can attach existing entities as modified List existingData; - using (var db = new MusicStoreContext(serviceProvider)) + using (var db = serviceProvider.GetService()) { existingData = db.Set().ToList(); } - using (var db = new MusicStoreContext(serviceProvider)) + using (var db = serviceProvider.GetService()) { foreach (var item in entities) { diff --git a/src/MusicStore/lkg.cmd b/src/MusicStore/lkg.cmd deleted file mode 100644 index d1718780ff..0000000000 --- a/src/MusicStore/lkg.cmd +++ /dev/null @@ -1 +0,0 @@ -\\indigofs\commonshare\prabht\k\LKGTools\LkgProjectGenerator.exe "%CD%\..\..\Packages" \ No newline at end of file