Mar 6, 2013 at 12:30 PM
Edited Mar 7, 2013 at 7:32 PM
The only thing you have to do is let Catel do its job.
Take a look into this sample
Dependency Injection (DI) "via View-Model constructor" using Catel ServiceLocator works out of the box. The usage of third party containers like Unity is no longer required. Catel ServiceLocator supports DI.
The easy way to get DI (via View-Model constructor) works following this steps:
1) Make your window inherit from DataWindow (from Catel)
2) Follow the Catel naming convention for the View and its ViewModel for auto-initialization via ViewModelLocator.
3) Register the type into the default service locator instance before ViewModel initialization (for instance: Application Startup event)
In a "tipical" (non View-Model) scenario you can try this:
public interface IClass1
public class Class1 : IClass1
public interface IClass2
public class Class2 : IClass2
public Class2(IClass1 class1)
var serviceLocator = new ServiceLocator();
var class2 = serviceLocator.ResolveType<IClass2>();
and you should notice how an instance of Class1 is injected.