简体   繁体   English

无法使用StructureMap在ASP.NET MVC中注入WCF服务依赖项

[英]Cannot inject WCF Service dependency in ASP.NET MVC with StructureMap

I have troubles injecting a WCF ServiceClient to a Controller's constructor using StructureMap. 我很难使用StructureMap将WCF ServiceClient注入到控制器的构造函数中。

I followed Phil Haack's example on DI in ASP.NET MVC 我遵循了Phil Haack在ASP.NET MVC中关于DI的示例

The WCF service I have is called LogService. 我拥有的WCF服务称为LogService。 It implements ILogService. 它实现了ILogService。

The StructureMap.config looks like this: StructureMap.config看起来像这样:

<?xml version="1.0" encoding="utf-8" ?>
<StructureMap>
<Assembly Name="Yakinix.Admin.Web" />
<Assembly Name="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

<PluginFamily Type="System.Web.Mvc.IController" Assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
    <Plugin Type="Yakinix.Admin.Web.Controllers.HomeController" ConcreteKey="home" Assembly="Yakinix.Admin.Web" />
</PluginFamily>

<PluginFamily Type="Yakinix.Admin.Web.LogService.ILogService" Assembly="Yakinix.Admin.Web" DefaultKey="WcfLogService">
    <Plugin Assembly="Yakinix.Admin.Web" Type="Yakinix.Admin.Web.LogService.LogServiceClient" ConcreteKey="WcfLogService" />
</PluginFamily>
</StructureMap>

The error getting thrown is this: 被抛出的错误是这样的:

StructureMap Exception Code: 200 StructureMap异常代码:200
Could not find an InstanceMemento for the requested InstanceKey "WcfLogService" of PluginFamily Yakinix.Admin.Web.LogService.ILogService 找不到用于PluginFamily Yakinix.Admin.Web.LogService.ILogService的请求的InstanceKey“ WcfLogService”的InstanceMemento

Do you have any ideas? 你有什么想法?

I can't have an exact answer to your question but at dimecasts.com there's a screencast that details how to add IOC support to your WCF Services. 对于您的问题,我没有确切答案,但是在dimecasts.com上有一个截屏视频,详细介绍了如何在WCF服务中添加IOC支持。 It's a worth try. 这是值得尝试的。

http://dimecasts.net/Casts/CastDetails/150 http://dimecasts.net/Casts/CastDetails/150

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM