我需要将范围限定为某个实例(想象一个HttpContext
实例)并将服务注入该范围(想象HttpRequest
和HttpResponse
)。
比我做的更像:
container.Register<HttpContext>(myScope);
container.Register<HttpRequest>(myScope);
container.Register<HttpResponse>(myScope);
EDIT1 下,的 EDIT2
我可以这样做吗?
container.Register<IDependency, MyHttpContextDependency>();
container.Register<IService, ExternalService>();
其中:
public class ExternalService : IService
{
public ExternalService(IDependency dependency)
...
}
public class MyHttpContextDependency : IDependency
{
public MyHttpContextDependency(HttpContext httpContext)
...
}