在单元测试中正确的部分我解决一个接口发送论据如下它的构造函数:温莎城堡 - 无法注册argumants
var args = new { arg1 = "arg1 value", arg2 = "arg2 value" };
var component = container.Resolve<IMyDependency>(args);
,它工作正常。但现在我想这样做在构造函数注入,例如:
public class Foo
{
private IMyDependency _dep;
public Foo(IMyDependency dep) { _dep = dep; }
}
所以,作为一个尝试我UsingFactoyMethod()
注册这样的:
public class BarInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<IMyDependency>().UsingFactoryMethod(
() =>
{
var args = new { arg1 = "arg1 value", arg2 = "arg2 value" };
var result = container.Resolve<IMyDependency>(args);
return result;
}).LifestyleTransient());
// + some other registerations and installs
}
}
但我还是错误:
Can't create component 'namespace.MyDependency' as it has dependencies to be satisfied.
'namespace.MyDependency' is waiting for the following dependencies:
- Parameter 'arg1' which was not provided. Did you forget to set the dependency?
- Parameter 'arg2' which was not provided. Did you forget to set the dependency?
当我检查时,'MyDependency'也在其他一些注册中注册。 –