【问题标题】:StructureMap with WCF?带有 WCF 的结构映射?
【发布时间】:2009-01-04 06:15:40
【问题描述】:

谁有幸将 StructureMap(DI 框架)与 WCF 集成在一起?

我可以像这样在我的 WCF 服务的构造函数中返回默认实例,但显然并不理想。

public MemberService()
{
     this.memberRepository = StructureMap.ObjectFactory.GetInstance<IMemberRepository>();
}

我已经看到了这个 (http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/07/29/integrating-structuremap-with-wcf.aspx),但我认为它与最新的 2.5+ 版本的 StructureMap 不兼容,所以没有设置好它。

【问题讨论】:

  • 我知道这是一篇旧文章,但仍然在谷歌搜索中排名第一。我只是整理了一个样本,将来有人可能会发现有用吗? github.com/house9/SampleWcfClientWithStructureMap
  • 我能够让 WCF 和 StructureMap 与您链接到的 lostechies 文章一起工作

标签: wcf dependency-injection structuremap


【解决方案1】:

这已经讨论过here。您在提供的示例中遇到了哪些问题?无需在服务的构造函数中编写代码,而是在 IInstanceProvider 实现的 GetInstance 方法中编写代码。

【讨论】:

  • 好吧,我遇到了一个错误,此时无法找到 .With 方法 .With();。因为我对依赖注入很陌生,所以我不知道从那里去哪里。但是,我可能不知道函数(或扩展)所在的命名空间。
  • 我会看看你发给我的帖子上的文章,谢谢。这看起来很有趣,DIInstanceProvider : IInstanceProvider。
  • 也许我应该在看到 Ayende 的作品后搬到温莎@@castleproject.org/container/facilities/trunk/wcf/index.html
  • 一旦你拔掉了所有的杂草,这很简单,我这里有一个测试项目,它只是简单的 wcf 和结构图github.com/billCreativeD/WCF_With_DI
猜你喜欢
  • 2012-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 2022-01-18
  • 2015-09-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多