【发布时间】:2014-01-02 23:05:39
【问题描述】:
我想创建一个容器,它允许解析 ISomeService,但不允许解析 ISomeOtherService。即使我对 ISomeService 的注册依赖于 ISomeOtherService。
这有意义吗?
public interface ISomeService {}
public interface ISomeOtherService {}
public class SomeService : ISomeService
{
public SomeService(ISomeOtherService someOtherService) {}
}
public class SomeOtherService : ISomeOtherService {}
我想要的这个容器会为 ISomeService 解析 SomeService 但如果我尝试解析 ISomeOtherService 或 SomeOtherService 它将失败。
这是糟糕的设计吗?
所以,有一点上下文...我有 ASP.Net MVC 控制器,将由各种开发人员开发。这些控制器应该可以访问 ISomeService 之类的应用程序服务,但不能访问它们的依赖项。我想避免必须对所有这些服务进行代码审查,以确保开发人员没有违反架构设计。他们应该能够获得对 ISomeService 的引用,但 ISomeOtherService 是一个 DB 存储库,他们不应该直接处理它,但 ISomeService 确实需要这个引用。
我不介意在解析过程中希望(它是一个 ASP.NET MVC 应用程序,我已经有一个用于创建控制器的扩展点)所以我可以看看正在解析的控制器,看看它的依赖关系并确保它们在白名单上,但我不知道如何轻松评估与 Windsor 的依赖关系。或者,我只需要自己通过查看构造函数参数来完成吗?
【问题讨论】:
标签: c# castle-windsor containers windsor-3.0