11namespace Puzzle . Core . Multitenancy . Extensions
22{
33 using System ;
4+ using System . Collections . Generic ;
45 using System . ComponentModel ;
6+ using Microsoft . Extensions . Configuration ;
7+ using Microsoft . Extensions . DependencyInjection ;
58 using Puzzle . Core . Multitenancy . Internal . Configurations ;
69 using Puzzle . Core . Multitenancy . Internal . Logging . LibLog ;
710 using Puzzle . Core . Multitenancy . Internal . Logging . LibLog . LogProviders ;
811
9- internal static class MultiTenancyConfigExtensions
12+ /// <summary>
13+ /// Extensions methos for add/or override configuration for MultiTenancyConfig.
14+ /// </summary>
15+ public static class MultiTenancyConfigExtensions
1016 {
17+
18+
19+ /// <summary>
20+ /// Set current LogProvider.
21+ /// </summary>
22+ /// <typeparam name="TTenant"></typeparam>
23+ /// <typeparam name="TLogProvider"></typeparam>
24+ /// <param name="configuration"></param>
25+ /// <param name="provider"></param>
26+ /// <returns></returns>
1127 public static MultiTenancyConfig < TTenant > UseLogProvider < TTenant , TLogProvider > ( this MultiTenancyConfig < TTenant > configuration , TLogProvider provider )
1228 where TLogProvider : ILogProvider
1329 {
14- if ( configuration == null )
15- {
16- throw new ArgumentNullException ( nameof ( configuration ) ) ;
17- }
18-
19- if ( provider == null )
20- {
21- throw new ArgumentNullException ( nameof ( provider ) ) ;
22- }
23-
2430 return configuration . Use ( provider , x => LogProvider . SetCurrentLogProvider ( x ) ) ;
2531 }
2632
27-
28-
29-
30- public static MultiTenancyConfig < TTenant > UseColoredConsoleLogProvider < TTenant > ( this MultiTenancyConfig < TTenant > configuration )
33+ /// <summary>
34+ /// Activate ConsoleLog.
35+ /// </summary>
36+ /// <typeparam name="TTenant"></typeparam>
37+ /// <param name="configuration"></param>
38+ /// <returns></returns>
39+ internal static MultiTenancyConfig < TTenant > UseColoredConsoleLogProvider < TTenant > ( this MultiTenancyConfig < TTenant > configuration )
3140 {
32- if ( configuration == null )
33- {
34- throw new ArgumentNullException ( nameof ( configuration ) ) ;
35- }
36-
3741 return configuration . UseLogProvider ( new ColoredConsoleLogProvider ( ) ) ;
3842 }
3943
40- /*
41- public static MultiTenancyConfig UseLog4NetLogProvider(this MultiTenancyConfig configuration)
42- {
43- if (configuration == null)
44- {
45- throw new ArgumentNullException(nameof(configuration));
46- }
47-
48- return configuration.UseLogProvider(new Log4NetLogProvider());
49- }
50- */
5144
45+ /// <summary>
46+ /// Add serilo ProviderLog.
47+ /// </summary>
48+ /// <param name="configuration"></param>
49+ /// <returns></returns>
50+ internal static MultiTenancyConfig < TTenant > UseSerilogLogProvider < TTenant > ( this MultiTenancyConfig < TTenant > configuration )
51+ {
52+ return configuration . UseLogProvider ( new SerilogLogProvider ( ) ) ;
53+ }
5254
53- /*
55+ /// <summary>
56+ ///
57+ /// </summary>
58+ /// <typeparam name="TTenant"></typeparam>
59+ /// <typeparam name="TLogProvider"></typeparam>
60+ /// <param name="configuration"></param>
61+ /// <param name="tenant"></param>
62+ /// <param name="tenantConfiguration"></param>
63+ /// <param name="provider"></param>
64+ /// <returns></returns>
65+ public static MultiTenancyConfig < TTenant > UseLogCustomServicesTenant < TTenant , TLogProvider > (
66+ this MultiTenancyConfig < TTenant > configuration , TTenant tenant , IConfiguration tenantConfiguration , TLogProvider provider )
67+ where TLogProvider : ILogProvider
68+ {
69+ return configuration . Use ( provider , x => LogProvider . SetCurrentLogProvider ( x ) ) ;
70+ }
5471
55- public static MultiTenancyConfig UseSerilogLogProvider(this MultiTenancyConfig configuration)
72+ /// <summary>
73+ ///
74+ /// </summary>
75+ /// <typeparam name="TTenant"></typeparam>
76+ /// <param name="configuration"></param>
77+ /// <param name="func"></param>
78+ /// <returns></returns>
79+ public static MultiTenancyConfig < TTenant > UseCustomServicesTenant < TTenant > (
80+ this MultiTenancyConfig < TTenant > configuration , Func < IServiceCollection , TTenant , IConfiguration , ILogProvider > func )
5681 {
57- if (configuration == null)
58- {
59- throw new ArgumentNullException(nameof(configuration));
60- }
82+ configuration . SetTenantLogProvider ( func ) ;
83+ return configuration ;
84+ }
6185
62- return configuration.UseLogProvider(new SerilogLogProvider());
86+ /// <summary>
87+ /// Add additionnal ConfigureServices for specific tenant.
88+ /// </summary>
89+ /// <typeparam name="TTenant"></typeparam>
90+ /// <param name="configuration">Object represents MultiTenancyConfig.</param>
91+ /// <param name="action">Action to configure services.</param>
92+ /// <returns></returns>
93+ public static MultiTenancyConfig < TTenant > UseConfigureServicesTenant < TTenant > (
94+ this MultiTenancyConfig < TTenant > configuration , Action < IServiceCollection , TTenant > action )
95+ {
96+ return configuration . Use ( action , x => configuration . SetConfigureServicesTenant ( action ) ) ;
6397 }
64- */
6598
99+
100+
101+ /// <summary>
102+ ///
103+ /// </summary>
104+ /// <typeparam name="TTenant"></typeparam>
105+ /// <typeparam name="T"></typeparam>
106+ /// <param name="configuration"></param>
107+ /// <param name="entry"></param>
108+ /// <param name="entryAction"></param>
109+ /// <returns></returns>
66110 [ EditorBrowsable ( EditorBrowsableState . Never ) ]
67111 public static MultiTenancyConfig < TTenant > Use < TTenant , T > ( this MultiTenancyConfig < TTenant > configuration , T entry , Action < T > entryAction )
68112 {
@@ -71,8 +115,7 @@ public static MultiTenancyConfig<TTenant> Use<TTenant,T>(this MultiTenancyConfig
71115 throw new ArgumentNullException ( nameof ( configuration ) ) ;
72116 }
73117
74- entryAction ( entry ) ;
75-
118+ entryAction ? . Invoke ( entry ) ;
76119 return configuration ;
77120 }
78121 }
0 commit comments