1

I am trying to use dependency injection with WCF REST (WebGet) and am having trouble understanding where I would use Unity to build my object to host the web service.

I have seen many examples all over the web, but they seem to all be hosting the service in a console app or Windows service.

Currently my config file looks like this:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Services.MyRestService">
        <endpoint address="http://localhost:8732/api" binding="webHttpBinding" contract="Shared.Services.IMyRestService"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

Currently the way it works is using the built in WCF service host in Visual Studio. However, I'd like to run this in IIS and use Unity to configure my container. Now I am using "bastard injection" to get the job done, but would like to use Unity to supply the data provider implementation, etc.

My question is, what configuration changes do I need to make to host this in IIS and also where do I configure the container and let IIS know about it.

There are no SVC files as this is a WCF Service Library.

Thanks in advance!

2
  • Is this regular WCF or the WCF web API? Commented Jan 30, 2012 at 14:03
  • The simple way to use your DI would be to write a custom service host that would inject this for you. Commented Jan 30, 2012 at 14:46

2 Answers 2

2

The "normal" way to do this would be to implement a custom IInstanceProvider WCF extension point, and add it through configuration. I've only done this with regular SOAP endpoints, but I think it would work the same for WebAPI.

Couple links that might help:

The 2nd link covers some of the XML configuration stuff for adding a custom IInstanceProvider to the behavior.

Sign up to request clarification or add additional context in comments.

Comments

0

With WCF REST you would use WebServiceFactory and WebServiceHost as your base classes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.