c# - Benefit of IoC container in MVVMLight -


What is the benefit of IOC container in MOVVM light? What is the benefit of ViewModelLocator? Why not start the visual-model directly in XAM file like below?

  & lt; UserControl & gt; & Lt; UserControl.DataContext & gt; & Lt; VM: MainViewModel / & gt; & Lt; /UserControl.DataContext> & Lt ;! - Other user control element here - & gt; & Lt; / UserControl & gt; It is perfectly ok to install the visual model in Xaml, but there are some things in this account ...  
  • When you use Xaml for the visual model, the VM constructor is the main The window is called during the InitializeComponent method. This means that VM will be built on the UI thread. Besides, when you use XML, it's like 'hard-coding' VM and it defeats late bond and module detection, which is an integral role in large composite applications.
  • relates to a certain extent from the previous point of view, some teams have to decrypt everything and use the configuration file, by telling them which key should be given immediately. This approach is particularly useful if you want to do isolation test.

For small, only WPF applications that want to use MVVM, the Xaml approach is OK; But as the app matured, eventually it will be called for a more industrial power outlook. And that is where the IoC container is necessary.


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -