This repository was archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 191
This repository was archived by the owner on Nov 20, 2018. It is now read-only.
Move UseMiddleware to Http.Abstractions #311
Copy link
Copy link
Closed
Description
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);
}
}
}