views:

300

answers:

1

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?

A: 

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

Diego Correa