我有储藏室。与他们一起工作是通过一个接口IRepository实现的。
在样本工程中用ISession实现了HomeController构造函数。当我写这个的时候:
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‘正在等待下列依赖项:-未注册的服务'dal.Repository.IRepository’。
如何解决这个问题?
组装dal.Repository正在工作。如果我写得到处都是new dal.Repository.Repository(),而不是this.repository,它就能工作。
发布于 2012-04-18 10:02:52
看起来您缺少了IRepository的绑定。
您必须有实现IRepository接口的具体类,比如MyRepository。然后您应该配置温莎,以了解IRepository是关于什么的。
就像,
container.Register(Component.For<IRepository>().ImplementedBy<MyRepository>());https://stackoverflow.com/questions/10207073
复制相似问题