2012-04-18 21 views
1

我有一些知识库。与他们一起工作是通过接口IRepository实现的。
sample projectHomeController用ISession实现的构造函数。当我写这个:IRepository vs ISession

public class TestingController : Controller 
{ 
    private ISession session; 

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

它运作良好。当我决定使用IRepository

public class TestingController : Controller 
{ 
    private IRepository repository; 

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

它不会在其他类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); 
    } 

我有例外

无法创建组件“MvcApplication1 .Controllers.ResultsController',因为它具有依赖性。

'MvcApplication1.Controllers.ResultsController'正在等待下列依赖项的 : - Service'dal.Repository.IRepository'未注册。

如何解决?

P.S.装配dal.Repository正在工作。如果我写new dal.Repository.Repository()而不是this.repository - 它正在工作。

回答

3

看起来你错过了IRepository的绑定。

你必须具有实现IRepository接口的具体类,比如MyRepository。那么你应该配置温​​莎,了解什么是IRepository

喜欢的东西,

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

IT WORKS !!!))) 非常感谢你)对我来说很难 - 理解这一点) – LuckSound 2012-04-18 10:10:22

0

我可以按照此Documentation

,另一件事是,如果我们下载新版本从github上这个项目,我们将不会看到这个expcetion解决同样的问题Link