I'm trying to build a line of business application using Silverlight. I felt like I was doing good then someone asked some questions. Immediately, I became really confused. I see discussions around Prism, Unity, and the Managed Extensibility Framework. However, they all look like they are trying to solve the same problem. Am I nuts? How do these three items compare / contrast with one another?
Thank you!
I recommend listening to the Herding Code podcasts with Glenn Block. (Part 1 and Part 2). He goes into this exactly subject, in much more detail than we can answer here.
That being said -
MEF and Unity are the two things that have quite a bit of overlap. Prism, in its default form, uses Unity for its dependency injection. You can use Prism with MEF, if you like, instead.
Prism is designed more for building composite applications. MEF, on the other hand, is about extensibility. There is definitely some overlap in goals here, but the basic driving factor is different.
In Prism's case, it's all about organizing known code.
MEF, on the other hand, is about discovering new code, and injecting it appropriately.
The newest guidance I've seen, which I fully agree with, was just posted on Glenn Block's blog: "If you are starting fresh you can use MEF for modularity, and general aspects of your composite app. Where appropriate you can pull in Prism bits."
http://blogs.msdn.com/gblock/archive/2009/12/02/mef-and-prism-to-be-or-not-to-be.aspx
There was this post today that discusses two scenarios where MEF and Prism work together to provide solutions. Each scenario leverages features that are not found in each, with 80/20 rules for those features that they do share.
Although there is overlap, the essential differences from a 30,000 view are
Unity is a IOC container. Use it to make your app more loosely coupled
Prism is gear toward making your UI more loosely coupled. As Reed mentioned, it uses Unity to help do this.
MEF is meant to make your code extensible. This helpful when having to interoperate with code that will be written by someone else. An example is if your application will support plugins.
Related
I'd like to start using IoC Container in an existing WPF application.
I need good performance, but from what I read, performance is really not an issue with most containers.
What I need most is a very easy to use container, that can be easily integrated into my app. I read recommendations about StructureMap (and the syntax looks great), but in their site it seems that there were no updates in the last 3 years, so I'm having some doubts about it.
Please provide recommendations with basic usage code samples (initialization + usage).
Edit
I'm not looking for a complete framework. I only need the IoC container ability, so many other alternatives exist. The last relevant discussion I found here is a few years old and I'd like to refresh it.
The answer really depends on personal preference and the details of your use case. Anyway, after using Unity, MEF (I know, not a real IoC container) and writing some individual solutions, I am now using Autofac and like it a lot. It is very easy to dig into and continuously reveals its advantages the longer you use it. It provides a fluent interface and is fast, compared to other frameworks (btw: The performance of your container can be a very important issue, depending on what you want to do). For usage and samples of Autofac see the link above.
Why I like it:
Easy to get into
Fluent interface
Supports open generics
Supports assembly scanning
Interoperability with MEF and other frameworks
Fast enough (Performance comparison of IoC containers)
Still, this is personal choice and there are other good solutions around, which might even be better for your special case.
And, more or less off-topic, I can recommend this article, especially the second half, for general considerations. It helped me a lot. So, just in case:
Article by Martin Fowler
Structuremap aint dead.
We are using it for our new green field project, and when v3 is out we may migrate to it. ATM using 2.6.4.
Your question is a shopping-list type question so it won't stay open long.
There are a number of IoC type frameworks, some of which require declarative or programmatic manipulation to do their work, some of which use code semantics to wire things up.
I would suggest you start with Unity1 until you get into the swing of things, then look to branch out into some of the more exotic frameworks when you can appreciate the differences between them.
1 Here is a good recent intro article: Visual Studio magazine: Creating Modularity with WPF, Prism and Unity
I need to write a composite WPF application with parts being potentially developed by other teams. These parts are actually indepndent applications now, and we want to put them under common "roof".
Two main options I consider for composition is Prism modules vs. MEF parts, and I am not 100% sure which to choose, since both have pros and cons. Note, that this is NOT about the IoC container choice, this is about discovering pluggable components. I am pretty much settled on the opinion that MEF is not to be used as an IoC container.
If I go with MEF for pluggability, the biggest plus is that it is baked in into the .NET framework, so there are no versioning issues. From the other hand, I will have to (partialy) reinvent mechanisms such as Prism region managers and other UI composition features.
If I go with Prism modules, I get much richer integration functionality (regions, event aggregator, etc.), but for that to work everyone must be on the same version of Prism, and preferrably the same version of Unity, to avoid unpleasant surprises. Upgrading to a next version of Prism/Unity will thus become a challenge.
I would like to hear your opinion about the choice.
I had a similar choice several years ago and choose Prism. I'm glad that I did. Unless I was building a trivial app, I wouldn't consider doing it without Prism. You can have different dev groups work in near isolation on their modules and integrate them when complete. The same goes for bugs and requirement changes: much easier to handle.
Yes, you'll want everyone working on the same version, but that's a small price to pay and very common. If you have specific questions, let me know.
It's possible to find tutorials on MVVM and DI, somewhat harder about getting Data from database properly into GUI.
Finding something that talks about all these things and how they integrate is near impossible.
I guess some people will say that it doesn't matter and all stands independently but I don't believe it. Especially considering MVVM and Data as I find keeping a tight grip on data managing while doing MVVM to be the hardest part.
So is there anything I could use, and I don't wan't some small simple problem solved but something near complete, at least steps from DB to GUI dynamically done. I'm willing to pay for such a book.
You could look at Prism guidance provided by Microsoft Patterns & Practice group. Prism is actually complete architectural approach to build enterprise level solutions. But it contains StockTrader Reference Implementation application that is built using DI, MVVM and includes interaction with data storage (they use XML files as data storage to provide easy distribution, but it really doesn't matter what data storage is used). Also, the guidance contains several small quickstart projects which emphasize particular part of the architecture. There is comprehensive documentation and active community around Prism, so you can find answers to any question. And it is completely free.
Among many other things my book Dependency Injection in .NET discusses all of those things. However, the subjects is DI first and foremost, with MVVM and data access only incidentals. However, you may find some of the code examples accompanying the book helpful.
In addition to Prism guidance already mentioned, I highly recommend Karl Shifflett's MVVM In-the-Box tutorial. It has great content and also encourages you to experiment with code as you progress through the topics (it is integrated with Visual Studio).
You might be interested in the BookLibrary sample application of the WPF Application Framework (WAF). The BookLibrary shows how to use MVVM, DI with MEF and data management with Entity Framework and SQL Compact Edition.
I'm working on Silverlight, of course I use MVVM. I found many problems but I can create work-around solution for them (some of these solution is not elegant at all), now I think it's time to bring some framework to help me.
I need functions that listed below.
Dependency Injection
Navigation
Callback
Messaging
Bind event to Command
Testability
As I know, there are many Framework out there, such as, Jounce, MVVMLight and Prism. I want to know which framework is suitable for my need?
When it comes to dependency injection I'd rather use MEF
which greatly simplifies code. As for the rest of the functions , currently I'm working with MVVMLight and I haven't faced any problem (although I'm not familiar with Jounce and Prism)
I think that you should consider the scale of the application. If it is a relatively small application that is unlikely to grow I would choose MVVMLight.
For a larger LOB application I would consider PRISM or Caliburn. I would also recommend reading blog posts by John Papa and Jeremy MIller on MVVM, Screens and Coordinators. Their ideas and insights helped enormously in a large scale Silverlight project I've built.
In WPF Prism is great, in Silverlight Jounce is the best by far. Its is very well integrated with MEF , very lightweight, elegant and stable. It also provides nice implementation to support complex events workflow scenarios, VisualStateManager in ViewModel (love that one), validation, debugging and unit testing; Used it in some quite complex projects and was happy I chose it.
I'm looking for code of full applications that (1) use the MVVM pattern and (2) are approachable for WPF/Silverlight/MVVM beginners. So far I have only found:
Crack.NET - A runtime debugging and scripting tool (useful but quite complicated)
CipherText - WPF Password Manager (perfect but written in VB.NET)
What are some others?
preferably smaller helper apps or tools that use MVVM but that have a completed feel, perhaps with WPF/Silverlight graphic/animation goodness, etc. which show not only the MVVM concepts being used but in a context of a real-world, completed application
My Contribution
Thanks for all the tips, I collected together a list of 15+ MVVM code examples and posted the here:
Overview of WPF/Silverlight code examples that help you learn MVVM.
I too class myself as a beginner in MVVM developing a large scale application for about a month now. I'm over most of the main hurdles, but keep getting confused up by a few things.
Be careful with the suggestions from Kent. They'll get you started, but the subtle differences in Silverlight and WPF will trip you up occasionally (triggers are one).
I don't know of any full sites, but I started with the Composite Application Guidance and PRISM libraries. These a little too cumbersome for a 'beginner' and just MVVM, but some of the concepts are very useful (event aggregator for example).
I suggest that you read blogs by Josh Twist, Josh Smith, Shaun Wildermuth and Nikhil Kothari. These guys are very knowledgeable. They are also very open to answering questions too.
What is your development background? Some of the concepts surrounding method calls, responses and delegation are a real break from "traditional sequential" coding techniques.
Given the question, you may be interested in the current effort going on to create a "Pet Shop" type reference implementation for M-V-VM. You can join the conversation or follow progress here.
I've been using MVVM for the last couple of months on a project and it's been fantastic. I've been doing UI work for over 12 years and it's the best thing I've come across.
I have been using MVVM for about 2 years now, and I can say that it is a resounding success. I have shipped one large-scale medical imaging solution using MVVM in Silverlight. I am also about to ship a complicated WPF application using Prism and MVVM extensively. In fact, I don't know how I'd achieve some of my problems elegantly without MVVM in this more recent application.
+1 on MVVM. It works. It is testable. It is extensible. It facilitates developer-designer workflows. It ALSO doesn't have to be messy and plumbing-heavy.
In addition, I created a medium-sized Silverlight application using MVVM for the CodeMash conference in January. You can see it and get the source code here.
Try this one. Also, Family.Show may be useful.
The WPF Disciples group has decided to create a real-world MVVM + Mediator reference application similar to the Pet Shop refence application for Web Apps. Your can follow the development on codeplex here