I’m looking for a working sample of an ASP.NET MVC web application that uses Unity and calls an WCF service. I’ve looked at a lot of explanations on how to add dependency injection to WCF services but frankly I’m a little over my head here. It doesn’t help that I’m new to WCF services as well.
I’m currently using Unity with Contructor injection for our ASP.NET MVC applications but so far we aren’t using any WCF Web Services. The plan is to start using web services and I’m very confused on how to incorporate Unity with them.
I would love a nice working sample that I could walk through to better understand how to go about it.
It sounds like you’re already injecting your MVC Controllers using Unity and all you want to do is start injecting the WCF services you host as well. To inject WCF services, you need to use an
IInstanceProvider.Complete working solution is here:
http://orand.blogspot.com/2006/10/wcf-service-dependency-injection.html
You need 4 very very simple classes:
define those, specify your new ServiceHostFactory:
and you’re done.