Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Move UseMiddleware to Http.Abstractions #311

Closed
davidfowl opened this issue May 20, 2015 · 4 comments
Closed

Move UseMiddleware to Http.Abstractions #311

davidfowl opened this issue May 20, 2015 · 4 comments

Comments

@davidfowl
Copy link
Member

It's a pretty core overload to creating middleware and it would be great if we could move it to the main assembly. We want to make a middleware template in VS that does the following:

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;

namespace ProjectNs
{
    public static class Middleware1Extensions
    {
        public IApplicationBuilder UseMiddleware1(IApplicationBuilder app)
        {
            app.UseMiddleware<Middleware1>();
        }
    }

    public class Middleware1
    {
        private readonly RequestDelegate _next;
        public Middleware1(RequestDelegate next)
        {
            _next = next;
        }

        public Task Invoke(HttpContext context)
        {
             return _next(context);
        }
    }
}

Item templates can't add packages so we need to move the UseMiddleware to the core assembly. I'm not comfortable with making our core Http types rely on DI so maybe we make that thing shared source (just a piece of ActivatorUtilities we need). The other option is to change the template but we want to encourage DI by default. For sake of options:

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;

namespace ProjectNs
{
    public static class Middleware1Extensions
    {
        public IApplicationBuilder UseMiddleware1(IApplicationBuilder app)
        {
            app.Use(next => new Middleware1(next).Invoke);
        }
    }

    public class Middleware1
    {
        private readonly RequestDelegate _next;
        public Middleware1(RequestDelegate next)
        {
            _next = next;
        }

        public Task Invoke(HttpContext context)
        {
             return _next(context);
        }
    }
}
@davidfowl
Copy link
Member Author

/cc @Tratcher @DamianEdwards @muratg

We want to do this for beta5 so we can add the item template to VS.

@Tratcher Tratcher self-assigned this May 20, 2015
@Tratcher Tratcher added this to the 1.0.0-beta5 milestone May 20, 2015
@Tratcher
Copy link
Member

The new dependency would be on DI.Abstractions, not DI, so that's not terrible.

@davidfowl
Copy link
Member Author

Thats pretty terrible.

@Tratcher
Copy link
Member

@rustd

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants