#22 - Make UseMiddleware look for any Invoke method.
This commit is contained in:
parent
7edc2dfbe9
commit
afa87bf857
|
|
@ -27,6 +27,11 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
public static class ContainerExtensions
|
public static class ContainerExtensions
|
||||||
{
|
{
|
||||||
|
public static IBuilder UseMiddleware<T>(this IBuilder builder, params object[] args)
|
||||||
|
{
|
||||||
|
return builder.UseMiddleware(typeof(T), args);
|
||||||
|
}
|
||||||
|
|
||||||
public static IBuilder UseMiddleware(this IBuilder builder, Type middleware, params object[] args)
|
public static IBuilder UseMiddleware(this IBuilder builder, Type middleware, params object[] args)
|
||||||
{
|
{
|
||||||
// TODO: move this ext method someplace nice
|
// TODO: move this ext method someplace nice
|
||||||
|
|
@ -34,7 +39,7 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
var typeActivator = builder.ApplicationServices.GetService<ITypeActivator>();
|
var typeActivator = builder.ApplicationServices.GetService<ITypeActivator>();
|
||||||
var instance = typeActivator.CreateInstance(builder.ApplicationServices, middleware, new[] { next }.Concat(args).ToArray());
|
var instance = typeActivator.CreateInstance(builder.ApplicationServices, middleware, new[] { next }.Concat(args).ToArray());
|
||||||
var methodinfo = middleware.GetTypeInfo().GetDeclaredMethod("Invoke");
|
var methodinfo = middleware.GetRuntimeMethods().Single(info => info.Name.Equals("Invoke"));
|
||||||
return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance);
|
return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
"System.Diagnostics.Debug": "4.0.10.0",
|
"System.Diagnostics.Debug": "4.0.10.0",
|
||||||
"System.Linq": "4.0.0.0",
|
"System.Linq": "4.0.0.0",
|
||||||
"System.Reflection": "4.0.10.0",
|
"System.Reflection": "4.0.10.0",
|
||||||
|
"System.Reflection.Extensions": "4.0.0.0",
|
||||||
"System.Runtime": "4.0.20.0",
|
"System.Runtime": "4.0.20.0",
|
||||||
"System.Runtime.Extensions": "4.0.10.0",
|
"System.Runtime.Extensions": "4.0.10.0",
|
||||||
"System.Threading": "4.0.0.0",
|
"System.Threading": "4.0.0.0",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue