Coder Social home page Coder Social logo

x39 / x39.hosting.modularization Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 189 KB

WIP plugin system for dotnet with DI support. As of now this is not functional or tested

C# 99.22% Batchfile 0.78%
csharp dependency-injection dotnet hostbuilder module-system plugin-system

x39.hosting.modularization's Introduction

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. Additionally, every module also can offer services to other modules depending on it.

x39.hosting.modularization's People

Contributors

dependabot[bot] avatar x39 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.