Use separate service providers

This commit is contained in:
Arthur Vickers 2016-03-16 09:18:07 -07:00
parent 6116f0e2e8
commit 98c69c3c4b
12 changed files with 35 additions and 46 deletions

View File

@ -47,10 +47,8 @@ namespace MusicStore
// Add EF services to the services container // Add EF services to the services container
if (useInMemoryStore) if (useInMemoryStore)
{ {
services.AddOptions(); services.AddDbContext<MusicStoreContext>(options =>
services options.UseInMemoryDatabase());
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
} }
else else
{ {

View File

@ -53,10 +53,8 @@ namespace MusicStore
// Add EF services to the services container // Add EF services to the services container
if (useInMemoryStore) if (useInMemoryStore)
{ {
services.AddOptions(); services.AddDbContext<MusicStoreContext>(options =>
services options.UseInMemoryDatabase());
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
} }
else else
{ {

View File

@ -42,10 +42,8 @@ namespace MusicStore
// Add EF services to the services container // Add EF services to the services container
if (useInMemoryStore) if (useInMemoryStore)
{ {
services.AddOptions(); services.AddDbContext<MusicStoreContext>(options =>
services options.UseInMemoryDatabase());
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
} }
else else
{ {

View File

@ -57,10 +57,8 @@ namespace MusicStore
// Add EF services to the services container // Add EF services to the services container
if (useInMemoryStore) if (useInMemoryStore)
{ {
services.AddOptions(); services.AddDbContext<MusicStoreContext>(options =>
services options.UseInMemoryDatabase());
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
} }
else else
{ {

View File

@ -19,12 +19,11 @@ namespace MusicStore.Components
public CartSummaryComponentTest() public CartSummaryComponentTest()
{ {
var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddOptions(); services.AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));
services
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
} }

View File

@ -21,12 +21,11 @@ namespace MusicStore.Controllers
public CheckoutControllerTest() public CheckoutControllerTest()
{ {
var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddOptions(); services.AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));
services
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
} }

View File

@ -16,11 +16,11 @@ namespace MusicStore.Components
public GenreMenuComponentTest() public GenreMenuComponentTest()
{ {
var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddOptions();
services services.AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
} }

View File

@ -17,12 +17,11 @@ namespace MusicStore.Controllers
public HomeControllerTest() public HomeControllerTest()
{ {
var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddOptions(); services.AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));
services
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
} }

View File

@ -23,11 +23,12 @@ namespace MusicStore.Controllers
public ManageControllerTest() public ManageControllerTest()
{ {
var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddOptions(); services.AddOptions();
services services
.AddEntityFrameworkInMemoryDatabase() .AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
services.AddIdentity<ApplicationUser, IdentityRole>() services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MusicStoreContext>(); .AddEntityFrameworkStores<MusicStoreContext>();

View File

@ -45,11 +45,12 @@ namespace MusicStore.Test
public ShoppingCartFixture() public ShoppingCartFixture()
{ {
var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddOptions();
services services.AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
} }

View File

@ -24,12 +24,11 @@ namespace MusicStore.Controllers
public ShoppingCartControllerTest() public ShoppingCartControllerTest()
{ {
var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddOptions(); services.AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));
services
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
services.AddMvc(); services.AddMvc();

View File

@ -17,12 +17,11 @@ namespace MusicStore.Controllers
public StoreControllerTest() public StoreControllerTest()
{ {
var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddOptions(); services.AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));
services
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<MusicStoreContext>((p, b) => b.UseInMemoryDatabase().UseInternalServiceProvider(p));
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
} }