With structure map, you can register a convention that lets you not just tweak the type, but also intervene during object creation. How can I do this with Unity.
public class SettingsRegistration : IRegistrationConvention
{
public void Process(Type type, Registry registry)
{
if (!type.IsAbstract && typeof(ISettings).IsAssignableFrom(type))
{
registry.For(type).Use(x =>
{
var svc = x.GetInstance<ISettingService>();
return svc.LoadSetting(type);
});
}
}
}
You can do this with a combination of Unity's Registration by Convention and an InjectionFactory. I see three common options for implementation, though I'm sure there are more...
Option 1
Register all type at once with if conditions inline in a lambda expression. Though this does not scale well if you are registering many types with many custom registrations...
Option 2
Register only the ISettings types and supply some nice helper methods. You will need to call container.RegisterTypes multiple times, but it is much more readable...
Option 3
Or you could create a class derived from RegistrationConvention and let that class make all of the registration decisions...