Tedd.ModuleLoader 1.0.1

Easy dynamic loading of assemblies in .Net Core. Integrates with ASP.Net Core Dependency Injection. Load modules and find implementations of interfaces.

Install-Package Tedd.ModuleLoader -Version 1.0.1
dotnet add package Tedd.ModuleLoader --version 1.0.1
<PackageReference Include="Tedd.ModuleLoader" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tedd.ModuleLoader --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Dependency

References Microsoft.Extensions.DependencyInjection.Abstractions for AddScoped<T>, AddTransient<T> and AddSingleton<T>.
References Microsoft.Extensions.Hosting.Abstractions to reference IHostedService in AddHostedService&lt;T&gt;.

Examples

Create instances directly

Load all files in directory (with default filter of *.dll). Create an instance of all classes that inherit from ICalcModule.

var modules = AssemblyLoader.LoadDirectory(&quot;.&quot;).CreateInstances&lt;ICalcModule&gt;();

or if ctor requires arguments

var modules = AssemblyLoader.LoadDirectory(&quot;.&quot;).CreateInstances&lt;ICtorArgsModule&gt;(new object[] { &quot;Test&quot;, 123 });

Get TypeInfo

Load all files in directory (with default filter of *.dll). Find TypeInfo for all classes that inherit from ICalcModule.

var types = AssemblyLoader.LoadDirectory(&quot;.&quot;).GetTypeInfoOf&lt;ICalcModule&gt;();

Create instance from TypeInfo

types.CreateInstances&lt;ICalcModule&gt;()

Dependency injection

services.AddScoped&lt;ICalcModule&gt;(AssemblyLoader.LoadDirectory(&quot;.&quot;));

or

services.AddTransient&lt;ICalcModule&gt;(AssemblyLoader.LoadDirectory(&quot;.&quot;));

or

services.AddSingleton&lt;ICalcModule&gt;(AssemblyLoader.LoadDirectory(&quot;.&quot;));

Filter what files to load

  • .Net Directory.GetFiles filter:
    AssemblyLoader.LoadDirectory(&quot;.&quot;, &quot;*.Module1.dll&quot;)
  • Regex filter, case insensitive: AssemblyLoader.LoadDirectory(&quot;.&quot;, @&quot;Test.*Module1\.dll$&quot;, false)
  • Regex filter, case sensitive: AssemblyLoader.LoadDirectory(&quot;.&quot;, @&quot;Test.*Module1\.dll$&quot;, true)
  • Custom list of files: AssemblyLoader.LoadDirectory(files) where files is an IEnumerable (i.e. List, Array or LINQ result) of string.

Dependency

References Microsoft.Extensions.DependencyInjection.Abstractions for AddScoped<T>, AddTransient<T> and AddSingleton<T>.
References Microsoft.Extensions.Hosting.Abstractions to reference IHostedService in AddHostedService&lt;T&gt;.

Examples

Create instances directly

Load all files in directory (with default filter of *.dll). Create an instance of all classes that inherit from ICalcModule.

var modules = AssemblyLoader.LoadDirectory(&quot;.&quot;).CreateInstances&lt;ICalcModule&gt;();

or if ctor requires arguments

var modules = AssemblyLoader.LoadDirectory(&quot;.&quot;).CreateInstances&lt;ICtorArgsModule&gt;(new object[] { &quot;Test&quot;, 123 });

Get TypeInfo

Load all files in directory (with default filter of *.dll). Find TypeInfo for all classes that inherit from ICalcModule.

var types = AssemblyLoader.LoadDirectory(&quot;.&quot;).GetTypeInfoOf&lt;ICalcModule&gt;();

Create instance from TypeInfo

types.CreateInstances&lt;ICalcModule&gt;()

Dependency injection

services.AddScoped&lt;ICalcModule&gt;(AssemblyLoader.LoadDirectory(&quot;.&quot;));

or

services.AddTransient&lt;ICalcModule&gt;(AssemblyLoader.LoadDirectory(&quot;.&quot;));

or

services.AddSingleton&lt;ICalcModule&gt;(AssemblyLoader.LoadDirectory(&quot;.&quot;));

Filter what files to load

  • .Net Directory.GetFiles filter:
    AssemblyLoader.LoadDirectory(&quot;.&quot;, &quot;*.Module1.dll&quot;)
  • Regex filter, case insensitive: AssemblyLoader.LoadDirectory(&quot;.&quot;, @&quot;Test.*Module1\.dll$&quot;, false)
  • Regex filter, case sensitive: AssemblyLoader.LoadDirectory(&quot;.&quot;, @&quot;Test.*Module1\.dll$&quot;, true)
  • Custom list of files: AssemblyLoader.LoadDirectory(files) where files is an IEnumerable (i.e. List, Array or LINQ result) of string.

Release Notes

Added AddHostedService<T>

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 107 5/14/2019
1.0.0 92 5/14/2019