Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOA Architecture with WCF + IOC Structuremap

I'm a little new to DI containers like StructureMap and I've been using it for a short time with asp.net mvc applications. Now I'm splitting my architecture that will have a WCF service layer and a sort of consumers like ASP.NET MVC app, Silverlight App, And Winfors/WPF App. When using SM with asp.net mvc I've been initializing the IOC by the app startup of the asp.net mvc, now, using for many project I can't think a good place where the IOC config should be located. I want to make DI in the services layer too(injecting Repositories).

In this scenario, where I do load my IOC config and how I'll use across the projects(like the controller factory is needed only in the asp.net mvc app)?

like image 910
Diego Correa Avatar asked Nov 05 '22 16:11

Diego Correa


1 Answers

You create and configure a container per application.

If you have an ASP.NET MVC site, you create and configure a container instance in Global.asax.

In a WCF service you can write a custom ServiceHostFactory that spins up a custom ServiceHost that again attaches an appropriate IInstanceProvider that uses a container instance to wire up the WCF service. That sounds complicated, and it definitely is more complicated than it ought to be. I have previously touched on this subject in a completely different context, but this blog post should give you some hints - particularly if you keep in mind that delegates are anonymous interfaces.

like image 127
Mark Seemann Avatar answered Nov 15 '22 07:11

Mark Seemann