I am using Unity and Unity.AutoRegistration. This line for Unity:
unityContainer.RegisterType(typeof(IAction<>), typeof(Action<>));
effectively registers every class in the project to IAction/Action:
unityContainer.RegisterType<IAction<ObjectA>, Action<ObjectA>>();
unityContainer.RegisterType<IAction<ObjectB>, Action<ObjectB>>();
unityContainer.RegisterType<IAction<ObjectC>, Action<ObjectC>>();
[...]
unityContainer.RegisterType<IAction<UnrelatedObject>, Action<UnrelatedObject>>();
[...]
But, I only want specific objects to be registered. How would I do that? My guess is to add a custom attribute decorator to the specific classes.
[ActionAtribute]
public class ObjectB
{ [...] }
And try to use Unity.AutoRegistration. This is where I am stuck at:
unityContainer.ConfigureAutoRegistration()
.Include(If.DecoratedWith<ActionAtribute>,
Then.Register()
.As ?? // I'm guessing this is where I specify
.With ?? // IAction<match> goes to Action<match>
)
.ApplyAutoRegistration();