I have a class:
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 knows how to build SessionContext, ISession and ICriteria.
In another class I have (I am trying to set up an initial state in this one case):
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));
}
The problem is it is not overloading the constructor when it creates the instance, when it calls
container.GetInstance<T>();
by itself it does not call the single parameter constructor...instead get an error:
StructureMap Exception Code: 205 Missing requested Instance property "newConnectionString" for InstanceKey "f4fea539-2b04-4067-9c1a-990516268cea"