views:

260

answers:

1

Hello, 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)?

+1  A: 

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.

Mark Seemann
I'll look at it, any news I'll post about. And thanks for the reply, following you at twitter right now =)
Diego Correa
I just finished a 11-page detailed walkthrough about this for my upcoming book. Hopefully, it will be available through the MEAP in a month or two...
Mark Seemann