Skip to content

Auto-wire services? #2

@Antaris

Description

@Antaris

Hi,

Just discovered this whilst looking more at ICompileModule, seems you're ahead of me on an idea I've been pondering about auto-wiring services (ala MEF) for ASP.NET 5.

Generally, my idea is along the lines of:

[Transient]
public class Service : IService { }

And have an ICompileModule generate a class through precompilation, such like:

public static class AutoWireServicesExtensions
{
    public static void AutoWire(this IServicesCollection services)
    {
        services.AddTransient<IService, Service>();
    }
}

Which is then added to the compilation, perhaps then modifying the Startup class:

ConfigureServices(IServiceCollection services) 
{
    services.AutoWire();
}

I get the feeling you're actually further along with I am with this train of thought, so its interesting to know where you are at so far?

I think this sort of model could probably be extended to automatically wireup the pipeline middleware too,

[Middleware("MyMiddleware")]
public class MyMiddleware: IMiddleware
{
    public void RegisterMiddleware(IApplicationBuilder app)
    {
        app.UseMiddleware<...>();
    }
}

What I am looking to achieve, is pluggable modules using the ASP.NET 5 runtime model, and how we can create dynamic runtime pipelines, and automatic dependency wireup, without the developer having to do a whole load of bootstrapping work anytime they want to add a new module in.

It works ok for simple 1-project websites, but needs more consideration for more complex CMS-type projects.

What is your current thoughts on this, if you have any?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions