Using Unity, I'd like to automatically register all interface/class combinations in an assembly based on the following convention:
INameOfObject > NameOfObject
StructureMap does that when the default conventions are enabled.
I wrote the following method for it:
private static IUnityContainer RegisterITypesOf(this IUnityContainer container, string assemblyName)
{
Assembly.Load(assemblyName)
.GetTypes()
.Where(t => t.GetInterfaces().Any(i => i.Name == "I" + t.Name))
.ForEach(t => container.RegisterType(t.GetInterface("I" + t.Name, false), t));
return container;
}
My question is:
Unity 3.5.140.0 has built in functionality to register interfaces with similar names as the class that uses it.
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterTypes(
AllClasses.FromLoadedAssemblies(),
WithMappings.FromMatchingInterface,
WithName.Default);
}