@@ -20,22 +20,46 @@ public static void AddDefinitions(this IServiceCollection source, WebApplication
2020 {
2121 var logger = source . BuildServiceProvider ( ) . GetRequiredService < ILogger < AppDefinition > > ( ) ;
2222 var definitions = new List < IAppDefinition > ( ) ;
23+ var appDefinitionInfo = source . BuildServiceProvider ( ) . GetService < AppDefinitionCollection > ( ) ;
24+ var info = appDefinitionInfo ?? new AppDefinitionCollection ( ) ;
25+
2326 foreach ( var entryPoint in entryPointsAssembly )
2427 {
28+ info . AddEntryPoint ( entryPoint . Name ) ;
29+
30+
2531 var types = entryPoint . Assembly . ExportedTypes . Where ( x => ! x . IsAbstract && typeof ( IAppDefinition ) . IsAssignableFrom ( x ) ) ;
2632 var instances = types . Select ( Activator . CreateInstance ) . Cast < IAppDefinition > ( ) . ToList ( ) ;
27- var instancesOrdered = instances . Where ( x => x . Enabled ) . OrderBy ( x => x . OrderIndex ) . ToList ( ) ;
28- if ( logger . IsEnabled ( LogLevel . Debug ) )
33+ //if (logger.IsEnabled(LogLevel.Debug))
34+ //{
35+ // logger.LogDebug("AppDefinitions Founded: {@AppDefinitionsCountTotal}.", instances.Count);
36+ //}
37+
38+ foreach ( var definition in instances )
2939 {
30- logger . LogDebug ( @"[AppDefinitions] Founded: {AppDefinitionsCountTotal}. Enabled: {AppDefinitionsCountEnabled}" , instances . Count , instancesOrdered . Count ) ;
31- logger . LogDebug ( @"[AppDefinitions] Registered [{Total}]" , string . Join ( ", " , instancesOrdered . Select ( x => x . GetType ( ) . Name ) . ToArray ( ) ) ) ;
40+ info . AddInfo ( new AppDefinitionItem ( definition ) ) ;
3241 }
3342
43+ var instancesOrdered = instances . Where ( x => x . Enabled ) . OrderBy ( x => x . OrderIndex ) . ToList ( ) ;
3444 definitions . AddRange ( instancesOrdered ) ;
3545 }
3646
37- definitions . ForEach ( app => app . ConfigureServices ( source , builder ) ) ;
38- source . AddSingleton ( definitions as IReadOnlyCollection < IAppDefinition > ) ;
47+ foreach ( var definition in definitions )
48+ {
49+ definition . ConfigureServices ( source , builder ) ;
50+ }
51+ if ( logger . IsEnabled ( LogLevel . Debug ) )
52+ {
53+ logger . LogDebug ( "[AppDefinitions]: From {@items}" , string . Join ( ", " , info . EntryPoints ) ) ;
54+
55+
56+ foreach ( var item in info . Items . OrderBy ( x => x . Definition . GetType ( ) . Name ) )
57+ {
58+ logger . LogDebug ( "[AppDefinitions]: {@AppDefinitionName} (Enabled: {@Enabled})" , item . Definition . GetType ( ) . Name , item . Definition . Enabled ? "Yes" : "No" ) ;
59+ }
60+ }
61+
62+ source . AddSingleton ( info ) ;
3963 }
4064
4165 /// <summary>
@@ -49,14 +73,20 @@ public static void AddDefinitions(this IServiceCollection source, WebApplication
4973 public static void UseDefinitions ( this WebApplication source )
5074 {
5175 var logger = source . Services . GetRequiredService < ILogger < AppDefinition > > ( ) ;
52- var definitions = source . Services . GetRequiredService < IReadOnlyCollection < IAppDefinition > > ( ) ;
53- var instancesOrdered = definitions . Where ( x => x . Enabled ) . OrderBy ( x => x . OrderIndex ) . ToList ( ) ;
76+ var definitions = source . Services . GetRequiredService < AppDefinitionCollection > ( ) ;
77+
78+ if ( logger . IsEnabled ( LogLevel . Debug ) )
79+ {
80+ logger . LogDebug ( "From {Modules} assemblies totally AppDefinitions found: {Count} " , string . Join ( ", " , definitions . EntryPoints ) , definitions . Items . Count ) ;
81+ }
82+
83+ var instancesOrdered = definitions . Items . Where ( x => x . Definition . Enabled ) . OrderBy ( x => x . Definition . OrderIndex ) . ToList ( ) ;
5484
55- instancesOrdered . ForEach ( x => x . ConfigureApplication ( source ) ) ;
85+ instancesOrdered . ForEach ( x => x . Definition . ConfigureApplication ( source ) ) ;
5686
5787 if ( logger . IsEnabled ( LogLevel . Debug ) )
5888 {
59- logger . LogDebug ( "Total application definitions configured {Count}" , instancesOrdered . Count ) ;
89+ logger . LogDebug ( "Total AppDefinitions applied: {Count}" , instancesOrdered . Count ) ;
6090 }
6191 }
6292
0 commit comments