Unity 2.1 - Container.BuildUp does NOT call any InjectionMethodAttribute methods

Jun 6, 2011 at 5:29 PM

I have downloaded the new Unity 2.1 release.  I have a very basic Silverlight Navigation app and when a Page is navigated to, I have some code which calls the Container.BuildUp method to Inject any dependencies on the new Page.  However, the method I have marked as "InjectionMethod" is NEVER called.  Is there a reason this is broken in this release?

Jun 7, 2011 at 2:22 AM


It would be nice if you can provide us the relevant code.


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.

Aug 16, 2011 at 9:15 AM

In my "Shell.xaml" which is the RootVisual, there is a navigation frame control.  Basically I'm hooking into the"PageNavigated" event and attempting to "BuildUp" the Page's dependencies.

private void OnPageNavigated(object sender, NavigationEventArgs e)

And in the Page, here's the source:

public void InjectDependencies(IUnityContainer container) { container.BuildUp(this.someChildUserControl); }

Not, that complicated. But the Injection method NEVER gets called.

Aug 17, 2011 at 12:47 AM

Change the call to:

this.IoC.BuildUp(e.Content, e.Content.GetType());

This is a known flaw in the API design; unfortunately back compat concerns push against fixing it.


Aug 18, 2011 at 2:02 AM

Great, that works!  Except your code snippet was backwards, should be like this (but I got the gist)...

this.IoC.BuildUp(e.Content.GetType(), e.Content);