StructureMap: "No default instance of plugin defined" - even though it is
- by Dave Hanna
I've been using StructureMap for about 6 months now; you would think it would start getting easier. It doesn't seem to.
Here's the first line of my registry:
For<IDbConnection>()
.Singleton()
.Use<SqlConnection>()
.Ctor<string>(WebConfigurationManager.ConnectionStrings["UnifiedConnectionString"].ConnectionString);
It compiles and runs. But when I try to use that Interface, like this:
return MsSqlConfiguration.MsSql2008.ConnectionString(((DbConnection)ObjectFactory.GetInstance<IDbConnection>()).ConnectionString);
I get
StructureMap Exception Code: 202
No Default Instance defined for PluginFamily System.Data.IDbConnection, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Now I may be missing something (okay, I obviously am), but I don't know how much more plain I can be about defining the default instance for IDbConnection. What am I doing wrong?