OWIN: Change interop extension methods.
This commit is contained in:
parent
caff1d3d68
commit
4a5de61cd1
|
|
@ -25,7 +25,6 @@
|
||||||
<Compile Include="OwinEnvironment.cs" />
|
<Compile Include="OwinEnvironment.cs" />
|
||||||
<Compile Include="OwinExtensions.cs" />
|
<Compile Include="OwinExtensions.cs" />
|
||||||
<Compile Include="OwinFeatureCollection.cs" />
|
<Compile Include="OwinFeatureCollection.cs" />
|
||||||
<Compile Include="OwinMiddlewareFactory.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VSToolsPath)\ProjectK\Microsoft.Web.ProjectK.targets" Condition="'$(VSToolsPath)' != ''" />
|
<Import Project="$(VSToolsPath)\ProjectK\Microsoft.Web.ProjectK.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -3,28 +3,86 @@ using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Abstractions;
|
using Microsoft.AspNet.Abstractions;
|
||||||
using Microsoft.AspNet.Owin;
|
using Microsoft.AspNet.Owin;
|
||||||
|
using Microsoft.AspNet.PipelineCore;
|
||||||
|
|
||||||
namespace Microsoft.AspNet
|
namespace Microsoft.AspNet
|
||||||
{
|
{
|
||||||
using AppFunc = Func<IDictionary<string, object>, Task>;
|
using AppFunc = Func<IDictionary<string, object>, Task>;
|
||||||
|
using CreateMiddleware = Func<
|
||||||
|
Func<IDictionary<string, object>, Task>,
|
||||||
|
Func<IDictionary<string, object>, Task>
|
||||||
|
>;
|
||||||
|
using AddMiddleware = Action<Func<
|
||||||
|
Func<IDictionary<string, object>, Task>,
|
||||||
|
Func<IDictionary<string, object>, Task>
|
||||||
|
>>;
|
||||||
|
|
||||||
public static class OwinExtensions
|
public static class OwinExtensions
|
||||||
{
|
{
|
||||||
public static IBuilder UseOwinMiddleware(this IBuilder builder, Func<AppFunc, AppFunc> middleware)
|
public static AddMiddleware UseOwin(this IBuilder builder)
|
||||||
{
|
{
|
||||||
Func<RequestDelegate, RequestDelegate> middleware1 = next1 =>
|
return middleware =>
|
||||||
{
|
{
|
||||||
AppFunc exitMiddlware = env =>
|
Func<RequestDelegate, RequestDelegate> middleware1 = next1 =>
|
||||||
{
|
{
|
||||||
return next1((HttpContext)env[typeof(HttpContext).FullName]);
|
AppFunc exitMiddlware = env =>
|
||||||
|
{
|
||||||
|
return next1((HttpContext)env[typeof(HttpContext).FullName]);
|
||||||
|
};
|
||||||
|
var app = middleware(exitMiddlware);
|
||||||
|
return httpContext =>
|
||||||
|
{
|
||||||
|
return app.Invoke(new OwinEnvironment(httpContext));
|
||||||
|
};
|
||||||
};
|
};
|
||||||
var app = middleware(exitMiddlware);
|
builder.Use(middleware1);
|
||||||
return httpContext =>
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IBuilder UseOwin(this IBuilder builder, Action<AddMiddleware> pipeline)
|
||||||
|
{
|
||||||
|
pipeline(builder.UseOwin());
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IBuilder UseBuilder(this AddMiddleware app)
|
||||||
|
{
|
||||||
|
var builder = new Builder(serviceProvider: null);
|
||||||
|
|
||||||
|
CreateMiddleware middleware = CreateMiddlewareFactory(exit =>
|
||||||
|
{
|
||||||
|
builder.Use(ignored => exit);
|
||||||
|
return builder.Build();
|
||||||
|
});
|
||||||
|
|
||||||
|
app(middleware);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CreateMiddleware CreateMiddlewareFactory(Func<RequestDelegate, RequestDelegate> middleware)
|
||||||
|
{
|
||||||
|
return next =>
|
||||||
|
{
|
||||||
|
var app = middleware(httpContext =>
|
||||||
{
|
{
|
||||||
return app.Invoke(new OwinEnvironment(httpContext));
|
return next(httpContext.GetFeature<ICanHasOwinEnvironment>().Environment);
|
||||||
|
});
|
||||||
|
|
||||||
|
return env =>
|
||||||
|
{
|
||||||
|
return app.Invoke(
|
||||||
|
new DefaultHttpContext(
|
||||||
|
new FeatureCollection(
|
||||||
|
new OwinFeatureCollection(env))));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return builder.Use(middleware1);
|
}
|
||||||
|
|
||||||
|
public static AddMiddleware UseBuilder(this AddMiddleware app, Action<IBuilder> pipeline)
|
||||||
|
{
|
||||||
|
var builder = app.UseBuilder();
|
||||||
|
pipeline(builder);
|
||||||
|
return app;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNet.Abstractions;
|
|
||||||
using Microsoft.AspNet.FeatureModel;
|
|
||||||
using Microsoft.AspNet.PipelineCore;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Owin
|
|
||||||
{
|
|
||||||
using AppFunc = Func<IDictionary<string, object>, Task>;
|
|
||||||
|
|
||||||
public static class OwinMiddlewareFactory
|
|
||||||
{
|
|
||||||
public static Func<AppFunc, AppFunc> Create(Action<IBuilder> configuration)
|
|
||||||
{
|
|
||||||
return Create(services: null, configuration: configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Func<AppFunc, AppFunc> Create(IServiceProvider services, Action<IBuilder> configuration)
|
|
||||||
{
|
|
||||||
var builder = new Builder(services);
|
|
||||||
configuration(builder);
|
|
||||||
|
|
||||||
return Create(exit =>
|
|
||||||
{
|
|
||||||
builder.Use(ignored => exit);
|
|
||||||
return builder.Build();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Func<AppFunc, AppFunc> Create(Func<RequestDelegate, RequestDelegate> middleware)
|
|
||||||
{
|
|
||||||
return next =>
|
|
||||||
{
|
|
||||||
var app = middleware(httpContext =>
|
|
||||||
{
|
|
||||||
return next(httpContext.GetFeature<ICanHasOwinEnvironment>().Environment);
|
|
||||||
});
|
|
||||||
|
|
||||||
return env =>
|
|
||||||
{
|
|
||||||
return app.Invoke(
|
|
||||||
new DefaultHttpContext(
|
|
||||||
new FeatureCollection(
|
|
||||||
new OwinFeatureCollection(env))));
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue