fixd issue where the ihostedservice registration was too wide resulting in an error Cannot instantiate implementation type 'Microsoft.Extensions.Hosting.BackgroundService' for service type 'Microsoft.Extensions.Hosting.IHostedService'

This commit is contained in:
Shaun Walker
2020-01-10 10:51:14 -05:00
parent 72f0eae441
commit d8d5e768b2
2 changed files with 7 additions and 3 deletions

View File

@ -42,7 +42,7 @@ namespace Oqtane.Controllers
[HttpGet("{id}")] [HttpGet("{id}")]
public Page Get(int id, string userid) public Page Get(int id, string userid)
{ {
if (userid == "") if (string.IsNullOrEmpty(userid))
{ {
return Pages.GetPage(id); return Pages.GetPage(id);
} }

View File

@ -79,7 +79,7 @@ namespace Microsoft.Extensions.DependencyInjection
var serviceTypes = assembly.GetTypes(hostedServiceType); var serviceTypes = assembly.GetTypes(hostedServiceType);
foreach (var serviceType in serviceTypes) foreach (var serviceType in serviceTypes)
{ {
if (serviceType.Name != nameof(HostedServiceBase)) if (serviceType.IsSubclassOf(typeof(HostedServiceBase)))
{ {
services.AddSingleton(hostedServiceType, serviceType); services.AddSingleton(hostedServiceType, serviceType);
} }
@ -103,7 +103,11 @@ namespace Microsoft.Extensions.DependencyInjection
{ {
// load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well ) // load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well )
assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(file.FullName))); assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(file.FullName)));
_oqtaneModuleAssemblies.Add(assembly); if (pattern == "Module")
{
// build a list of module assemblies
_oqtaneModuleAssemblies.Add(assembly);
}
} }
} }
} }