For this demo, I created a fake database repository + below
Fake db + repository
public interface IDemoRepository { string[] GetUsers(); } public class DemoRepository : IDemoRepository, IDisposable { public string[] GetUsers() { string[] Users = { "Robert","Linda","Jack"}; return Users; } public void Dispose() {
My controller looks like this:
public class TestController:Controller { protected IDemoRepository _repository; public BaseController(IDemoRepository repository) { _repository = repository; } public ActionResult() { var users = _repository.GetUsers(); Return View(users); } }
Non-injection part
I installed ninject from NUGet and added below code to allow repositories
kernel.Bind<IDemoRepository>().To<DemoRepository>()
Ninject does not call DemoRepository.Dispose
, I added a breakpoint, even my current code throws an error, but Ninject does not call DemoRepository.Dispose
.
Can any body suggest me how to remove an object.
source share