File tree Expand file tree Collapse file tree
Dibix.Http.Server/Runtime Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,4 +18,4 @@ public string InitiatorFullName
1818 set => _initiatorFullName = value ;
1919 }
2020 }
21- }
21+ }
Original file line number Diff line number Diff line change 1+ using Dibix . Http . Server ;
2+ using Microsoft . Extensions . DependencyInjection ;
3+
4+ namespace Dibix . Http . Host
5+ {
6+ internal sealed class DatabaseScopeFactory : IDatabaseScopeFactory
7+ {
8+ private readonly IServiceScopeFactory _scopeFactory ;
9+
10+ public DatabaseScopeFactory ( IServiceScopeFactory scopeFactory )
11+ {
12+ _scopeFactory = scopeFactory ;
13+ }
14+
15+ public IDatabaseAccessorFactory Create < TInitiator > ( ) => Create ( typeof ( TInitiator ) . FullName ! ) ;
16+ public IDatabaseAccessorFactory Create ( string initiatorFullName )
17+ {
18+ IServiceScope serviceScope = _scopeFactory . CreateScope ( ) ;
19+ DatabaseScope databaseScope = serviceScope . ServiceProvider . GetRequiredService < DatabaseScope > ( ) ;
20+ databaseScope . InitiatorFullName = initiatorFullName ;
21+ IDatabaseAccessorFactory databaseAccessorFactory = serviceScope . ServiceProvider . GetRequiredService < IDatabaseAccessorFactory > ( ) ;
22+ return databaseAccessorFactory ;
23+ }
24+ }
25+ }
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ private static async Task Main(string[] args)
3131 . AddScoped < IDatabaseAccessorFactory , ScopedDatabaseAccessorFactory > ( )
3232 . AddScoped < DatabaseScope > ( )
3333 . AddScoped < CreateDatabaseLogger > ( x => ( ) => x . GetRequiredService < ILoggerFactory > ( ) . CreateLogger ( x . GetRequiredService < DatabaseScope > ( ) . InitiatorFullName ) )
34+ . AddSingleton < IDatabaseScopeFactory , DatabaseScopeFactory > ( )
3435 . AddSingleton < HttpApiRegistryFactory > ( )
3536 . AddSingleton < IHttpApiRegistry > ( z => z . GetRequiredService < HttpApiRegistryFactory > ( ) . Create ( ) )
3637 . AddSingleton < IEndpointUrlBuilder , AssemblyEndpointConfigurationUrlBuilder > ( )
Original file line number Diff line number Diff line change 1+ namespace Dibix . Http . Server
2+ {
3+ public interface IDatabaseScopeFactory
4+ {
5+ IDatabaseAccessorFactory Create < TInitiator > ( ) ;
6+ IDatabaseAccessorFactory Create ( string initiatorFullName ) ;
7+ }
8+ }
You can’t perform that action at this time.
0 commit comments