Skip to content

Commit

Permalink
Revert "Fix bug on DLL resolve for plugins (#380)"
Browse files Browse the repository at this point in the history
This reverts commit 7725cc3.
  • Loading branch information
antoineatstariongroup authored Jan 24, 2025
1 parent 7725cc3 commit 882cd23
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CodeQuality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
run: dotnet-coverage collect --output CoverageResults/integration.test.report.coverage.xml --output-format cobertura --session-id integrationtestsession "dotnet run --project CometServer/CometServer.csproj -c Debug" &

- name: Wait for API to start
run: sleep 60 # Adjust as necessary to ensure the API is up
run: sleep 45 # Adjust as necessary to ensure the API is up

- name: Checkout Integration Test Suite
uses: actions/checkout@v4
Expand Down
38 changes: 3 additions & 35 deletions CometServer/Authentication/AuthenticationPluginInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ namespace CometServer.Authentication
/// <summary>
/// The injector loads up authenticator plugins.
/// </summary>
public class AuthenticationPluginInjector : IAuthenticationPluginInjector, IDisposable
public class AuthenticationPluginInjector : IAuthenticationPluginInjector
{
/// <summary>
/// A collection of <see cref="Assembly" /> that has been discovered
/// </summary>
private List<Assembly> discoveredAssemblies = new List<Assembly>();

/// <summary>
/// The name of the folder where all authentication modules reside.
/// </summary>
Expand All @@ -64,7 +59,6 @@ public class AuthenticationPluginInjector : IAuthenticationPluginInjector, IDisp
public AuthenticationPluginInjector(ILogger<AuthenticationPluginInjector> logger)
{
this.logger = logger;
AppDomain.CurrentDomain.AssemblyResolve += this.OnAssemblyResolve;

this.Plugins = this.LoadPlugins();

Expand Down Expand Up @@ -109,7 +103,6 @@ private static string[] GetFolders()
/// <returns>The <see cref="List{T}"/> of <see cref="IAuthenticatorPlugin"/> modules</returns>
private ReadOnlyCollection<IAuthenticatorPlugin> LoadPlugins()
{
this.discoveredAssemblies.Clear();
var sw = Stopwatch.StartNew();

var result = new List<IAuthenticatorPlugin>();
Expand All @@ -123,20 +116,15 @@ private ReadOnlyCollection<IAuthenticatorPlugin> LoadPlugins()
// load all assemblies types encountered in the plugin folders that implement the IAuthenticatorPlugin interface
foreach (var pluginFolder in pluginFolders)
{
var assemblies = new DirectoryInfo(pluginFolder).GetFiles().Where(file => file.Extension == ".dll")
.Select(file => Assembly.LoadFile(file.FullName))
.ToList();

foreach (var assembly in assemblies)
foreach (var assembly in new DirectoryInfo(pluginFolder).GetFiles().Where(file => file.Extension == ".dll")
.Select(file => Assembly.LoadFile(file.FullName)))
{
builder.RegisterAssemblyTypes(assembly)
.Where(x => typeof(IAuthenticatorPlugin).IsAssignableFrom(x))
.AsImplementedInterfaces()
.PropertiesAutowired()
.SingleInstance();
}

this.discoveredAssemblies.AddRange(assemblies);
}

var container = builder.Build();
Expand All @@ -150,25 +138,5 @@ private ReadOnlyCollection<IAuthenticatorPlugin> LoadPlugins()

return result.AsReadOnly();
}

/// <summary>
/// Helps resolving assemblies that may be required for loaded plugins
/// </summary>
/// <param name="sender">The sender object</param>
/// <param name="args">The <see cref="ResolveEventArgs"/></param>
/// <returns>The resolved assemblies, if found</returns>
private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
return this.discoveredAssemblies.FirstOrDefault(x => x.FullName == args.Name);
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
AppDomain.CurrentDomain.AssemblyResolve -= this.OnAssemblyResolve;
}
}
}

0 comments on commit 882cd23

Please sign in to comment.