StructureMap:如何为每个接口使用多个具体类

发布于 2024-09-11 16:19:00 字数 153 浏览 1 评论 0原文

我如何计算 StructureMap 为每个接口使用多个具体类。 即 IRepositoryCustomer 是通过以下方式实现的:RepositoryCustomerA 和 RepositoryCustomerB

如何向 StructureMap IoC 容器注册并解析它?

How can I figure StructureMap to use more than one concrete Class per Interface.
i.e. an IRepositoryCustomer is implemented by: RepositoryCustomerA and RepositoryCustomerB

How do I register and resolve this to/from the StructureMap IoC container?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过潦 2024-09-18 16:19:00

您首先需要回答以下问题:“我什么时候需要 RepositoryCustomerA 而不是 RepositoryCustomerB?”

如果这些类中的任何一个都可以根据某些运行时状态在生产中实例化,那么您可能需要研究 条件对象构造

如果 RepositoryCustomerA 应在开发时实例化(例如,用于单元测试),而 RepositoryCustomerB 是生产模拟,那么您需要两个不同的 Registry:一个仅存在于测试代码中,另一个是在生产中可访问。有关此路线的更多信息,请阅读创建注册表作为配置 StructureMap 的一种方法。

You first need to answer the question, "when do I want RepositoryCustomerA instead of RepositoryCustomerB?"

If either of those classes could be instantiated in production based on some runtime state, then you probably want to look into conditional object construction.

If RepositoryCustomerA should be instantiated at development time (for unit testing, say) while RepositoryCustomerB is the production analog, then you need two distinct Registrys: one that exists only in your test code, and one that is accessible in production. For more on this route, read about creating registries as a means of configuring StructureMap.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文