I have an interface "ISetting". I have POCO classes the implement this empty interface with some properties with some auto getter/setters.
I would like for SimpleInjector to inspect every type requested (that isn't explicitly registered), and if it implements this interface, resolve it with a method I provide.
This allows me to use POCO objects for settings with an option of binding the POCO objects to their self using default values (from constructor). This is great for unit testing as well as turning settings off (using default values).
Is this possible and what is the approach?
Thanks in advance!
This is available using the ResolveUnregisteredType event. Example:
container.ResolveUnregisteredType += (s, e) =>
{
Type type = e.UnregisteredType;
if (typeof(ISetting).IsAssignableFrom(type))
{
// If you need raw performance, there is also
// an overload that takes in an Expression.
e.Register(() =>
{
// Do something useful here. Example:
return Activator.CreateInstance(type);
});
}
};