Wednesday, April 18, 2012

IRepository vs ISession

I have some Repository. Work with them is realized through an interface IRepository.

In sample project HomeController constructor realized with ISession. When I wrote this:



public class TestingController : Controller
{
private ISession session;

public TestingController(ISession session)
{
this.session = session;
}
//Some code here with this.session
}


It working well. When I decided to use IRepository:



public class TestingController : Controller
{
private IRepository repository;

public TestingController(IRepository repository)
{
this.repository = repository;
}
//Some code here with this.repository
}


It doesn't work in this method of other class WindsorControllerFactory:



protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
{
throw new HttpException(404, string.Format("The controller for path {0} culd not found!", requestContext.HttpContext.Request.Path));
}

return (IController)this.kernel.Resolve(controllerType);
}


I have exception




Can't create component 'MvcApplication1.Controllers.ResultsController' as it has dependencies to be satisfied.



'MvcApplication1.Controllers.ResultsController' is waiting for the
following dependencies:
- Service 'dal.Repository.IRepository' which was not registered.




How to solve it?



P.S. Assembly dal.Repository is working. If I write everywhere new dal.Repository.Repository() instead of this.repository - it working.





No comments:

Post a Comment