File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
application/shared-kernel/SharedKernel/Configuration Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 77using Microsoft . ApplicationInsights . Extensibility ;
88using Microsoft . AspNetCore . Http ;
99using Microsoft . EntityFrameworkCore ;
10+ using Npgsql ;
1011using Microsoft . Extensions . Configuration ;
1112using Microsoft . Extensions . DependencyInjection ;
1213using Microsoft . Extensions . Hosting ;
@@ -85,8 +86,20 @@ private IHostApplicationBuilder ConfigureDatabaseContext<T>(string connectionNam
8586 ? Environment . GetEnvironmentVariable ( "DATABASE_CONNECTION_STRING" )
8687 : builder . Configuration . GetConnectionString ( connectionName ) ;
8788
89+ var dataSourceBuilder = new NpgsqlDataSourceBuilder ( connectionString ) ;
90+ if ( IsRunningInAzure )
91+ {
92+ var credential = new DefaultAzureCredential ( ) ;
93+ dataSourceBuilder . UsePeriodicPasswordProvider ( async ( _ , cancellationToken ) =>
94+ {
95+ var token = await credential . GetTokenAsync ( new Azure . Core . TokenRequestContext ( [ "https://ossrdbms-aad.database.windows.net/.default" ] ) , cancellationToken ) ;
96+ return token . Token ;
97+ } , TimeSpan . FromMinutes ( 30 ) , TimeSpan . FromSeconds ( 5 ) ) ;
98+ }
99+
100+ var dataSource = dataSourceBuilder . Build ( ) ;
88101 builder . Services . AddDbContext < T > ( options =>
89- options . UseNpgsql ( connectionString , o => o . MigrationsHistoryTable ( "__ef_migrations_history" ) ) . UseSnakeCaseNamingConvention ( )
102+ options . UseNpgsql ( dataSource , o => o . MigrationsHistoryTable ( "__ef_migrations_history" ) ) . UseSnakeCaseNamingConvention ( )
90103 ) ;
91104
92105 return builder ;
You can’t perform that action at this time.
0 commit comments