diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index cfe88fa7..bea44bd2 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -83,10 +83,10 @@ namespace Oqtane.Server options.AddPolicy("ViewModule", policy => policy.Requirements.Add(new PermissionRequirement("Module", "View"))); options.AddPolicy("EditModule", policy => policy.Requirements.Add(new PermissionRequirement("Module", "Edit"))); }); - services.AddScoped(); // register scoped core services services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -309,6 +309,9 @@ namespace Oqtane.Server options.AddPolicy("ViewModule", policy => policy.Requirements.Add(new PermissionRequirement("Module", "View"))); options.AddPolicy("EditModule", policy => policy.Requirements.Add(new PermissionRequirement("Module", "Edit"))); }); + + // register scoped core services + services.AddScoped(); services.AddScoped(); services.AddSingleton(); @@ -362,11 +365,6 @@ namespace Oqtane.Server services.AddSingleton(Configuration); services.AddSingleton(); - // install any modules or themes - ServiceProvider sp = services.BuildServiceProvider(); - var InstallationManager = sp.GetRequiredService(); - InstallationManager.InstallPackages("Modules,Themes"); - // register transient scoped core services services.AddTransient(); services.AddTransient(); @@ -443,6 +441,21 @@ namespace Oqtane.Server } } + // dynamically register hosted services + foreach (Assembly assembly in assemblies) + { + Type[] servicetypes = assembly.GetTypes() + .Where(item => item.GetInterfaces().Contains(typeof(IHostedService))) + .ToArray(); + foreach (Type servicetype in servicetypes) + { + if (servicetype.Name != "HostedServiceBase") + { + services.AddSingleton(typeof(IHostedService), servicetype); + } + } + } + services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Oqtane", Version = "v1" }); @@ -456,7 +469,7 @@ namespace Oqtane.Server } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IInstallationManager InstallationManager) { app.UseResponseCompression(); @@ -467,7 +480,7 @@ namespace Oqtane.Server } // install any modules or themes - InstallationManager.InstallPackages("Modules,Themes"); + InstallationManager.InstallPackages("Modules,Themes", false); app.UseClientSideBlazorFiles(); app.UseStaticFiles();