X39.Hosting.Modularization.TemplatePackage
0.0.1
See the version list below for details.
dotnet new install X39.Hosting.Modularization.TemplatePackage::0.0.1
Quickstart
A simple setup looks as follows:
// Program.cs
var hostBuilder = Host.CreateDefaultBuilder(args);
hostBuilder.UseModularization(Path.GetFullPath("Modules"));
hostBuilder.ConfigureServices(collection => collection.AddHostedService<Worker>());
var host = hostBuilder.Build();
host.Run();
// Worker.cs
public class Worker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _moduleLoader.LoadAllAsync(stoppingToken);
}
}
Please do note that plugin directories are provided once at start.
Features
module.json
configuration file to provide information about the module:The module configuration allows to declare things like a guid for the module to uniquely identify them over successive runs, offers a way to declare a module license, list the licenses used in the module and much more.
Automatic dependency resolution:
A module can depend on another module by providing a dependency in the
module.json
file.Module unloading:
Unloading a module is as simple as calling
Unload()
on theModuleContext
. Please do note that normal unloading rules apply - as in: even having a type reference is enough to prevent proper unloading of the assembly. To debug theese, checking which objects are still loaded (Rider → Memory Tab; Visual Studio → Take .net object snapshot with diagnostics tool; for both check the types that live in the loaded module) can be a useful tool in your tookit. A common issue eg. is caching that prevents the types from being properly released by the garbage collector.Clear entry point:
Every module must, for it to properly function, implement the
IModuleMain
interface. This allows the module to work more or less like the normal ´void Main()` you know and love.Dependency Injection for modules:
Every main module class is constructed by dependency injection, using
IServiceProvider
. It even supports nullable references so you do not have to ever worry about invalid "not null" references ever again.
ToDo's
- Add version checks to dependency resolution
- Document and style all exceptions properly
- Offer a way to "include" types to prevent type duplicates
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.0.0.35 | 97 | 12/14/2024 |
2.0.0.34 | 109 | 9/28/2024 |
1.0.0.33 | 120 | 9/16/2024 |
1.0.0.32-da89c1738d81a83aaf... | 100 | 9/16/2024 |
0.0.1.27 | 590 | 9/21/2023 |
0.0.1.26 | 370 | 5/4/2023 |
0.0.1.24 | 651 | 10/16/2022 |
0.0.1.23 | 357 | 10/16/2022 |
0.0.1.22 | 358 | 10/16/2022 |
0.0.1.21 | 355 | 10/15/2022 |
0.0.1.20 | 356 | 10/15/2022 |
0.0.1.19 | 367 | 10/15/2022 |
0.0.1.18 | 387 | 10/1/2022 |
0.0.1.17 | 356 | 10/1/2022 |
0.0.1.16 | 350 | 10/1/2022 |
0.0.1.15 | 416 | 9/24/2022 |
0.0.1.14 | 410 | 9/21/2022 |
0.0.1.13 | 367 | 9/20/2022 |
0.0.1.12 | 362 | 9/20/2022 |
0.0.1.11 | 393 | 9/15/2022 |
0.0.1.10 | 438 | 9/14/2022 |
0.0.1.9 | 439 | 9/6/2022 |
0.0.1.8 | 403 | 9/5/2022 |
0.0.1.7 | 398 | 9/2/2022 |
0.0.1 | 431 | 9/1/2022 |