How do I configure StructureMap to use a generic repository?

Posted by simonjreid on Stack Overflow See other posts from Stack Overflow or by simonjreid
Published on 2010-05-14T15:35:43Z Indexed on 2010/05/14 16:14 UTC
Read the original article Hit count: 265

I have an interface IGenericRepository<TEntity> where TEntity : IEntity and an implementation GenericRepository<TEntity> where TEntity : Entity.

I'm trying to inject a specific IGenericRepository<Section> into a class using StructureMap:

    ObjectFactory.Initialize(x =>
        {
            x.For(typeof(IGenericRepository<>)).Use(typeof(GenericRepository<>));
        });

But when I try to use ObjectFactory.GetInstance<IGenericRepository<Section>>(); I get:

StructureMap Exception Code: 202 No Default Instance defined for PluginFamily System.Data.Common.DbConnection

Any ideas why this is or what I'm doing wrong?

Thanks in advance,

Simon

© Stack Overflow or respective owner

Related posts about structuremap

Related posts about generics