I\'ve got an interface:
IRepository where T : IEntity
while im knocking up my UI im using some fake repository implementations tha
There is an easier way to do this. Please see this blog posting for details: Advanced StructureMap: connecting implementations to open generic types
public class HandlerRegistry : Registry
{
public HandlerRegistry()
{
Scan(cfg =>
{
cfg.TheCallingAssembly();
cfg.IncludeNamespaceContainingType<FakeRepositories.FakeClientRepository>();
cfg.ConnectImplementationsToTypesClosing(typeof(IRepository<>));
});
}
}
Doing it this way avoids having to create your own ITypeScanner
or conventions.
Take a look at this discussion from the StructureMap users group: http://groups.google.com/group/structuremap-users/browse_thread/thread/649f5324c570347d
Thanks Chris, thats exactly what I needed. For clarity, heres what I did from your link:
Scan(x =>
{
x.TheCallingAssembly();
x.IncludeNamespaceContainingType<FakeRepositories.FakeClientRepository>();
x.With<FakeRepositoryScanner>();
});
private class FakeRepositoryScanner : ITypeScanner
{
public void Process(Type type, PluginGraph graph)
{
Type interfaceType = type.FindInterfaceThatCloses(typeof(IRepository<>));
if (interfaceType != null)
{
graph.AddType(interfaceType, type);
}
}
}