This project has moved. For the latest updates, please go here.

Using UnityWCF and WebAPI in the same application

Oct 9, 2013 at 3:13 PM

I've got a MVC4 application which contains WCF SOAP services and WebAPI controllers.

I've configured Unity.WCF using the the NuGet package and it's working as expected for the WCF service and I've also configured Unity for use with WebAPI using IDependencyResolver (I believe there's a better way to do this which I'll switch to soon: but the trouble is both these approaches have separate containers which I'm registering types with separately.

Is there a way to use the same container for both scenarios so I only have to configure the types in one place?

I'm using runtime code based mappings, perhaps it'd make sense to use XML based mappings which they can share but I think I prefer the type safety of code based mappings.
Oct 9, 2013 at 3:26 PM
I can pass both containers to a static method which configures the mappings but there's still two containers which seems wasteful.
Oct 9, 2013 at 3:36 PM
Another option would be to create my own implementation of UnityServiceHostFactory and reference a static shared UnityContainer.

This static container could then also be used in my Web API dependency resolver.

Any advice would be gratefully received.