@@ -5,6 +5,7 @@ namespace EstateReportingAPI.Bootstrapper;
55using BusinessLogic ;
66using Common ;
77using Lamar ;
8+ using Microsoft . EntityFrameworkCore ;
89using Shared . EntityFramework ;
910using Shared . EntityFramework . ConnectionStringConfiguration ;
1011using Shared . General ;
@@ -14,31 +15,21 @@ namespace EstateReportingAPI.Bootstrapper;
1415[ ExcludeFromCodeCoverage ]
1516public class RepositoryRegistry : ServiceRegistry {
1617 public RepositoryRegistry ( ) {
17-
18- Boolean useConnectionStringConfig = bool . Parse ( ConfigurationReader . GetValue ( "AppSettings" , "UseConnectionStringConfig" ) ) ;
19-
20- if ( useConnectionStringConfig )
18+ String ? inTestMode = Environment . GetEnvironmentVariable ( "InTestMode" ) ;
19+ if ( String . Compare ( inTestMode , Boolean . TrueString , StringComparison . InvariantCultureIgnoreCase ) != 0 )
2120 {
22- String connectionStringConfigurationConnString = ConfigurationReader . GetConnectionString ( "ConnectionStringConfiguration" ) ;
23- this . AddSingleton < IConnectionStringConfigurationRepository , ConnectionStringConfigurationRepository > ( ) ;
24- this . AddTransient ( c => { return new ConnectionStringConfigurationContext ( connectionStringConfigurationConnString ) ; } ) ;
21+ this . AddSingleton < IReportingManager , ReportingManager > ( ) ;
22+ }
2523
26- // TODO: Read this from a the database and set
24+ this . AddSingleton ( typeof ( IDbContextResolver < > ) , typeof ( DbContextResolver < > ) ) ;
25+ if ( Startup . WebHostEnvironment . IsEnvironment ( "IntegrationTest" ) || Startup . Configuration . GetValue < Boolean > ( "ServiceOptions:UseInMemoryDatabase" ) == true )
26+ {
27+ this . AddDbContext < EstateManagementContext > ( builder => builder . UseInMemoryDatabase ( "TransactionProcessorReadModel" ) ) ;
2728 }
2829 else
2930 {
30- this . AddSingleton < IConnectionStringConfigurationRepository , ConfigurationReaderConnectionStringRepository > ( ) ;
31+ this . AddDbContext < EstateManagementContext > ( options =>
32+ options . UseSqlServer ( ConfigurationReader . GetConnectionString ( "TransactionProcessorReadModel" ) ) ) ;
3133 }
32-
33- String ? inTestMode = Environment . GetEnvironmentVariable ( "InTestMode" ) ;
34- if ( String . Compare ( inTestMode , Boolean . TrueString , StringComparison . InvariantCultureIgnoreCase ) != 0 ) {
35- this . AddSingleton < IReportingManager , ReportingManager > ( ) ;
36- }
37-
38- this . AddSingleton < IDbContextFactory < EstateManagementContext > , DbContextFactory < EstateManagementContext > > ( ) ;
39-
40- this . AddSingleton < Func < String , EstateManagementContext > > ( cont => connectionString => {
41- return new EstateManagementContext ( connectionString ) ;
42- } ) ;
4334 }
4435}
0 commit comments