简体   繁体   中英

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.

I followed Phil Haack's example on DI in ASP.NET MVC

The WCF service I have is called LogService. It implements ILogService.

The StructureMap.config looks like this:

<?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
Could not find an InstanceMemento for the requested InstanceKey "WcfLogService" of PluginFamily Yakinix.Admin.Web.LogService.ILogService

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. It's a worth try.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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