Unity with WCF dependencies failing

Feb 18, 2011 at 5:26 PM

Hi Everyone!

I have a project with and MVC  UI Layer, then a services layer and a repositores layer. First of all the services were simply classes with dependencies on the repositories. It worked fine.

Today I added a new Project into the solution, a wcf service (we want to move all our services classes to WCF services).

I created the WCF Service, then created new classes for the InstanceProvider, InstanceProviderServiceBehavior, ServiceHost and ServiceHostFactory, inside the instanceprovider I'm using a singleton UnityProvider which is the same I've been using and working with.

when I try to create a new instance of my service client, it fails because it doesn't recognize a dependency, it says that the dependency is an interface and it can't be instantiated.

What could be happening? I think the container is fine but after a few hours trying I don't know for sure.



Feb 18, 2011 at 5:41 PM

Nevermind, I was able to fix it... it wasn't sharing the container between the fronend and the services layer and I though i was sharing it.


Mar 15, 2011 at 7:20 PM


I'm having similar issues when trying to share an existing Unity container with a new WCF project in my solution.

I have created the UnityInstanceProvider,UnityServiceBehavior,UnityServiceHost and UnityServiceHostFactory classes
, and I think everything is fine as far as starting and hosting the service.

When I have an empty constructor for my WCF service, I'm able to run the test methods on the service just fine, but
, when I include a constructor parameter in my WCF service (my dataService class), it fails.

Here's my WCF constructor:

public CHKShotWCFService(IWellHeaderService wellHeaderService)

    _wellHeaderService = wellHeaderService;
    //_wellHeaderService = new WellHeaderService();


Will you please explain how you're using the singleton UnityProvider, I think that may be where I'm doing something wrong.

Currently, i'm using a Bootstrapper project that I created in order to separate the unity container management.
It has all of the .RegisterType statements, including the .RegisterType<IWellHeaderService, WellHeaderService>() that
i'm trying to use with my WCF service.
Originally the BootStrapper code was incorporated into the main web application project, but I was having circular reference issues
, so it made sense to bust it out into it's own project, with the web app and the WCF service both referencing it.
Well, the web app is working fine, but the WCF service is still throwing "Assembly not found" errors.

I can include more of my source code if you need it, but I'll hold off for now, so I don't inundate you with code
you don't want to see.

Thanks in advance.




Mar 15, 2011 at 8:01 PM

Hi Keith, my main problem was that it was not sharing the some container between the front end project and the WCF service project, but then i realized it wasn't really necessary, I mean... exposing composition information into the front end app was not necessary at all.

So I used it's own Singleton Unity Provider object just for my WCF services, inside the WCF Services's web config is where is set up all the composition info. The downside is that i can't instantiate services from the front end project, so i created proxy objects. Those proxy objects are the way to comunicate with my services, then each proxy has a reference to the desired reference.

It is probably not the best solution but it is what we feel it was right, and we decoupled the services from the front end anyways.... so now changing the way my services works it is just changing the proxies.

Let me know if it helps or if you need some more info about our solution.