I would like my constructor to call another constructor with parameter but when I do this(MyProperty), then MyProperty must be static. And the problem is in the getter of this static Property, I have to get an instance of ISettingReader from structuremap Container and as it is static, my container contains only two elements instead of more than 50 elements, then it can't find the instance. (Error of pluginFamily on ISettingReader)
Here's my code.
private static Func<LinqDataContext> _contextFactory;
public static Func<LinqDataContext> DefaultContextFactory
{
get
{
var settingReader = ObjectFactory.GetInstance<ISettingReader>(); // I get an error saying it can't find ISettingReader()
var connectionString = settingReader.GetSetting("MyProject.ConnectionString");
_contextFactory = () => new LinqDataContext(connectionString);
return _contextFactory;
}
}
public MyProjectViewModelService() : this(DefaultContextFactory)
{
}
public MyProjectViewModelService(Func<LinqDataContext> contextFactory)
{
_contextFactory = contextFactory;
}
I think if I can get rid of my static keyword, it should work. And I confirm I have initialized my ISettingReader in structureMap container when I started my application in Program.exe
So what should I do ? Thanks !
John
PS: there's similar problem I found on stackoverflow, but he doesn't use structureMap: Constructor chaining with intermediate variables