Tedd.ModuleLoader
1.0.1
dotnet add package Tedd.ModuleLoader --version 1.0.1
NuGet\Install-Package Tedd.ModuleLoader -Version 1.0.1
<PackageReference Include="Tedd.ModuleLoader" Version="1.0.1" />
paket add Tedd.ModuleLoader --version 1.0.1
#r "nuget: Tedd.ModuleLoader, 1.0.1"
// 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
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.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 is compatible. netcoreapp2.2 is compatible. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.0
-
.NETCoreApp 2.1
-
.NETCoreApp 2.2
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added AddHostedService<T>