StructureMap: "No default instance of plugin defined" - even though it is

Posted by Dave Hanna on Stack Overflow See other posts from Stack Overflow or by Dave Hanna
Published on 2010-04-06T22:27:31Z Indexed on 2010/04/06 22:33 UTC
Read the original article Hit count: 474

Filed under:

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?

© Stack Overflow or respective owner

Related posts about structuremap