add defensive logic to Oqtane.Maui for loading modules which have not declared all dependencies
This commit is contained in:
		| @ -212,23 +212,37 @@ public static class MauiProgram | ||||
|     private static void RegisterModuleServices(Assembly assembly, IServiceCollection services) | ||||
|     { | ||||
|         // dynamically register module scoped services | ||||
|         var implementationTypes = assembly.GetInterfaces<IService>(); | ||||
|         foreach (var implementationType in implementationTypes) | ||||
|         try | ||||
|         { | ||||
|             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}")); | ||||
|                 services.AddScoped(serviceType ?? implementationType, implementationType); | ||||
|                 if (implementationType.AssemblyQualifiedName != null) | ||||
|                 { | ||||
|                     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) | ||||
|     { | ||||
|         var startUps = assembly.GetInstances<IClientStartup>(); | ||||
|         foreach (var startup in startUps) | ||||
|         try | ||||
|         { | ||||
|             startup.ConfigureServices(services); | ||||
|             var startUps = assembly.GetInstances<IClientStartup>(); | ||||
|             foreach (var startup in startUps) | ||||
|             { | ||||
|                 startup.ConfigureServices(services); | ||||
|             } | ||||
|         } | ||||
|         catch | ||||
|         { | ||||
|             // could not interrogate assembly - likely missing dependencies | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1,9 +1,9 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk.Razor"> | ||||
|  | ||||
| 	<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> | ||||
| 		<!-- 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> --> | ||||
| 		<OutputType>Exe</OutputType> | ||||
|     <Version>3.4.1</Version> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker