Skip to content

Commit

Permalink
Improved MFLC
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed May 2, 2024
1 parent 7ab676e commit fe69ece
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/Piral.Blazor.Orchestrator/MicrofrontendLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,35 @@ namespace Piral.Blazor.Orchestrator;

internal class MicrofrontendLoadContext(string name) : AssemblyLoadContext(name, true)
{
private readonly AssemblyLoadContext _root = All.FirstOrDefault(m => m.Name == "root") ?? Default;

protected override Assembly? Load(AssemblyName assemblyName)
{
//string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
//if (assemblyPath != null)
//{
// return LoadFromAssemblyPath(assemblyPath);
//}
//return null;
var existing = GetExisting(_root.Assemblies, assemblyName);

if (existing is not null)
{
return existing;
}

// root and default are different; we must be in an emulator
if (_root != Default)
{
// Let's see if we find this in the default ALC
var globalAssembly = GetExisting(Default.Assemblies, assemblyName);

if (globalAssembly is not null)
{
// In case we found it we return null to trigger the not found flow
return null;
}
}

return base.Load(assemblyName);
}

private static Assembly? GetExisting(IEnumerable<Assembly> assemblies, AssemblyName name)
{
return assemblies.FirstOrDefault(m => AssemblyName.ReferenceMatchesDefinition(m.GetName(), name));
}
}
1 change: 1 addition & 0 deletions src/Piral.Blazor.Sdk/Emulator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.Loader;
Expand Down

0 comments on commit fe69ece

Please sign in to comment.