X39.Hosting.Modularization 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package X39.Hosting.Modularization --version 0.0.1
NuGet\Install-Package X39.Hosting.Modularization -Version 0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="X39.Hosting.Modularization" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add X39.Hosting.Modularization --version 0.0.1
#r "nuget: X39.Hosting.Modularization, 0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install X39.Hosting.Modularization as a Cake Addin
#addin nuget:?package=X39.Hosting.Modularization&version=0.0.1

// Install X39.Hosting.Modularization as a Cake Tool
#tool nuget:?package=X39.Hosting.Modularization&version=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 the ModuleContext. 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
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.0.1.27 123 9/21/2023
0.0.1.26 138 5/4/2023
0.0.1.24 378 10/16/2022
0.0.1.23 328 10/16/2022
0.0.1.22 341 10/16/2022
0.0.1.21 343 10/15/2022
0.0.1.20 343 10/15/2022
0.0.1.19 358 10/15/2022
0.0.1.18 357 10/1/2022
0.0.1.17 336 10/1/2022
0.0.1.16 334 10/1/2022
0.0.1.15 355 9/24/2022
0.0.1.14 359 9/21/2022
0.0.1.13 339 9/20/2022
0.0.1.12 372 9/20/2022
0.0.1.11 360 9/15/2022
0.0.1.10 377 9/14/2022
0.0.1.9 380 9/6/2022
0.0.1.8 357 9/5/2022
0.0.1.7 376 9/2/2022
0.0.1.6 354 9/1/2022
0.0.1 377 9/1/2022