我在使用 Castle Windsor ISubDependencyResolver 获取参数名称时遇到了一点问题。我有类似下面的代码,对于 Foo,我希望 myBar.BarName 为“Foo_myBar”
Public Class Foo
{
private readonly IBar myBar;
Public Foo(IBar myBar){
this.myBar = myBar;
}
}
Public Class Bar: IBar
{
Public string BarName {get; private set;}
Public Bar(string barName){
BarName = barName;
}
}
public class BarNameResolver : ISubDependencyResolver
{
public bool CanResolve(CreationContext context,
ISubDependencyResolver contextHandlerResolver,
ComponentModel model,
DependencyModel dependency)
{
return context.RequestedType == typeof (IBar)
&& dependency.TargetType == typeof (string)
&& dependency.DependencyKey.Equals("barName");
}
public object Resolve(CreationContext context,
ISubDependencyResolver contextHandlerResolver,
ComponentModel model,
DependencyModel dependency)
{
return string.Format("{0}_{1}",
context.Handler.ComponentModel.Name,
**NameOfFooBarParameter**);
}
}
有什么方法可以在 ISubDependencyResolver 中获取“myBar”?
我需要这个在 Foo 中有多个具有不同配置的 IBar 实例。