views:

368

answers:

2

Hi there,

can anyone help?

I have created a WCF library (not application) and i will be hosting this in a SVC IIS page..

But i was wanting to load the unity stuff in generic place... I could load it in the global.asax but then its tied to the IIS Asp.net container and when doing TDD this part wouldn't execute so not of my resolves would work.

WCF Library is a pure class so i doubt i can use any events like OnStartup etc?

The only way i thought of what having the service inherit from a base class as well the interface which would call a static class of some kind and do the bootstrapping for unity..

I am a little lost, is this the only way or is there some way i am unaware of.

Basically the idea is ... Who ever calls the wcf library then the unity injection needs to happen..

Any ideas?

Thanks

A: 

You can use an IInstanceProvider to create service objects using Unity or another IOC container. Check this blog posts for details on how to do so.

Next you can use an IContractBehavior implemented as an Attribute to add the IInstanceProvider to the DispatchRuntime by setting the InstanceProvider in the ApplyDispatchBehavior method.

Maurice
+3  A: 

There are several ways of tackling this problem. Here are you two best options:

You can create a custom ServiceHost and override InitializeRuntime

You can create a class called ApplicationStart in your App_Code directory with a public static method AppInitialize (it's a bit of a smell, though):

public static class ApplicationStart
{
    public static void AppInitialize()
    {
        // Initialise IoC container
    }
}

Wenlong Dong has the other methods on his blog.

Richard Szalay
thank you, i am going to use InitializeRuntime
mark smith