|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Diagnostics; |
| 4 | +using System.IdentityModel.Tokens.Jwt; |
4 | 5 | using System.IO; |
5 | 6 | using System.Linq; |
6 | 7 | using System.Net; |
|
11 | 12 | using Microsoft.AspNetCore.Authentication.Cookies; |
12 | 13 | using Microsoft.AspNetCore.Authentication.JwtBearer; |
13 | 14 | using Microsoft.AspNetCore.Authentication.OAuth; |
14 | | -using Microsoft.AspNetCore.Identity; |
15 | 15 | using Microsoft.AspNetCore.Http; |
| 16 | +using Microsoft.AspNetCore.Identity; |
16 | 17 | using Microsoft.AspNetCore.Mvc.ApplicationParts; |
17 | | -using Microsoft.Extensions.Localization; |
18 | 18 | using Microsoft.EntityFrameworkCore; |
19 | 19 | using Microsoft.Extensions.Configuration; |
20 | 20 | using Microsoft.Extensions.DependencyInjection; |
| 21 | +using Microsoft.Extensions.Localization; |
21 | 22 | using SimplCommerce.Infrastructure; |
22 | 23 | using SimplCommerce.Infrastructure.Modules; |
23 | 24 | using SimplCommerce.Infrastructure.Web.ModelBinders; |
24 | 25 | using SimplCommerce.Module.Core.Data; |
25 | 26 | using SimplCommerce.Module.Core.Extensions; |
26 | 27 | using SimplCommerce.Module.Core.Models; |
27 | 28 | using SimplCommerce.WebHost.IdentityServer; |
28 | | -using System.IdentityModel.Tokens.Jwt; |
29 | 29 |
|
30 | 30 | namespace SimplCommerce.WebHost.Extensions |
31 | 31 | { |
@@ -226,6 +226,29 @@ public static IServiceCollection AddCustomizedDataStore(this IServiceCollection |
226 | 226 | return services; |
227 | 227 | } |
228 | 228 |
|
| 229 | + /// <summary> |
| 230 | + /// Discovers and configures all modules in the application by finding and initializing their module initializers. |
| 231 | + /// </summary> |
| 232 | + /// <param name="services">The <see cref="IServiceCollection"/> to add module services to.</param> |
| 233 | + /// <returns>The same service collection so that multiple calls can be chained.</returns> |
| 234 | + public static IServiceCollection ConfigureModules(this IServiceCollection services) |
| 235 | + { |
| 236 | + foreach (var module in GlobalConfiguration.Modules) |
| 237 | + { |
| 238 | + var moduleInitializerType = module.Assembly.GetTypes() |
| 239 | + .FirstOrDefault(t => typeof(IModuleInitializer).IsAssignableFrom(t)); |
| 240 | + |
| 241 | + if (moduleInitializerType != null && moduleInitializerType != typeof(IModuleInitializer)) |
| 242 | + { |
| 243 | + var moduleInitializer = (IModuleInitializer)Activator.CreateInstance(moduleInitializerType); |
| 244 | + services.AddSingleton(typeof(IModuleInitializer), moduleInitializer); |
| 245 | + moduleInitializer.ConfigureServices(services); |
| 246 | + } |
| 247 | + } |
| 248 | + |
| 249 | + return services; |
| 250 | + } |
| 251 | + |
229 | 252 | private static void TryLoadModuleAssembly(string moduleFolderPath, ModuleInfo module) |
230 | 253 | { |
231 | 254 | const string binariesFolderName = "bin"; |
|
0 commit comments