Why Controller ask for IoC Container?

May 2, 2012 at 8:13 AM
Edited May 2, 2012 at 8:15 AM

The framework is well designed. however something look strange about IoC dependency injection.

I just look at the EmailClient sample and found the ApplicationController "ask for" container (in constructor) and parse it into another controller. 

this class has a dependency on container.

public CreateEmailAccountController(CompositionContainer container, //...)

So you need to create a CompositionContainer for UnitTest?

Why not ask for things that really needed. (just IMO, there is no "best" or the "only" right way to design.)

public CreateEmailAccountController(EmailAccountsViewModel emailAccountViewModel, CreateEmailAccountViewModel createEmailAccountViewModel, //...

* I 've heard some discussion about parsing the whole container from GoogleTechTalks - The Clean Code Talks 

Coordinator
May 3, 2012 at 6:10 PM

Thank you for your feedback.

I know there are some discussions if the Container should be used in a Service Locator approach like it is done in the EmailClient application. Some people disagree with this approach and accept the Dependency Injection style only.

However, MEF comes with a limitation in .NET 4.0 which forces us to use it via Service Locator approach when we need to create “NonShared” objects (factory). They fixed this by introducing the ExportFactory class in .NET 4.5.

I show how to use MEF in a Dependency Injection only style in the download “WAF for .NET 4.5 (Experimental)”. Please have a look at this discussion post which describes the usage of the ExportFactory in the WAF sample applications.