We're struggling with understanding the difference between these two ways to configure StructureMap. Our understanding is that they should be identical but we get different results between these two lines inside of Initialize:
ObjectFactory.Initialize(x =>
{
x.For<IBusinessRelationsContext>().Use<BusinessRelationsContext>().Ctor<string>().Is(ConfigurationManager.ConnectionStrings["BusinessRelationsContext"].ConnectionString);
x.For<IBusinessRelationsContext>().Use(_ => new BusinessRelationsContext(ConfigurationManager.ConnectionStrings["BusinessRelationsContext"].ConnectionString));
});
(we only use 1 of the two at a time - not both, obviously)
Our various constructor signatures on this object (it's EF4 stuff if you care):
public BusinessRelationsContext();
public BusinessRelationsContext(string connectionString);
public BusinessRelationsContext(EntityConnection connection);
The code we use to invoke this is:
ObjectFactory.TryGetInstance<IBusinessRelationsContext>();
The difference in behavior that we see is that the line that includes Ctor<string>
fails because StructureMap fails with a 202 "No Default Instance defined for PluginFamily System.Data.Common.DbConnection" (we have no idea why it thinks it needs this). However, if I comment that line out and use the other one, it works perfectly as we would expect. Given that the other one works, I suspect that my understanding that it shouldn't need config for DbConnection is correct.
So rather than tracking down WHY it needs the DbConnection I would rather track down the answer to my question: What's the difference between these two?