假设我有下一个课程:
public class DBUnitOfWork : IUnitOfWork { ... }
public class CustomerRepository : ICustomerRepository
{
public CustomerRepository(DBUnitOfWork unitOfWork) { ... }
}
public class OrderRepository : IOrderRepository
{
public OrderRepository(DBUnitOfWork unitOfWork) { ... }
}
public class AppService : IAppService
{
public AppService(IUnitOfWork unitOfWork, ICustomerRepository customers, IOrderRepository orders) { ... }
}
public class AppView
{
public AppView(IAppService appService) { ... }
}
我想通过 StructureMap 创建一个 AppView 的实例,每次创建它时都会注入一个新的 AppService 对象,并且 AppServiceDBUnitOfWork
本身和两个存储库都有相同的实例。如何在 StructureMap 上设置它?
更新:我正在寻找类似的东西,但在容器配置中或通过注册表完全定义。