虽然我之前在 Castle Windsor 中使用过泛型,但这种特殊的组合目前让我感到困惑。
我想将其解析为构造函数参数,在此单元测试中通过显式调用resolve() 对其进行模拟。
但我无法弄清楚我需要做什么注册和解析的组合。我在下面显示了测试失败的代码,以明确问题。
public abstract class BaseSettings<T> where T : class
{
protected void Save(T obj)
{ }
}
public class AddinSettings : BaseSettings<AddinSettings>
{ }
public class OtherSettings : BaseSettings<OtherSettings>
{ }
public class LogConfig<T> where T : class
{
private readonly BaseSettings<T> _client;
public LogConfig(BaseSettings<T> client)
{
_client = client;
}
public BaseSettings<T> Client
{
get { return _client; }
}
}
[Test]
public void resolve_generics()
{
var container = new WindsorContainer();
container.Register(Component.For<OtherSettings >());
var otherSettings = container.Resolve<LogConfig<OtherSettings>>();
Assert.That(otherSettings, Is.Not.Null);
}