Custom MVVM implementation Vs. PRISM

2020-01-26 06:52发布

问题:

This question is inspired from this closed question:

What does Prism actually offer the developer? And is it worth it?

I have already implemented my own custom MVVM implementations in enterprise applications. I am interested in knowing:

  • Why should I learn PRISM (specifically PRISM, not other MVVM frameworks)?
  • Benefits of PRISM over custom MVVM implementation and
  • Is it worth the investment in learning PRISM?

I hope this question is not subjective and everyone please don't get into arguments :)

回答1:

As with many frameworks that do a common task for you, you get:

  1. Tested by many more eyeballs: than just yourself. This (hopefully) includes unit tests, which you may or may not be doing while building your own framework.
  2. More readable for other developers: nobody else has experience with your custom MVVM framework. But if another developer joins your project, or joins your team, or joins your company, they can jump straight into Prism code.
  3. Better documentation: Along the same lines, anyone new joining likely has to learn the ropes by manually gathering the collective knowledge from your brain, and any other users on the team, and by looking at the source code. Third party frameworks have their own documentation, and tons more blog posts on the internet.
  4. Better community: You can ask questions on StackOverflow about "how do I do X with Prism?" You can't ask that with your custom framework.
  5. Likely more capable: by needing to serve more users than just you/your team, more features will have been added. If you need to do something MVVM-related that you've never done before, chances are support for it isn't built in to your own MVVM framework. But it's likely in Prism.
  6. Better structure: Let's say you wanted to do something MVVM-related but it wasn't in Prism. Very likely, there's a good reason for that! If something's not in a (reasonably-mature) framework made for working in a given domain, that's a sign that what you're trying to do is an unnatural or awkward way of approaching the problem. Working with your own framework, it's too easy to say "oh I'll add that feature," then 6 months later realize you made a huge mistake because this new feature makes your code very hard to follow or ends up being a vector for lots of bugs or whatnot.
  7. A CV line-item: I would have mixed feelings toward hiring someone who had "implemented and used custom MVVM framework." While it could mean they're smart, it could also indicate the dreaded "not built here syndrome." On the other hand, putting "Microsoft Prism MVVM Framework" among a huge list of technologies could be nice, but isn't a wow-er. The best of both worlds would be a longer bullet point, along the lines of "Deep understanding of the MVVM pattern, achieved by first implementing a toy MVVM framework for learning purposes before switching to MVVM Prism." Yes, the difference between these three isn't going to make or break your CV, and not-built-here syndrome is something that would hopefully come up in an interview, but it's just worth keeping in mind, especially if you're applying for a place that gets enough resumes they can afford to throw out anything that unnerves them slightly.


回答2:

PRISM can be interesting to you because it's more than an MVVM framework. Yes, a part of it can be considered in fact an MVVM framework (the NotificationObject, the EventAggregator and the Command objects are all examples of that), but it offers much more.

It allows you to create Composite Application of multiple loosely couples "Modules". It has a very flexible and extensible navigation framework (Region Navigation), offers integration with IoC containers (notably Unity and MEF) and a ton of other features.

Other than that, the documentation (including an ebook) is pretty good and comes with a lot of examples and quick starts. I believe it's worth the investment, which shouldn't be much, by the way.

Hope this helps :)



回答3:

Prism is an application composition framework with MVVM features, but is not (in my opinion) a fully-featured MVVM framework. It offers the minimum required to do some basic MVVM development.

See my previous answer to a similar question for a breakdown of application composition frameworks and MVVM frameworks. Most applications pick one from both categories:

Alternatives to Prism + MEF for modular MVVM apps



回答4:

With prism and MEF you can build highly extensible and maintainable. Net application. With each module with its own UI in its own separate dll. The only connection between your modules or extensions and MainUI will be region in which you will inject the UI of your extension. And believe me it's highly extensible and maintainable