我需要将一些参数传递给自定义的AbstractLifestyleManager派生类型. 当我从容器请求一个类型的实例时,我使用以下重载: T ResolveT(string key, object argumentsAsAnonymousType) 例如: public IHttpControll
当我从容器请求一个类型的实例时,我使用以下重载:
T Resolve<T>(string key, object argumentsAsAnonymousType)
例如:
public IHttpController CreateController(HttpControllerContext controllerContext, string controllerName) { var controller = this.container.Resolve<IHttpController>( controllerName, new { requestProperties = controllerContext.Request.Properties }); // ... }
然后,在自定义AbstractLifestyleManager派生类型中,我可以这样做:
var messageProperties = (IDictionary<string, object>) context.AdditionalArguments["requestProperties"];
返回我预先传递的值.
但是,如果我调用base.Resolve(context,releasePolicy),则如果代码以递归方式输入自定义类型,则AdditionalArguments为null.
是否可以在base.Resolve调用之间传递/流动AdditionalArguments?
在实现生活方式管理器时,我不太确定流程是什么,但听起来像CreateContext AdditionalArguments在默认情况下不会传播到子上下文的问题.见 this other question.如果是这种情况,您可以尝试通过继承DefaultDependencyResolver来更改链接问题中描述的默认值.