Making core clr friendly
This commit is contained in:
parent
7b038d4e31
commit
951e8df893
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNet.Abstractions;
|
using Microsoft.AspNet.Abstractions;
|
||||||
|
|
@ -14,32 +15,32 @@ namespace Microsoft.AspNet.RequestContainer
|
||||||
// TODO: move this ext method someplace nice
|
// TODO: move this ext method someplace nice
|
||||||
return builder.Use(next =>
|
return builder.Use(next =>
|
||||||
{
|
{
|
||||||
//TODO: this should be MethodInfo.CreateDelegate for coreclr
|
|
||||||
var typeActivator = builder.ServiceProvider.GetService<ITypeActivator>();
|
var typeActivator = builder.ServiceProvider.GetService<ITypeActivator>();
|
||||||
var instance = typeActivator.CreateInstance(middleware, new[] { next }.Concat(args).ToArray());
|
var instance = typeActivator.CreateInstance(middleware, new[] { next }.Concat(args).ToArray());
|
||||||
return (RequestDelegate)Delegate.CreateDelegate(typeof(RequestDelegate), instance, "Invoke");
|
var methodinfo = middleware.GetTypeInfo().GetDeclaredMethod("Invoke");
|
||||||
|
return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IBuilder UseContainer(this IBuilder app)
|
public static IBuilder UseContainer(this IBuilder builder)
|
||||||
{
|
{
|
||||||
return app.UseMiddleware(typeof(ContainerMiddleware));
|
return builder.UseMiddleware(typeof(ContainerMiddleware));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IBuilder UseContainer(this IBuilder app, IServiceProvider applicationServices)
|
public static IBuilder UseContainer(this IBuilder builder, IServiceProvider applicationServices)
|
||||||
{
|
{
|
||||||
app.ServiceProvider = applicationServices;
|
builder.ServiceProvider = applicationServices;
|
||||||
|
|
||||||
return app.UseMiddleware(typeof(ContainerMiddleware));
|
return builder.UseMiddleware(typeof(ContainerMiddleware));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IBuilder UseContainer(this IBuilder app, IEnumerable<IServiceDescriptor> applicationServices)
|
public static IBuilder UseContainer(this IBuilder builder, IEnumerable<IServiceDescriptor> applicationServices)
|
||||||
{
|
{
|
||||||
var serviceCollection = new ServiceCollection();
|
var serviceCollection = new ServiceCollection();
|
||||||
serviceCollection.Add(applicationServices);
|
serviceCollection.Add(applicationServices);
|
||||||
app.ServiceProvider = serviceCollection.BuildServiceProvider(app.ServiceProvider);
|
builder.ServiceProvider = serviceCollection.BuildServiceProvider(builder.ServiceProvider);
|
||||||
|
|
||||||
return app.UseMiddleware(typeof(ContainerMiddleware));
|
return builder.UseMiddleware(typeof(ContainerMiddleware));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -43,12 +43,19 @@ namespace Microsoft.AspNet.RequestContainer
|
||||||
_rootHttpContextAccessor.SetContextSource(AccessRootHttpContext, ExchangeRootHttpContext);
|
_rootHttpContextAccessor.SetContextSource(AccessRootHttpContext, ExchangeRootHttpContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NET45
|
||||||
|
#else
|
||||||
|
#warning This MUST NOT be ThreadStatic in reality
|
||||||
|
[ThreadStatic]
|
||||||
|
HttpContext THIS_IS_BROKEN_AND_MUST_BE_CHANGED;
|
||||||
|
#endif
|
||||||
|
|
||||||
private HttpContext AccessRootHttpContext()
|
private HttpContext AccessRootHttpContext()
|
||||||
{
|
{
|
||||||
#if NET45
|
#if NET45
|
||||||
return CallContext.LogicalGetData(LogicalDataKey) as HttpContext;
|
return CallContext.LogicalGetData(LogicalDataKey) as HttpContext;
|
||||||
#else
|
#else
|
||||||
throw new NotImplementedException()
|
return THIS_IS_BROKEN_AND_MUST_BE_CHANGED;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,7 +66,9 @@ namespace Microsoft.AspNet.RequestContainer
|
||||||
CallContext.LogicalSetData(LogicalDataKey, httpContext);
|
CallContext.LogicalSetData(LogicalDataKey, httpContext);
|
||||||
return prior;
|
return prior;
|
||||||
#else
|
#else
|
||||||
throw new NotImplementedException()
|
var prior = THIS_IS_BROKEN_AND_MUST_BE_CHANGED;
|
||||||
|
THIS_IS_BROKEN_AND_MUST_BE_CHANGED = httpContext;
|
||||||
|
return prior;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue