add defensive logic to Oqtane.Maui for loading modules which have not declared all dependencies

This commit is contained in:
Shaun Walker 2023-03-14 20:37:42 -04:00
parent 0a30f2b7e8
commit 04c0b9d37d
2 changed files with 23 additions and 9 deletions

View File

@ -212,23 +212,37 @@ public static class MauiProgram
private static void RegisterModuleServices(Assembly assembly, IServiceCollection services) private static void RegisterModuleServices(Assembly assembly, IServiceCollection services)
{ {
// dynamically register module scoped services // dynamically register module scoped services
var implementationTypes = assembly.GetInterfaces<IService>(); try
foreach (var implementationType in implementationTypes)
{ {
if (implementationType.AssemblyQualifiedName != null) var implementationTypes = assembly.GetInterfaces<IService>();
foreach (var implementationType in implementationTypes)
{ {
var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}")); if (implementationType.AssemblyQualifiedName != null)
services.AddScoped(serviceType ?? implementationType, implementationType); {
var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}"));
services.AddScoped(serviceType ?? implementationType, implementationType);
}
} }
} }
catch
{
// could not interrogate assembly - likely missing dependencies
}
} }
private static void RegisterClientStartups(Assembly assembly, IServiceCollection services) private static void RegisterClientStartups(Assembly assembly, IServiceCollection services)
{ {
var startUps = assembly.GetInstances<IClientStartup>(); try
foreach (var startup in startUps)
{ {
startup.ConfigureServices(services); var startUps = assembly.GetInstances<IClientStartup>();
foreach (var startup in startUps)
{
startup.ConfigureServices(services);
}
}
catch
{
// could not interrogate assembly - likely missing dependencies
} }
} }
} }

View File

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Razor"> <Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks> <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET --> <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks> -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> --> <!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<Version>3.4.1</Version> <Version>3.4.1</Version>