cofoundry icon indicating copy to clipboard operation
cofoundry copied to clipboard

Simpler Customization of Startup

Open HeyJoel opened this issue 4 years ago • 0 comments

At the moment if you want to customize the startup process you need to create an implementation of one of the objects that gets used in the startup pipeline e.g. IRouteRegistration or IStartupTask. This is great for plugins and modular code, but we lack a simple way to modify the pipeline from your Startup.cs.

One example is configuring routing endpoints, where to enable RazorPages you currently need a separate class:

public class ExampleRouteRegistration : IRouteRegistration
{
    public void RegisterRoutes(IEndpointRouteBuilder routeBuilder)
    {
        routeBuilder.MapRazorPages();
    }
}

public class Startup
{
    public IConfiguration Configuration { get; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddRazorPages()
            .AddCofoundry(Configuration);
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseCofoundry();
    }
}

It would be nice in a simple scenario to be abel to do something like this, which runs at a default point in the startup pipeline:

public class Startup
{
    public IConfiguration Configuration { get; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddRazorPages()
            .AddCofoundry(Configuration);
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseCofoundry(c =>
        {
            c.AppBuilder.MapRazorPages();
        });
    }
}

HeyJoel avatar Jun 01 '20 09:06 HeyJoel