Good day, dear forum users. I am doing a learning project and faced the following question. The project consists of two parts Domain and UI. In Domaine created interfaces, their implementation and classes:

public interface IDbRepository { IQueryable<Article> Article { get; } } public class EFRepository:IDbRepository { private readonly ApplicationDbContext _context= new ApplicationDbContext(); public IQueryable<Article> Article { get { return _context.Articles; } } } //данные классы перенес из UI namespace Domain.FF { public class ApplicationUser : IdentityUser { } public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("DefaultConnection") { } public DbSet<Article> Articles { get; set; } } } 

The UI announced the ninject

 private void AddBindings() { // конфигурирование контейнера ninjectKernel.Bind<IDbRepository>().To<EFRepository>(); } 

And with such a controller implementation, I see the Article class

 private IDbRepository _repository; public ХХController(IDbRepository reposit) { this._repository = reposit; } 

It seems like all the rules work, but the question arises how to observe the principle of loose coupling in

 AccountController public class AccountController : Controller { public AccountController() : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()))) { } 

Where and how to add? but it still turns out if we declare Domain.FF in the using namespace.

Thank you in advance.

    1 answer 1

    In asp.net mvc, there is such a thing as a DependencyResolver. If you put ninject.Mvc, then it should work. Like that:

     DependencyResolver.Current.GetService<IUserStore>(); 

    Here you can read

    • Veikedo Thank you very much. The article helped a little). Truth made fig understand as in the end I don’t know correctly in terms of a template or not, but it works :). - Alex_student
    • You can read sergeyteplyakov.blogspot.ru/2013/01/blog-post.html by the pattern yourself . And the book is still there, Dependency Injection in .net In general, ioc is not an end in itself, proceed from how you feel more comfortable - Veikedo
    • Yes, I just just understand all this programming. I read Freeman's book on MVC and try to write something of my own). So there is recommended such a division .... Thanks for the links) I will study) - Alex_student