我有以下结构,在另一个大会中设有一个公务员班,称为内部助手班:
ApplicationAssembly {
public class Widget {
public Widget(ReferencedAssembly.Service service) { ... }
}
}
ReferencedAssembly {
public class Service {
public Service(Helper helper) { ... }
}
class Helper { ... }
}
(我认识到,我可以不把一个内部阶级放在一个公共阶层的构造者——Im的论点中,只是试图说明IoC的模式,Im在之后。)
The problem is that ApplicationAssembly
can t see ReferencedAssembly.Helper
, so it can t be registered in my IoC container (Autofac in this case). As a result, Helper
cannot be resolved when I try to resolve Service
. What is my best option here?
备选案文1:删除<代码>Helper>,从
> 处
到构造,并在构造中明确加以更新。 我不喜欢这一选择,因为这种做法打破了国际奥委会的模式。备选案文2:制作<代码>Helper,实施公共<代码>IHelper接口,然后在
内添加公共模块。 登记<代码>Helper
的参考大会。 我不喜欢这一选择,因为它要求<代码>ApplicationAssembly了解太多的执行细节-service
,而且如果用户忘记在启动时登记该模块,则每次都会中断。Option 3: Create a public static constructor on
Service
that builds a 2nd IoC container specifically forReferencedAssembly
and registersHelper
in it. RemoveHelper
fromService
s constructor and resolve it within the constructor using the 2nd IoC container. This seems like my best option but requires more "plumbing" code than the others. I m also not a big fan of public static constructors.备选办法4. 将我的架构完全改为其他内容。