When I try to create a new IRepository<Tag>
using kernel.Get
, Ninject throws an exception. Am I using Ninject in the correct manner and are the bindings set up correctly?
Method of class NinjectDependencyResolver
:
private void AddBindings()
{
var mapperConfiguration = new MapperConfiguration(cfg =>
{
cfg.AddProfile(new TagProfile());
});
var mapper = mapperConfiguration.CreateMapper();
_kernel.Bind<BlogDbContext>().ToSelf().InRequestScope();
_kernel.Bind<IRepository<Tag>, Repository<Tag>>();
_kernel.Bind<IMapper>().ToConstant(mapper);
var repository = _kernel.Get<IRepository<Tag>>(); // exception thrown here
_kernel.Bind<ITagService, TagService>();
}
Class Repository
:
`public class Repository<T> : IRepository<T> where T : class
{
private readonly BlogDbContext _db;
public Repository(BlogDbContext db)
{
_db = db;
}
}`
P.S.. I do not know whether this is important, but its interface repository is located in the same assembly, and Ninject registration in another.