【发布时间】:2011-07-25 16:08:24
【问题描述】:
假设我有两个服务(A 和 B)都注册为 ISomeService。还假设我将来需要需要这些服务之一的课程。但我还不知道类名。我所知道的是它们正在实现给定的接口或抽象类(实现给定接口的所有类都需要相同的 ISomeService 实例)。如何确保此解决方案发生?
Here is a related question where the name of the class which uses the resolved service is known. 但在我的情况下,类名 CustomerRepository 的名称是未知的。只有接口(如 IUserRepository 或 IFunctionRepository)或抽象类的名称是已知的。换句话说,我只知道 SomeRepository:IUserRepository 和 IUserRepository 类型需要 A。我必须允许用户编写更多实现 IUserRepository 的类。
这是提出问题的更好方法。 我需要所有 IFunctionRepository 构造函数来获取 A(where A:ISomeService) 和所有 IUserRepository 构造函数来获取 B(where B:ISomeService)
【问题讨论】:
标签: c# .net-4.0 ioc-container autofac