I have the following interface:
public interface IQueryStringHelper<T, in TQueryString> where T : class where TQueryString : class
{
IQueryable<T> ApplyQueryStringToQuery(IQueryable<T> query, TQueryString queryString, out int count);
}
and its implementation in one of the classes looks like:
public class BookingQueryStringHelper : IQueryStringHelper<Booking, BookingsQueryString>
{
public IQueryable<Booking> ApplyQueryStringToQuery(IQueryable<Booking> query, BookingsQueryString queryString, ICmsDbContext _cmsDbContext, out int count)
{
var cat....
}
}
I have many different classes that use this generic interface and i want to bind it in ninject but having 0 success so far. I don't want one line per implementation(i know that works).
I've tried writing it something like this:
kernel.Bind(x => x.FromThisAssembly()
.SelectAllClasses()
.InheritedFrom(typeof(IQueryStringHelper<,>))
.BindSingleInterface());
and
kernel.Bind(x =>
x.FromThisAssembly()
.SelectAllClasses()
.InheritedFrom(typeof(IQueryStringHelper<,>))
.BindToSelf());
but Im not able to get it to work
All help is very welcome!
*EDIT @Steven pointed me in the correct direction, so the bind statement is as following:
kernel.Bind(x =>
x.FromAssemblyContaining(typeof(IQueryStringHelper<,>))
.SelectAllClasses()
.InheritedFrom(typeof(IQueryStringHelper <,>))
.BindSingleInterface());
and now everything works as intended!