I have a common interface IRepository<T>and two implementations xrmRepository<T>andefRepository<T>
I want to change the binding based on T, more specifically use xrmRepositorywhen Tcomes from Entity. How can i do this?
I currently have:
kernel.Bind(typeof(IRepository<>)).To(typeof(efRepository<>)).InRequestScope();
kernel.Bind(typeof(IRepository<>)).To(typeof(xrmRepository<>)).When(request => request.Service.GetGenericArguments()[0].GetType().IsSubclassOf(typeof(Entity))).InRequestScope();
But when I try to resolve IRepository<Contact>, it goes into efRepository, although Contact inherits Entity.
I do not want to use Named Bindings, otherwise I will have to add names everywhere.
source
share