0
我有一個類:StructureMap默認實例有明確的參數超載,錯誤205
public class SystemQuery<T> : ISystemQuery<T> where T : class, IUIView {
protected ISession session;
protected ICriteria baseCriteria;
public SystemQuery(SessionContext sessionContext) {
this.session = sessionContext.Session;
this.baseCriteria = session.CreateCriteria<T>();
}
public SystemQuery(SessionContext sessionContext, string newConnectionString)
{
var connection = new SqlConnection(newConnectionString);
connection.Open();
this.session = sessionContext.Session.SessionFactory.OpenSession(connection);
this.baseCriteria = session.CreateCriteria<T>();
}
StructureMap知道如何實現SessionContext,ISession的和的ICriteria。
在另一類我有(我想在此設立一個情況下,初始狀態):
public T BuildQuery<T>() where T: ISystemQuery {
return container.GetInstance<T>();
}
public T BuildQuery<T>(string newConnectionString) where T: ISystemQuery
{
var dict = new Dictionary<string, object>();
dict.Add("newConnectionString",newConnectionString);
return container.GetInstance<T>(new ExplicitArguments(dict));
}
的問題是它沒有超載時,它會創建實例的構造,當它調用
container.GetInstance<T>();
它本身不會調用單參數的構造函數...相反得到一個錯誤:
StructureMap異常代碼: 205 缺少請求實例屬性「newConnectionString」爲InstanceKey「f4fea539-2b04-4067-9c1a-990516268cea」