For this Demo I have created a fake Database+repository as 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()
{
//do nothing
throw new Exception("Disposed is called");
}
}
My Controller looks this
public class TestController:Controller
{
protected IDemoRepository _repository;
public BaseController(IDemoRepository repository)
{
_repository = repository;
}
public ActionResult()
{
var users = _repository.GetUsers();
Return View(users);
}
}
Ninject Part
I installed ninject from NUGet and added below code for resolving repositories
kernel.Bind<IDemoRepository>().To<DemoRepository>()
Ninject is not calling DemoRepository.Dispose
, i added a break point even my current code is throwing error but Ninject is not calling DemoRepository.Dispose
.
Can any body suggest me how dispose the object.