Move UseMiddleware from RequestContainer to Http.Extensions.
This commit is contained in:
parent
0f2b9b3701
commit
8bd068f4a6
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
public static class UseMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseMiddleware<T>(this IApplicationBuilder builder, params object[] args)
|
||||
{
|
||||
return builder.UseMiddleware(typeof(T), args);
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseMiddleware(this IApplicationBuilder builder, Type middleware, params object[] args)
|
||||
{
|
||||
return builder.Use(next =>
|
||||
{
|
||||
var typeActivator = builder.ApplicationServices.GetService<ITypeActivator>();
|
||||
var instance = typeActivator.CreateInstance(builder.ApplicationServices, middleware, new[] { next }.Concat(args).ToArray());
|
||||
var methodinfo = middleware.GetMethod("Invoke", BindingFlags.Instance | BindingFlags.Public);
|
||||
return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*"
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.Framework.DependencyInjection": "1.0.0-*"
|
||||
},
|
||||
"frameworks" : {
|
||||
"aspnet50" : {
|
||||
},
|
||||
"aspnetcore50" : {
|
||||
"dependencies": {
|
||||
"System.Reflection": "4.0.10-beta-*",
|
||||
"System.Reflection.Extensions": "4.0.0-beta-*",
|
||||
"System.Reflection.TypeExtensions": "4.0.0-beta-*",
|
||||
"System.Runtime": "4.0.20-beta-*"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue