File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88var builder = webKernelBuilder . AppBuilder ;
99
10- webKernelBuilder . AddModule < SampleModule > ( ) ;
10+ webKernelBuilder . AddModule < SampleModule , SampleModuleConfigurator > ( ) ;
1111
1212builder . Services . AddEndpointsApiExplorer ( ) ;
1313builder . Services . AddSwaggerGen ( ) ;
Original file line number Diff line number Diff line change 1- using EasyWay . Samples . Databases ;
2- using Microsoft . EntityFrameworkCore ;
3- using System . Reflection ;
4-
5- namespace EasyWay . Samples
1+ namespace EasyWay . Samples
62{
7- public sealed class SampleModule : EasyWayModule
8- {
9- protected override IEnumerable < Assembly > Assemblies => new List < Assembly >
10- {
11- typeof ( SampleModule ) . Assembly
12- } ;
13-
14- protected override void ConfigureDependencies ( IServiceCollection services , IConfiguration configuration )
15- {
16- string connectionString = configuration . GetConnectionString ( "Database" ) ;
17-
18- services . AddEntityFrameworkCore < SampleDbContext > ( x => x . UseNpgsql ( connectionString ) ) ;
19- }
20- }
3+ public sealed class SampleModule : EasyWayModule ;
214}
Original file line number Diff line number Diff line change 1+ using EasyWay . Samples . Databases ;
2+ using Microsoft . EntityFrameworkCore ;
3+ using System . Reflection ;
4+
5+ namespace EasyWay . Samples
6+ {
7+ public class SampleModuleConfigurator : ModuleConfigurator < SampleModule >
8+ {
9+ protected override IEnumerable < Assembly > Assemblies => new List < Assembly >
10+ {
11+ typeof ( SampleModule ) . Assembly
12+ } ;
13+
14+ protected override void ConfigureDependencies ( IServiceCollection services , IConfiguration configuration )
15+ {
16+ string connectionString = configuration . GetConnectionString ( "Database" ) ;
17+
18+ services . AddEntityFrameworkCore < SampleDbContext > ( x => x . UseNpgsql ( connectionString ) ) ;
19+ }
20+ }
21+ }
Original file line number Diff line number Diff line change 11using EasyWay ;
2+ using Payments . Application ;
23using Payments . Infrastructure ;
34
45var webKernelBuilder = WebKernel . CreateBuilder ( args ) ;
56
67var builder = webKernelBuilder . AppBuilder ;
78
8- webKernelBuilder . AddModule < PaymentsModule > ( ) ;
9+ webKernelBuilder . AddModule < PaymentsModule , PaymentsModuleConfigurator > ( ) ;
910
1011builder . Services . AddEndpointsApiExplorer ( ) ;
1112builder . Services . AddSwaggerGen ( ) ;
Original file line number Diff line number Diff line change 1+ using EasyWay ;
2+
3+ namespace Payments . Application
4+ {
5+ public sealed class PaymentsModule : EasyWayModule ;
6+ }
Original file line number Diff line number Diff line change 11using EasyWay ;
22using Microsoft . Extensions . Configuration ;
33using Microsoft . Extensions . DependencyInjection ;
4+ using Payments . Application ;
45using Payments . Domain . Payments ;
56using System . Reflection ;
67
78namespace Payments . Infrastructure
89{
9- public sealed class PaymentsModule : EasyWayModule
10+ public sealed class PaymentsModuleConfigurator : ModuleConfigurator < PaymentsModule >
1011 {
11- //TODO Module
1212 protected override IEnumerable < Assembly > Assemblies => new List < Assembly >
1313 {
1414 typeof ( Payment ) . Assembly ,
Original file line number Diff line number Diff line change @@ -11,15 +11,16 @@ internal WebKernelBuilder(WebApplicationBuilder webApplicationBuilder)
1111 AppBuilder = webApplicationBuilder ;
1212 }
1313
14- public void AddModule < TModule > ( )
15- where TModule : EasyWayModule , new ( )
14+ public void AddModule < TModule , TModuleConfigurator > ( )
15+ where TModule : EasyWayModule
16+ where TModuleConfigurator : ModuleConfigurator < TModule > , new ( )
1617 {
1718 var services = AppBuilder . Services ;
1819 var configuration = AppBuilder . Configuration . GetSection ( typeof ( TModule ) . Name ) ;
1920
20- var module = new TModule ( ) ;
21+ var moduleConfigurator = new TModuleConfigurator ( ) ;
2122
22- module . Initialize < TModule > ( services , configuration ) ;
23+ moduleConfigurator . Initialize ( services , configuration ) ;
2324 }
2425
2526 public WebKernel Build ( )
Original file line number Diff line number Diff line change 1- using EasyWay . Internals ;
2- using EasyWay . Internals . Modules ;
3- using Microsoft . Extensions . Configuration ;
4- using Microsoft . Extensions . DependencyInjection ;
5- using System . Reflection ;
6-
7- namespace EasyWay
1+ namespace EasyWay
82{
9- public abstract class EasyWayModule
10- {
11- internal void Initialize < TModule > ( IServiceCollection services , IConfiguration configuration )
12- where TModule : EasyWayModule
13- {
14- services . AddEasyWay < TModule > ( Assemblies ) ;
15-
16- ConfigureDependencies ( services , configuration ) ;
17-
18- services . AddSingleton < IModuleExecutor < TModule > , ModuleExecutor < TModule > > ( ) ;
19- }
20-
21- protected abstract IEnumerable < Assembly > Assemblies { get ; }
22-
23- protected abstract void ConfigureDependencies ( IServiceCollection services , IConfiguration configuration ) ;
24- }
3+ public abstract class EasyWayModule ;
254}
Original file line number Diff line number Diff line change 1+ using EasyWay . Internals ;
2+ using EasyWay . Internals . Modules ;
3+ using Microsoft . Extensions . Configuration ;
4+ using Microsoft . Extensions . DependencyInjection ;
5+ using System . Reflection ;
6+
7+ namespace EasyWay
8+ {
9+ public abstract class ModuleConfigurator < TModule >
10+ where TModule : EasyWayModule
11+ {
12+ internal void Initialize ( IServiceCollection services , IConfiguration configuration )
13+ {
14+ services . AddEasyWay < TModule > ( Assemblies ) ;
15+
16+ ConfigureDependencies ( services , configuration ) ;
17+
18+ services . AddSingleton < IModuleExecutor < TModule > , ModuleExecutor < TModule > > ( ) ;
19+ }
20+
21+ protected abstract IEnumerable < Assembly > Assemblies { get ; }
22+
23+ protected abstract void ConfigureDependencies ( IServiceCollection services , IConfiguration configuration ) ;
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments