22using System . Linq ;
33using System . Threading . Tasks ;
44using Microsoft . EntityFrameworkCore ;
5+ using Microsoft . Extensions . Configuration ;
56using Microsoft . Extensions . DependencyInjection ;
67using Microsoft . Extensions . Logging ;
78using Serilog ;
@@ -144,6 +145,8 @@ private static async Task DoMessagesDemosAsync(IServiceProvider serviceProvider,
144145
145146 private static IServiceProvider CreateServiceProvider ( LoggingLevelSwitch loggingLevelSwitch )
146147 {
148+ var configuration = GetConfiguration ( ) ;
149+
147150 return new ServiceCollection ( )
148151 . AddLogging ( builder =>
149152 {
@@ -157,7 +160,7 @@ private static IServiceProvider CreateServiceProvider(LoggingLevelSwitch logging
157160
158161 builder . AddSerilog ( serilogLogger ) ;
159162 } )
160- . AddDbContext < ProductsDbContext > ( builder => builder . UseSqlServer ( "Server=localhost;Database=TT-Runtime-Extensions-Demo;Integrated Security=true;TrustServerCertificate=true" )
163+ . AddDbContext < ProductsDbContext > ( builder => builder . UseSqlServer ( configuration . GetConnectionString ( "default" ) )
161164 . EnableSensitiveDataLogging ( )
162165 . UseThinktectureValueConverters ( configureEnumsAndKeyedValueObjects : property =>
163166 {
@@ -179,6 +182,14 @@ private static IServiceProvider CreateServiceProvider(LoggingLevelSwitch logging
179182 . BuildServiceProvider ( ) ;
180183 }
181184
185+ private static IConfiguration GetConfiguration ( )
186+ {
187+ return new ConfigurationBuilder ( )
188+ . AddJsonFile ( "appsettings.json" )
189+ . AddUserSecrets < Program > ( )
190+ . Build ( ) ;
191+ }
192+
182193 private static int RoundUp ( int value )
183194 {
184195 return value + ( 10 - value % 10 ) ;
0 commit comments