Currently i have a webapi controller with the constructor like this:
readonly IQueryFactory queryFactory;
readonly ICommandFactory commandFactory;
public UserBenefitsController(
IQueryFactory queryFactory,
ICommandFactory commandFactory)
{
this.queryFactory = queryFactory;
this.commandFactory = commandFactory;
}
I am using simple injector to register both of these types.
container.RegisterWebApiRequest<IQueryFactory, QueryFactory>();
container.RegisterWebApiRequest<ICommandFactory, CommandFactory>();
But i am finding that as i continue to develop my app that I am continuing to have a lot of ISomeInterface
resolving to ISomeConcrete
with 1:1 ratio.
Is it possible to tell simple injector to look for at an interface and automatically resolve it when there is only 1 concrete for it within the WebApiRequest scope?
You can use batch / automatic registration to resolve to concrete instances. The Simple Injector documentation explains it here
For instance: