From 2f17838a69440a92b91aff4e399eba62bfe5e451 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Fri, 27 Sep 2019 09:15:33 -0400 Subject: [PATCH] rename to ReplaceCoreServices --- .../TestInMemory/CustomWebFactory.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/All/test/TestTheTest/TestInMemory/CustomWebFactory.cs b/All/test/TestTheTest/TestInMemory/CustomWebFactory.cs index 57977c9..4ac99b4 100644 --- a/All/test/TestTheTest/TestInMemory/CustomWebFactory.cs +++ b/All/test/TestTheTest/TestInMemory/CustomWebFactory.cs @@ -35,7 +35,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) // // This will replace DbContextOptions // - //AddCoreServices(services, (p, o) => + //ReplaceCoreServices(services, (p, o) => //{ // o.UseInMemoryDatabase("DB"); //}, ServiceLifetime.Scoped); @@ -43,15 +43,21 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) }); } - private static void AddCoreServices(IServiceCollection serviceCollection, Action optionsAction, ServiceLifetime optionsLifetime) where TContextImplementation : DbContext + private static void ReplaceCoreServices(IServiceCollection serviceCollection, + Action optionsAction, + ServiceLifetime optionsLifetime) where TContextImplementation : DbContext { - serviceCollection.Add(new ServiceDescriptor(typeof(DbContextOptions), (IServiceProvider p) => DbContextOptionsFactory(p, optionsAction), optionsLifetime)); - serviceCollection.Add(new ServiceDescriptor(typeof(DbContextOptions), (IServiceProvider p) => p.GetRequiredService>(), optionsLifetime)); + serviceCollection.Add(new ServiceDescriptor(typeof(DbContextOptions), + (IServiceProvider p) => DbContextOptionsFactory(p, optionsAction), optionsLifetime)); + serviceCollection.Add(new ServiceDescriptor(typeof(DbContextOptions), + (IServiceProvider p) => p.GetRequiredService>(), optionsLifetime)); } - private static DbContextOptions DbContextOptionsFactory(IServiceProvider applicationServiceProvider, Action optionsAction) where TContext : DbContext + private static DbContextOptions DbContextOptionsFactory(IServiceProvider applicationServiceProvider, + Action optionsAction) where TContext : DbContext { - DbContextOptionsBuilder dbContextOptionsBuilder = new DbContextOptionsBuilder(new DbContextOptions(new Dictionary())); + DbContextOptionsBuilder dbContextOptionsBuilder = new DbContextOptionsBuilder( + new DbContextOptions(new Dictionary())); dbContextOptionsBuilder.UseApplicationServiceProvider(applicationServiceProvider); optionsAction?.Invoke(applicationServiceProvider, dbContextOptionsBuilder); return dbContextOptionsBuilder.Options;