Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity and WCF Library: Where to load unity in a wcf library?

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

like image 398
mark smith Avatar asked Oct 08 '09 12:10

mark smith


1 Answers

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.

like image 131
Richard Szalay Avatar answered Sep 21 '22 22:09

Richard Szalay