我想创建一个容器,它允许解析 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 是一个数据库存储库,他们不应该直接处理它,但 ISomeService 确实需要这个引用。
我不介意在解析过程中希望(它是一个 ASP.NET MVC 应用程序,我已经有一个用于创建控制器的扩展点)所以我可以查看正在解析的控制器,查看它的依赖关系并确保它们'在白名单上,但我不知道如何轻松评估与 Windsor 的依赖关系。或者,我是否只需要通过查看构造函数参数自己来完成?