只要我爲使用泛型的接口設置規則,就很難處理。例如,這工作(對於一個簡單的界面)設置使用泛型的接口的構造函數參數
// Imagine this interface
public interface ISearchProvider.
// Easy to set up with constructor parameters
x.For<ISearchProvider>()
.HybridHttpOrThreadLocalScoped()
.Use<CatalogueSearchProvider>()
.Ctor<bool>("recreateDb").Is(false)
.Ctor<string>("connectionString").Is(catalogConnString);
與此比較:
// Now this interface (that use generics)
public interface IRepo<T> : IRepo<T> where T : IEntity
如果我想使用相同的設置,我必須使用「typeof運算」和而不同structuremap方法,缺乏設置構造函數參數的可能性。
x.For(typeof(IRepo<>))
.HybridHttpOrThreadLocalScoped()
.Use(typeof(MyRepo<>)
.Ctor <-- doesn't exist!
);
我可以找到沒有等價物,是否有任何?