How do I configure StructureMap to use a generic repository?
- by simonjreid
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