|
1 | | -/*---------------------------------------------------------------- |
2 | | - Copyright (C) 2024 Senparc |
3 | | -
|
4 | | - FileName: Register.cs |
5 | | - File Function Description: Senparc.CO2NET quick registration process (including Thread, TraceLog, etc.) |
6 | | -
|
7 | | -
|
8 | | - Creation Identifier: Senparc - 20180222 |
9 | | -
|
10 | | - Modification Identifier: Senparc - 20180516 |
11 | | - Modification Description: Optimize RegisterService |
12 | | -
|
13 | | - Modification Identifier: Senparc - 20180704 |
14 | | - Modification Description: v0.1.6.1 Add Register.UseSenparcGlobal() method |
15 | | -
|
16 | | - Modification Identifier: Senparc - 20180707 |
17 | | - Modification Description: v0.1.9 Remove senparcSetting parameter from UseSenparcGlobal() method, as it is already provided in RegisterService.Start |
18 | | -
|
19 | | -----------------------------------------------------------------*/ |
20 | | - |
21 | | - |
22 | | - |
23 | | -using System; |
24 | | -using Senparc.CO2NET.Threads; |
25 | | -using Senparc.CO2NET.RegisterServices; |
26 | | -using Senparc.CO2NET.Cache; |
27 | | -using System.Collections.Generic; |
28 | | -using System.Linq; |
29 | | -using Senparc.CO2NET.Helpers; |
30 | | -using Senparc.CO2NET.Extensions; |
31 | | -using Microsoft.Extensions.Configuration; |
32 | | - |
33 | | - |
34 | | -namespace Senparc.CO2NET |
35 | | -{ |
36 | | - /// <summary> |
37 | | - /// Senparc.CO2NET basic information registration |
38 | | - /// </summary> |
39 | | - public static class Register |
40 | | - { |
41 | | - /// <summary> |
42 | | - /// Modify the default cache namespace |
43 | | - /// </summary> |
44 | | - /// <param name="registerService">RegisterService</param> |
45 | | - /// <param name="customNamespace">Custom namespace name</param> |
| 1 | +/*---------------------------------------------------------------- |
| 2 | + Copyright (C) 2024 Senparc |
| 3 | +
|
| 4 | + FileName: Register.cs |
| 5 | + File Function Description: Senparc.CO2NET quick registration process (including Thread, TraceLog, etc.) |
| 6 | +
|
| 7 | +
|
| 8 | + Creation Identifier: Senparc - 20180222 |
| 9 | +
|
| 10 | + Modification Identifier: Senparc - 20180516 |
| 11 | + Modification Description: Optimize RegisterService |
| 12 | +
|
| 13 | + Modification Identifier: Senparc - 20180704 |
| 14 | + Modification Description: v0.1.6.1 Add Register.UseSenparcGlobal() method |
| 15 | +
|
| 16 | + Modification Identifier: Senparc - 20180707 |
| 17 | + Modification Description: v0.1.9 Remove senparcSetting parameter from UseSenparcGlobal() method, as it is already provided in RegisterService.Start |
| 18 | +
|
| 19 | +----------------------------------------------------------------*/ |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +using System; |
| 25 | +using Senparc.CO2NET.Threads; |
| 26 | +using Senparc.CO2NET.RegisterServices; |
| 27 | +using Senparc.CO2NET.Cache; |
| 28 | +using System.Collections.Generic; |
| 29 | +using System.Linq; |
| 30 | +using Senparc.CO2NET.Helpers; |
| 31 | +using Senparc.CO2NET.Extensions; |
| 32 | +using Microsoft.Extensions.Configuration; |
| 33 | + |
| 34 | + |
| 35 | +namespace Senparc.CO2NET |
| 36 | +{ |
| 37 | + /// <summary> |
| 38 | + /// Senparc.CO2NET basic information registration |
| 39 | + /// </summary> |
| 40 | + public static class Register |
| 41 | + { |
| 42 | + /// <summary> |
| 43 | + /// Modify the default cache namespace |
| 44 | + /// </summary> |
| 45 | + /// <param name="registerService">RegisterService</param> |
| 46 | + /// <param name="customNamespace">Custom namespace name</param> |
46 | 47 | /// <returns></returns> |
47 | | - public static IRegisterService ChangeDefaultCacheNamespace(this IRegisterService registerService, string customNamespace) |
48 | | - { |
49 | | - Config.DefaultCacheNamespace = customNamespace; |
50 | | - return registerService; |
51 | | - } |
52 | | - |
53 | | - |
54 | | - /// <summary> |
55 | | - /// Method to register Threads (if this thread is not registered, AccessToken, JsTicket, etc. cannot use SDK for automatic storage and management) |
56 | | - /// </summary> |
57 | | - /// <param name="registerService">RegisterService</param> |
| 48 | + public static IRegisterService ChangeDefaultCacheNamespace(this IRegisterService registerService, string customNamespace) |
| 49 | + { |
| 50 | + Config.DefaultCacheNamespace = customNamespace; |
| 51 | + return registerService; |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Method to register Threads (if this thread is not registered, AccessToken, JsTicket, etc. cannot use SDK for automatic storage and management) |
| 57 | + /// </summary> |
| 58 | + /// <param name="registerService">RegisterService</param> |
58 | 59 | /// <returns></returns> |
59 | | - public static IRegisterService RegisterThreads(this IRegisterService registerService) |
60 | | - { |
61 | | - ThreadUtility.Register();// If this thread is not registered, AccessToken, JsTicket, etc. cannot use SDK for automatic storage and management. |
62 | | - return registerService; |
63 | | - } |
64 | | - |
65 | | - /// <summary> |
66 | | - /// Method to register TraceLog |
67 | | - /// </summary> |
68 | | - /// <param name="registerService">RegisterService</param> |
69 | | - /// <param name="action"></param> |
| 60 | + public static IRegisterService RegisterThreads(this IRegisterService registerService) |
| 61 | + { |
| 62 | + ThreadUtility.Register();// If this thread is not registered, AccessToken, JsTicket, etc. cannot use SDK for automatic storage and management. |
| 63 | + return registerService; |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Method to register TraceLog |
| 68 | + /// </summary> |
| 69 | + /// <param name="registerService">RegisterService</param> |
| 70 | + /// <param name="action"></param> |
70 | 71 | /// <returns></returns> |
71 | | - public static IRegisterService RegisterTraceLog(this IRegisterService registerService, Action action) |
72 | | - { |
73 | | - action(); |
74 | | - return registerService; |
75 | | - } |
76 | | - |
77 | | - /// <summary> |
78 | | - /// Start Senparc.CO2NET initialization parameter process |
79 | | - /// </summary> |
80 | | - /// <param name="registerService"></param> |
81 | | - /// <param name="autoScanExtensionCacheStrategies">Whether to automatically scan global extension caches (will increase system startup time)</param> |
82 | | - /// <param name="extensionCacheStrategiesFunc"><para>Extension cache strategies that need to be manually registered</para> |
83 | | - /// <para>(LocalContainerCacheStrategy, RedisContainerCacheStrategy, MemcacheContainerCacheStrategy are already automatically registered),</para> |
84 | | - /// <para>If set to null (note: not delegate returning null, but the entire delegate parameter is null), it will automatically use reflection to scan all possible extension cache strategies</para></param> |
| 72 | + public static IRegisterService RegisterTraceLog(this IRegisterService registerService, Action action) |
| 73 | + { |
| 74 | + action(); |
| 75 | + return registerService; |
| 76 | + } |
| 77 | + |
| 78 | + /// <summary> |
| 79 | + /// Start Senparc.CO2NET initialization parameter process |
| 80 | + /// </summary> |
| 81 | + /// <param name="registerService"></param> |
| 82 | + /// <param name="autoScanExtensionCacheStrategies">Whether to automatically scan global extension caches (will increase system startup time)</param> |
| 83 | + /// <param name="extensionCacheStrategiesFunc"><para>Extension cache strategies that need to be manually registered</para> |
| 84 | + /// <para>(LocalContainerCacheStrategy, RedisContainerCacheStrategy, MemcacheContainerCacheStrategy are already automatically registered),</para> |
| 85 | + /// <para>If set to null (note: not delegate returning null, but the entire delegate parameter is null), it will automatically use reflection to scan all possible extension cache strategies</para></param> |
85 | 86 | /// <returns></returns> |
86 | | - public static IRegisterService UseSenparcGlobal(this IRegisterService registerService, bool autoScanExtensionCacheStrategies = false, Func<IList<IDomainExtensionCacheStrategy>> extensionCacheStrategiesFunc = null) |
87 | | - { |
88 | | - // Register extension cache strategies |
89 | | - CacheStrategyDomainWarehouse.AutoScanDomainCacheStrategy(autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc); |
90 | | - |
91 | | - return registerService; |
92 | | - } |
93 | | - |
94 | | - |
95 | | - |
96 | | -#if !NET462 |
97 | | - |
98 | | - /// <summary> |
99 | | - /// Start Senparc.CO2NET initialization parameter process |
100 | | - /// </summary> |
101 | | - /// <param name="senparcSetting">SenparcSetting object</param> |
102 | | - /// <param name="registerConfigure">RegisterService settings</param> |
103 | | - /// <param name="autoScanExtensionCacheStrategies">Whether to automatically scan global extension caches (will increase system startup time)</param> |
104 | | - /// <param name="extensionCacheStrategiesFunc"><para>Extension cache strategies that need to be manually registered</para> |
105 | | - /// <para>(LocalContainerCacheStrategy, RedisContainerCacheStrategy, MemcacheContainerCacheStrategy are already automatically registered),</para> |
106 | | - /// <para>If set to null (note: not delegate returning null, but the entire delegate parameter is null), it will automatically use reflection to scan all possible extension cache strategies</para></param> |
| 87 | + public static IRegisterService UseSenparcGlobal(this IRegisterService registerService, bool autoScanExtensionCacheStrategies = false, Func<IList<IDomainExtensionCacheStrategy>> extensionCacheStrategiesFunc = null) |
| 88 | + { |
| 89 | + // Register extension cache strategies |
| 90 | + CacheStrategyDomainWarehouse.AutoScanDomainCacheStrategy(autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc); |
| 91 | + |
| 92 | + return registerService; |
| 93 | + } |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +#if !NET462 |
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// Start Senparc.CO2NET initialization parameter process |
| 101 | + /// </summary> |
| 102 | + /// <param name="senparcSetting">SenparcSetting object</param> |
| 103 | + /// <param name="registerConfigure">RegisterService settings</param> |
| 104 | + /// <param name="autoScanExtensionCacheStrategies">Whether to automatically scan global extension caches (will increase system startup time)</param> |
| 105 | + /// <param name="extensionCacheStrategiesFunc"><para>Extension cache strategies that need to be manually registered</para> |
| 106 | + /// <para>(LocalContainerCacheStrategy, RedisContainerCacheStrategy, MemcacheContainerCacheStrategy are already automatically registered),</para> |
| 107 | + /// <para>If set to null (note: not delegate returning null, but the entire delegate parameter is null), it will automatically use reflection to scan all possible extension cache strategies</para></param> |
107 | 108 | /// <returns></returns> |
108 | | - public static IRegisterService UseSenparcGlobal( |
109 | | - SenparcSetting senparcSetting, |
110 | | - Action<RegisterService> registerConfigure, |
111 | | - bool autoScanExtensionCacheStrategies = false, |
112 | | - Func<IList<IDomainExtensionCacheStrategy>> extensionCacheStrategiesFunc = null) |
113 | | - { |
114 | | - // Initialize global RegisterService object and store SenparcSetting information |
115 | | - var register = RegisterService.Start(senparcSetting); |
116 | | - RegisterService.Object = register; |
117 | | - |
118 | | - registerConfigure?.Invoke(register); |
119 | | - |
120 | | - return register.UseSenparcGlobal(autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc); |
121 | | - } |
122 | | - |
123 | | - |
124 | | - /// <summary> |
125 | | - /// Start Senparc.CO2NET initialization parameter process |
126 | | - /// </summary> |
127 | | - /// <param name="app">configuration source</param> |
128 | | - /// <param name="senparcSetting">SenparcSetting object</param> |
129 | | - /// <param name="registerConfigure">RegisterService settings</param> |
130 | | - /// <param name="autoScanExtensionCacheStrategies">Whether to automatically scan global extension caches (will increase system startup time)</param> |
131 | | - /// <param name="extensionCacheStrategiesFunc"><para>Extension cache strategies that need to be manually registered</para> |
132 | | - /// <para>(LocalContainerCacheStrategy, RedisContainerCacheStrategy, MemcacheContainerCacheStrategy are already automatically registered),</para> |
133 | | - /// <para>If set to null (note: not delegate returning null, but the entire delegate parameter is null), it will automatically use reflection to scan all possible extension cache strategies</para></param> |
| 109 | + public static IRegisterService UseSenparcGlobal( |
| 110 | + SenparcSetting senparcSetting, |
| 111 | + Action<RegisterService> registerConfigure, |
| 112 | + bool autoScanExtensionCacheStrategies = false, |
| 113 | + Func<IList<IDomainExtensionCacheStrategy>> extensionCacheStrategiesFunc = null) |
| 114 | + { |
| 115 | + // Initialize global RegisterService object and store SenparcSetting information |
| 116 | + var register = RegisterService.Start(senparcSetting); |
| 117 | + RegisterService.Object = register; |
| 118 | + |
| 119 | + registerConfigure?.Invoke(register); |
| 120 | + |
| 121 | + return register.UseSenparcGlobal(autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc); |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + /// <summary> |
| 126 | + /// Start Senparc.CO2NET initialization parameter process |
| 127 | + /// </summary> |
| 128 | + /// <param name="app">configuration source</param> |
| 129 | + /// <param name="senparcSetting">SenparcSetting object</param> |
| 130 | + /// <param name="registerConfigure">RegisterService settings</param> |
| 131 | + /// <param name="autoScanExtensionCacheStrategies">Whether to automatically scan global extension caches (will increase system startup time)</param> |
| 132 | + /// <param name="extensionCacheStrategiesFunc"><para>Extension cache strategies that need to be manually registered</para> |
| 133 | + /// <para>(LocalContainerCacheStrategy, RedisContainerCacheStrategy, MemcacheContainerCacheStrategy are already automatically registered),</para> |
| 134 | + /// <para>If set to null (note: not delegate returning null, but the entire delegate parameter is null), it will automatically use reflection to scan all possible extension cache strategies</para></param> |
134 | 135 | /// <returns></returns> |
135 | | - public static (IConfigurationRoot app, IRegisterService registerService) UseSenparcGlobal( |
136 | | - this IConfigurationRoot app, |
137 | | - SenparcSetting senparcSetting, |
138 | | - Action<RegisterService> registerConfigure, |
139 | | - bool autoScanExtensionCacheStrategies = false, |
140 | | - Func<IList<IDomainExtensionCacheStrategy>> extensionCacheStrategiesFunc = null) |
141 | | - { |
142 | | - return (app, UseSenparcGlobal(senparcSetting, registerConfigure, autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc)); |
143 | | - } |
144 | | -#endif |
145 | | - } |
146 | | -} |
| 136 | + public static (IConfigurationRoot app, IRegisterService registerService) UseSenparcGlobal( |
| 137 | + this IConfigurationRoot app, |
| 138 | + SenparcSetting senparcSetting, |
| 139 | + Action<RegisterService> registerConfigure, |
| 140 | + bool autoScanExtensionCacheStrategies = false, |
| 141 | + Func<IList<IDomainExtensionCacheStrategy>> extensionCacheStrategiesFunc = null) |
| 142 | + { |
| 143 | + return (app, UseSenparcGlobal(senparcSetting, registerConfigure, autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc)); |
| 144 | + } |
| 145 | +#endif |
| 146 | + } |
| 147 | +} |
0 commit comments