LuckSound
LuckSound

Reputation: 996

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.

Upvotes: 1

Views: 176

Answers (2)

Sajjad Ali Khan
Sajjad Ali Khan

Reputation: 1813

I able to resolve the same issue by following this Documentation

and another thing is if we download new version for this project from github we will not see this expcetion Link

Upvotes: 0

Alexander Beletsky
Alexander Beletsky

Reputation: 19821

It looks like you missing the binding for IRepository.

You have to have concrete class that would implement IRepository interface, say MyRepository. Then you should configure Windsor, to understand what the IRepository is about.

Something like,

container.Register(Component.For<IRepository>().ImplementedBy<MyRepository>());

Upvotes: 3

Related Questions