What are the strengths and weaknesses of various M

2020-07-23 05:58发布

问题:

What are the strengths and weaknesses of various MVVM frameworks for Silverlight?

I know similar questions have been asked before, but the field is moving quickly and the answers given are rapidly out of date.

I'm specifically looking for a brief assessment of the following frameworks -

  • Prism
  • Caliburn
  • Cinch
  • Goldlight
  • MFedMVVM
  • MVVM Light
  • nRoute
  • Structured MVVM

...plus any others that anyone is aware of.

回答1:

The disadvantage of any framework is the same: It's someone else's code and it's someone else's implementation of the pattern. You're ceding control of the solution to someone else's code. If you're comfortable with that, by all means, go for it.

But MVVM is a really simple pattern to grasp. Implementing it is actually pretty trivial; WPF and Silverlight have baked in most of the core components you need to make binding work, and thus make MVVM work.

I've found that all I really need to do MVVM is an event aggregator for messaging across classes, a base view model class to handle the repetition of coding INotifyPropertyChanged, and then an IoC container for wiring up my dependencies. That's about it.

After my experience with the Component Application UI Block, I tend to shy away from anyone else's "framework". Especially if I can write the core bits myself in short order.

We do MVVM on our projects at my current job and my infrastructure is literally a couple of classes and interface for just what I stated above.



回答2:

I cannot speak for the other frameworks listed but I can say that I've had great success with the MVVM Light Toolkit. I sympahize with the perspective that you can "roll your own" framework when you need it but MVVM Light is small and inobtrusive; it doesn't take over your application architecture but just provides a few basic necessities of MVVM:

  1. RelayCommand - Command class that you can use for just about anything

  2. Messaging - Ability to do messaging and message aggregation

  3. ViewModelBase - Implements INotifyPropertyChanged etc...

  4. ViewModelLocator - A straightforward utility for injecting ViewModels into Views.

I think the reaction to frameworks caused by something like the Component Application UI Block (and its Silverlight cousin, Prism) should be allayed by a framework as lightweight and straightforward as this one.