Xaml and Dependency Injection

Topics: Prism v2 - Silverlight 2
Apr 30, 2009 at 2:41 PM
Edited Apr 30, 2009 at 3:06 PM
Is there a way to reference a class that uses dependency injection in Xaml. Like the following:

 <command:MyClass  x:Name="MyClass" />





May 4, 2009 at 8:01 PM

Hi Robb,


I do not know the specifics of your class or application, but to be able to instantiate your classes from XAML, one of the requirements is that the class must be public and support a default (parameterless) public constructor.

This constructor will be the one used to instantiate your class, and this class will not be instantiated through your container (for example Unity) in this situation. Therefore, dependency injection will not be performed in case you instantiate the class from XAML.


This article provides more details about XAML and Custom Classes. For more information about Unity you might check Unity Application Block at MSDN.


Please let me know if this helps.


Damian Schenkelman