I have some classes like UserQuery, CustomerQuery implementing interfaces like IUserQuery, ICustomerQuery respectively. In my binding configuration I need to bind every interface with the respectively query:
builder.RegisterType<UserQuery>().As<IUserQuery>().InstancePerRequest();
builder.RegisterType<CustomerQuery>().As<ICustomerQuery>().InstancePerRequest();
This is working pretty fine, but I was wondering if there is a way to make a convention-based binding in place of binding every single classe XXX[Query] -> [I]XXX[Query].
I’m using AutoFac as my DI container.
I’m not a AutoFac experienced user. However after some research a tested the code below with success:
The IQuery interface above is just a tag interface that should be inherited from every query interface that you have. Using your example:
Interfaces
Classes