我使用this document来使用类型化工厂并将参数传递给构造函数。 当我尝试传递代码中显示的2个参数(1,“fo”)时,键入的工厂给了我这个错误。将参数传递给Castle Windsor Typed Factory
public class SomeClass {
public ITypedFactory2 F2 { get; set; }
public void SomeFunction() {
var req = F2.Create<IGetFooRequest>(1, "fo"); // ERROR HERE
}
}
public class GetFooRequest : IGetFooRequest {
public int Bar { get; private set; }
public string Ton { get; private set; }
public GetFooRequest(int bar, string ton) {
Bar = bar;
Ton = ton;
}
}
public interface IGetFooRequest{
int Bar { get; }
string Ton { get; }
}
public interface ITypedFactory2 {
T Create<T>(int param1, string param2);
void Release(object t);
}
,这是温莎安装部分...
container.AddFacility<TypedFactoryFacility>();
container.Register(Component.For<ITypedFactory2>().AsFactory());
container.Register(AllTypes
.FromAssemblyContaining<IGetFooRequest>()
.Where(type => type.Name.EndsWith("Request"))
.WithService.AllInterfaces().LifestyleTransient());
为什么说解决不了非可选依赖...?我通过了(1,“fo”);我真的不明白为什么会发生这种情况......请帮忙。
这不是标记为答案? – neverseenjack 2017-03-30 15:49:33
它被标记为答案 – 2018-01-19 02:00:23