1010using Microsoft . Extensions . DependencyInjection ;
1111using Microsoft . Extensions . Logging ;
1212
13- namespace ExtCore . Data . Dapper . Actions
13+ namespace ExtCore . Data . Dapper . Actions ;
14+
15+ /// <summary>
16+ /// Implements the <see cref="IConfigureServicesAction">IConfigureServicesAction</see> interface and
17+ /// registers found implementation of the <see cref="IStorageContext">IStorageContext</see> interface inside the DI.
18+ /// </summary>
19+ public class AddStorageContextAction : IConfigureServicesAction
1420{
1521 /// <summary>
16- /// Implements the <see cref="IConfigureServicesAction">IConfigureServicesAction</see> interface and
17- /// registers found implementation of the <see cref="IStorageContext">IStorageContext</see> interface inside the DI.
22+ /// Priority of the action. The actions will be executed in the order specified by the priority (from smallest to largest).
23+ /// </summary>
24+ public int Priority => 1000 ;
25+
26+ /// <summary>
27+ /// Registers found implementation of the <see cref="IStorageContext">IStorageContext</see> interface inside the DI.
1828 /// </summary>
19- public class AddStorageContextAction : IConfigureServicesAction
29+ /// <param name="services">
30+ /// Will be provided by the ExtCore and might be used to register any service inside the DI.
31+ /// </param>
32+ /// <param name="serviceProvider">
33+ /// Will be provided by the ExtCore and might be used to get any service that is registered inside the DI at this moment.
34+ /// </param>
35+ public void Execute ( IServiceCollection services , IServiceProvider serviceProvider )
2036 {
21- /// <summary>
22- /// Priority of the action. The actions will be executed in the order specified by the priority (from smallest to largest).
23- /// </summary>
24- public int Priority => 1000 ;
37+ Type type = ExtensionManager . GetImplementations < IStorageContext > ( ) ? . FirstOrDefault ( t => ! t . GetTypeInfo ( ) . IsAbstract ) ;
2538
26- /// <summary>
27- /// Registers found implementation of the <see cref="IStorageContext">IStorageContext</see> interface inside the DI.
28- /// </summary>
29- /// <param name="services">
30- /// Will be provided by the ExtCore and might be used to register any service inside the DI.
31- /// </param>
32- /// <param name="serviceProvider">
33- /// Will be provided by the ExtCore and might be used to get any service that is registered inside the DI at this moment.
34- /// </param>
35- public void Execute ( IServiceCollection services , IServiceProvider serviceProvider )
39+ if ( type == null )
3640 {
37- Type type = ExtensionManager . GetImplementations < IStorageContext > ( ) ? . FirstOrDefault ( t => ! t . GetTypeInfo ( ) . IsAbstract ) ;
41+ ILogger logger = serviceProvider . GetService < ILoggerFactory > ( ) . CreateLogger ( "ExtCore.Data.Dapper" ) ;
3842
39- if ( type == null )
40- {
41- ILogger logger = serviceProvider . GetService < ILoggerFactory > ( ) . CreateLogger ( "ExtCore.Data.Dapper" ) ;
42-
43- logger . LogError ( "Implementation of ExtCore.Data.Abstractions.IStorageContext not found" ) ;
44- return ;
45- }
46-
47- services . AddScoped ( typeof ( IStorageContext ) , type ) ;
43+ logger . LogError ( "Implementation of ExtCore.Data.Abstractions.IStorageContext not found" ) ;
44+ return ;
4845 }
46+
47+ services . AddScoped ( typeof ( IStorageContext ) , type ) ;
4948 }
5049}
0 commit comments