5

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

Mel
  • 2,337
  • 19
  • 25
Diego Correa
  • 767
  • 2
  • 9
  • 22
  • Sure, I'm open to others approaches just said that I'll look more deeper in what he said, anyway. Anyone have another suggestion on the question? – Diego Correa Feb 24 '10 at 01:01

1 Answers1

2

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
  • 225,310
  • 48
  • 427
  • 736
  • I'll look at it, any news I'll post about. And thanks for the reply, following you at twitter right now =) – Diego Correa Feb 23 '10 at 23:17
  • 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 Feb 26 '10 at 18:31