WPF Magellan ViewModel IOC

865 Views Asked by At

I am trying to add a viewmodel to IoC but not much documentation is given on that subject by the project developers. I have added the following code to the app.xaml:

viewModelFactory.Register("ProfileCreateViewModel", () => new ProfileCreateView(), () => new ProfileCreateViewModel());
viewModelFactory.Register("ProfileEditViewModel", () => new ProfileEditView(), () => new ProfileEditViewModel(new Profile()));
viewModelFactory.Register("ProfileDeleteViewModel", () => new ProfileDeleteView(), () => new ProfileDeleteViewModel(new Profile()));

How do I resolve these viewmodels in controllers?

Please provide guidance, or any links or articles.

Thank you in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

I've found some information about mvvm and IoC in this question: MVVM: Tutorial from start to finish?
There is a link to a great video tutorial covering important things, that can help you greatfully when developing a WPF application. Here is the link: http://www.codeplex.com/CompositeWPF/Release/ProjectReleases.aspx?ReleaseId=19170 (direct download)
This presentation covers the basics of IoC (Unity), MVVM and data binding. Hope that will be helpful.
If you want more concrete answer then if you are using Unity, you can just apply a Dependency attribute to a property and Unity will automaticly perform the injection.

private ProfileCreateViewModel  _model;

[Dependency]
public ProfileCreateViewModel Model {
        set
        {
            _model = value;
            this.DataContext = _model;
        }
}