5
votes

I'm programming a WCF service that internally relies heavily on Inversion of Control. I would like to bootstrap / initialize my IoC container inside a custom ServiceHostFactory. I've read some examples of different hooks that are available, but none of them seem to work for me.

This approach is the one I'd prefer to use (custom IServiceBehavior, IInstanceProvider, ServiceHost and ServiceHostFactory) but the last step is to signal to the service to use my custom ServiceHostFactory inside my serivce's *.svc-file. I don't have one of those since the project type is a WCF Service Library - not a WCF Service Application. Is there a way I can tell WCF to use my ServiceHostFactory in the App.config file?

2
The link in the question is now broken, if anyone has its location that would be helpful. Thanks.BBauer42
@BBauer42 If you mean the one from the original question I think this is it: lostechies.com/jimmybogard/2008/07/30/…Ciddan
@Ciddan Did u solve this issue?Kob_24
@Kob_24 I don't really remember. It was 6 years ago, after all... AFAIC remember I gave up and switched the project over to be a Service Application instead of a Service Library.Ciddan
Thank you anyway i solved it.Kob_24

2 Answers

3
votes

As I don't see an anwer, I'll post what I found, which is not very encouraging.

All references to ServiceHostFactory point to the svc file and the Factory attribute, which is not what you are looking for.

This thread on MSDN even tells that it is not possible to do what you are trying to achieve.

Sorry...

7
votes

Ciddan, glad to see you found a resolution (albeit not perfect). I had the same question as you and finally settled with using IIS to host the service and wired up my Ioc custom classes (that reside in my WCF Service Library) using the serviceHostingEnvironment in my web.config. Something along these lines:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    <serviceActivations>
        <add relativeAddress="./Service1.svc" service="WcfServiceLibrary1.Service1"
          factory="WcfServiceLibrary1.IocServiceHostFactory, WcfServiceLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </serviceActivations>
</serviceHostingEnvironment>

"./Service1.svc" is my fileless service location where as WcfServiceLibrary1.Service1 is the concrete imp. I did hit a few stumbling blocks but in the end managed to encapsulate the Ioc from within the WCF Service Library.

This blog post was very helpful and has a few great tips.