views:

237

answers:

2

Hello guys, I'm new to IOC and strcturemap but i want to know how I can register different classes that implements from the same interface like IRepository that implements CustomerRepository and CategoryRepository for example. And, as you can see, if i can use this with generic types. Like Repository or Repository

x.ForRequestedType<IRepository<Category>>().TheDefault.Is.OfConcreteType<IRepository<Category>>();

tried this bit It didn't worked..any help whould be appreciated!

+2  A: 

When configuring StructureMap, you can use the Scan API to auto-register the closed types.

Scan(x =>
{
  x.TheCallingAssembly();
  x.ConnectImplementationsToTypesClosing(typeof(IRepository<>));
});

This feature is in the latest trunk, but I'm not sure if it is any released version, and probably not yet in the official documentation. However, there is a good blog post that explains it.

Joshua Flanagan
A: 

No Default Instance defined for PluginFamily MVCPoco.Data.IRepository`1[[MVCPoco.Core.Category, MVCPoco.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], MVCPoco.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

got the latest version... the project runs but when i inject in the constructor a IRepository it gives me that error.

diego
I need to register ir? the name of the repository is Repository.cs... I counn't figure out what i'm doing wrong!
diego
I ran into the same problem, make sure the class it can't find is public.
Andrew