How to Inject Multiple Startup Config Files in Net Core MVC modular plugin app?

306 Views Asked by At

please read below scenario:

in a plugin based application built with Plugin Library DotnetCorePlugins where a single host application serves with micro plugins everything is working well and good. But i need to do startup service registration from these plugins as needed so say plugin1 introduces a middleware, plugin2 a pipeline, plugin3 some mediatr service etc...

i dig into OrchardCore & Orchard does that by using a StartupBase class but i am unable to find out how they are doing it [if my assumption is correct orchard uses msbuild for plugins unlike loadcontext of this library].

my requirements and structure is different from orchard, but i like the idea of having a StartupBase class where i can define configuration order and service init order and it gets called on main host app initilization can someone guide me to the right way to do this, i am ok with even minimal flow steps as long as its clear to understand. the Plugin Startup files must handle the defined order in host and be injected into main startup bus.

1

There are 1 best solutions below

1
Matt On

If I am understanding you correctly... you can register many customizations in Startup like this...

Create a ServiceExtensions Class

using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;

namespace Your.Custom.Namespace
{
    public static class ServiceExtensions
    {
        public static void ConfigureMiddleware(this IServiceCollection services, 
                                                      IConfiguration config)
        {
            // custom stuff
        }
        public static void ConfigurePipeline(this IServiceCollection services, 
                                                      IConfiguration config)
        {
            // custom stuff
        }
        public static void ConfigureMedia(this IServiceCollection services, 
                                                      IConfiguration config)
        {
            // custom stuff
        }
    }
}

Then in StartUp, call those methods...

public void ConfigureServices(IServiceCollection services)
{
   ... other configs
   services.ConfigureMiddleware(Configuration);
   services.ConfigurePipeline(Configuration);
   services.ConfigureMedia(Configuration);
}