From e25605696319a01073c32f525036a973a4c1eda4 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Mon, 18 Nov 2019 11:12:28 -0500 Subject: [PATCH] fixed issue #175 when running in Wasm --- Oqtane.Server/Startup.cs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index a824dfbc..1e661ed5 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -79,10 +79,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(); @@ -305,6 +305,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(); @@ -358,11 +361,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(); @@ -439,6 +437,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" }); @@ -452,7 +465,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(); @@ -463,7 +476,7 @@ namespace Oqtane.Server } // install any modules or themes - InstallationManager.InstallPackages("Modules,Themes"); + InstallationManager.InstallPackages("Modules,Themes", false); app.UseClientSideBlazorFiles(); app.UseStaticFiles();