Resolving windows in Structure Map or how to manage multiple windows in WPF MVVM?

前端 未结 3 812
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 21:09

I have been reading Mark Seeman\'s book on dependency injection in .NET and I\'m struggling to configure composition root in WPF application.

My container will be re

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 21:55

    Pushing container instance through constructor is a bad idea in 99% of cases, because container is a service locator. The main disadvantages of this approach are:

    • dependency from concrete implementation of container;
    • unclear API of your classes, which also leads to fragile unit tests.

    There are many ways to create window in MVVM fashion:

    1. using Mediators (like IMessenger in MvvmLight, IEventAggregator in Caliburn.Micro);
    2. using special IDialogService;
    3. using attached behaviours;
    4. using Action that inserted via ViewModel constructor;
    5. using Controllers.

提交回复
热议问题