我使用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