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.
#r "nuget: Tedd.ModuleLoader, 1.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tedd.ModuleLoader as a Cake Addin
#addin nuget:?package=Tedd.ModuleLoader&version=1.0.1

// Install Tedd.ModuleLoader as a Cake Tool
#tool nuget:?package=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<T>.

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(".").CreateInstances<ICalcModule>();

or if ctor requires arguments

var modules = AssemblyLoader.LoadDirectory(".").CreateInstances<ICtorArgsModule>(new object[] { "Test", 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(".").GetTypeInfoOf<ICalcModule>();

Create instance from TypeInfo

types.CreateInstances<ICalcModule>()

Dependency injection

services.AddScoped<ICalcModule>(AssemblyLoader.LoadDirectory("."));

or

services.AddTransient<ICalcModule>(AssemblyLoader.LoadDirectory("."));

or

services.AddSingleton<ICalcModule>(AssemblyLoader.LoadDirectory("."));

Filter what files to load

  • .Net Directory.GetFiles filter:
    AssemblyLoader.LoadDirectory(".", "*.Module1.dll")
  • Regex filter, case insensitive: AssemblyLoader.LoadDirectory(".", @"Test.*Module1\.dll$", false)
  • Regex filter, case sensitive: AssemblyLoader.LoadDirectory(".", @"Test.*Module1\.dll$", 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<T>.

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(".").CreateInstances<ICalcModule>();

or if ctor requires arguments

var modules = AssemblyLoader.LoadDirectory(".").CreateInstances<ICtorArgsModule>(new object[] { "Test", 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(".").GetTypeInfoOf<ICalcModule>();

Create instance from TypeInfo

types.CreateInstances<ICalcModule>()

Dependency injection

services.AddScoped<ICalcModule>(AssemblyLoader.LoadDirectory("."));

or

services.AddTransient<ICalcModule>(AssemblyLoader.LoadDirectory("."));

or

services.AddSingleton<ICalcModule>(AssemblyLoader.LoadDirectory("."));

Filter what files to load

  • .Net Directory.GetFiles filter:
    AssemblyLoader.LoadDirectory(".", "*.Module1.dll")
  • Regex filter, case insensitive: AssemblyLoader.LoadDirectory(".", @"Test.*Module1\.dll$", false)
  • Regex filter, case sensitive: AssemblyLoader.LoadDirectory(".", @"Test.*Module1\.dll$", 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>

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 266 5/14/2019
1.0.0 237 5/14/2019