【发布时间】:2011-05-25 20:01:05
【问题描述】:
使用 Autofac,假设我有一个 PersonRepository 和一个 EventRepository 类,它们都依赖于 IDataService 服务...我在 Mvc 控制器操作中使用这两个存储库类(例如 - 也可能是一些 MvvM WPF 应用程序) 喜欢
public class Mycontroller : controller
{
public Mycontroller(PersonRepository personRepo, EventRepository eventRepo) {...}
...
public ActionResult Index(){ ... I use the repository classes in here ...}
}
public class PersonRepository
{
public PersonRepository(IDataService service){...}
}
public class EventRepository
{
public PersonRepository(IDataService service){...}
}
我想确保在使用存储库类并使用 IDataService 实现注入它们时,两个存储库类都接收到相同的实例 IDataService 服务...
我该怎么做?
【问题讨论】: