.NET & Funky Fresh

Syndication

News

  • <script type="text/javascript" src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&amp;MarketPlace=US&amp;ID=V20070822/US/bluspiconinc-20/8001/8b68bf4b-6724-40e7-99a5-a6decf6d8648"> </script>
“Build Your Own MVVM Framework” is Online

Yesterday I delivered my talk, “Build Your Own MVVM Framework,” at Mix.  Thanks to all who came out to listen and allow me a short time to share some of my ideas.  I’m very grateful to have had this opportunity.  Thanks also to all who voted for the talk.  If you were not able to make it in person, Microsoft has made the video of the session available online along with the slides.  You can now watch it at http://live.visitmix.com/MIX10/Sessions/EX15. I’m also providing the full source code for the sample application as an attachment to this blog post.  If you look at the source code, there are a few things to keep in mind:

  • The backend is fake.
  • The framework is not intended to be used “as is.” It was built for this specific application. You should adapt it to your application, or use Caliburn, which was designed for general use.
  • There are a number of other interesting things in the sample, which I did not discuss in the talk. It’s worth poking around a little bit…

I hope this talk and sample give you some ideas. I would love to hear your feedback.  Enjoy!


Posted 03-16-2010 6:37 PM by Rob Eisenberg

[Advertisement]

Comments

Sven wrote re: “Build Your Own MVVM Framework” is Online
on 03-17-2010 4:44 AM

I can't begin to express my gratitude for being able to watch this video. I've been trying to apply MVVM in my own WPF app and struggling mightily (lot of repetitive code) up to a few months ago when I discovered RelayCommand which greatly improved things. I'm still bummed out by not being able to even preview (let alone design) DataTemplates in cider. Or maybe I'm doing something wrong...

Anyway I'm up to a point where I'm comfortably using DataTemplates and RelayCommands but the things you showed in your video were just mindblowing ! I especially like the Co-routine stuff, just a bummer that we're a VB.NET shop and I can't use that stuff without writing part of my code in C#.

I have a point of criticism though, I hope you don't take it too personally. I don't know you personally so it may just be your style but I really felt at times you weren't very keen on being there (on stage that is). Or maybe I'm biased from watching some of the other sessions where the speakers seem to be high-on diet-coke or something...

Anyway, apart from that, easily the most interesting session so far at mix ! 5/5 !

Sven

Rob Eisenberg wrote re: “Build Your Own MVVM Framework” is Online
on 03-17-2010 11:34 AM

Glad you enjoyed the talk! Your criticism is well taken.I have a pretty mellow personality and I tend to speak with a very monotone voice by nature.  I think that contributes to the sense you had. I was planning on watching the video myself in order to do a bit of self analysis. I'll keep what you said in mind.  Thanks!

DevelopMENTAL Madness wrote MVVM: Going it alone
on 03-17-2010 2:44 PM

MVVM: Going it alone

DaRage wrote re: “Build Your Own MVVM Framework” is Online
on 03-17-2010 4:31 PM

I watched the whole thing and all I can say is Amazing!! really. Good job.

What I loved most is the composability of the UI where the work is distributed on small objects rather than a big script that coordinates the UI behavior. And with the way and style you did it is stunningly clean.

I also loved Coroutines. I actually discovered this not a long ago and started using to return IDisposable types  so that the calling code doesn't have to worry about disposing them itself. Of course you took it much further with asynchronous calls. I think this feature is much under utilized in C# while continuations  are a natural part of other languages. I thought of writing a blog post about it but I don't have a blog! may be you can.

The only thing that worried me a bit is maybe the over use of conventions (you mentioned it 42 times). Don't you think this can create black boxes and hurt maintainability?

Again Amazing.. thanks.

Kelly Brownsberger wrote re: “Build Your Own MVVM Framework” is Online
on 03-17-2010 6:08 PM

I really dug your talk yesterday - thanks for posting the code.

Your convention over config style brings memories of Jeremy Miller, Build-Your-Own-Cab, and Opinionated-MVC (FubuMVC).  I love it.

The part of this (and other architectures I've seen) that feels weird is what I'd call "too MEF'ed".  I read somewhere from Glen that MEF is for managing unknown dependencies where IOC containers are for managing known dependencies.  That resonated well with me.  Most of the time, I think of many of these V->VM->M are known dependencies.  It seems more straightforward to me to let my IOC manage this wireup.   Bbut in my experience it's hard to use just a little bit of MEF.  For me it tends to quickly turn into an all-or-nothing thing where my IOC and MEF are fighting each other.  Then any simplicity I gain it replaced with complexity of having two containers managing object construction and lifetime.  Anyway... tangent.

Loved the talk and thanks again

-kelly

MichaelD! wrote re: “Build Your Own MVVM Framework” is Online
on 03-19-2010 1:31 PM

Rob:

This was easily my 2nd favorite session behind "Prototyping Rich Silverlight Applications w/ SketchFlow."  You have a talent not only for writing seriously awesome code, but also for public speaking as well.  Bravo.

Ward Bell wrote re: “Build Your Own MVVM Framework” is Online
on 03-19-2010 2:10 PM

Great talk. Shows how adopting conventions and a little bit of code (~500 lines) can help you sweep your application XAML  and  code-behind house clean of repeative gunk. Increase coding speed and testability while by-passing the drag-and-drop binding exercise completely.

A terrific foundation for grasping Caliburn if that's where you want to go.

I'm telling everyone I know to look at this talk.

Mcsean wrote re: “Build Your Own MVVM Framework” is Online
on 03-20-2010 8:46 AM

It's a great presentation! Can't say enough about it, and hope to see more of your talk in the future!

Caliburn eh?  definitely checking it out!

Pontus Munck wrote re: “Build Your Own MVVM Framework” is Online
on 03-20-2010 9:44 AM

This session was one of my favorites at Mix 10. Pretty advanced stuff but I like that. Your solutions are very clean and smart. I've always found Caliburn a bit hard to get a grip on because of its size. This talk really explained a lot of details in a great way and helps immensely when trying to decide whether to actually use Caliburn or just implement a few features ourselves to suit our project. Thanks!

Jimit Ndiaye wrote re: “Build Your Own MVVM Framework” is Online
on 03-21-2010 7:58 PM

Great presentation! Totally eliminated to any barriers I'd initially had towards embracing Caliburn.

I especially liked the part about coroutines - simply beautiful!

One smll problem though - the attachced zip file containing the samples from the presentation seems to be corrupt.

Krzysztof Kozmic wrote Validate your conventions.
on 03-22-2010 4:18 AM

I'm a big proponent of the whole Convention over configuration idea. I give up some meticulous control

zihotki wrote re: “Build Your Own MVVM Framework” is Online
on 03-22-2010 1:00 PM

I second Kelly and prefer to use MEF to load unknown dependencies like plugins, extensions, etc. But anyway, your session is one of my favorites on MIX10. Thanks a lot for you hard work!

RWilkerson wrote re: “Build Your Own MVVM Framework” is Online
on 03-24-2010 8:36 AM

Excellent talk.   Your delivery and content were spot on.  I really appreciate the fact that your sample was feature rich enough to illustrate the points without being overwhelming in details.

marcello.s wrote re: “Build Your Own MVVM Framework” is Online
on 03-24-2010 2:43 PM

Thank you very much for sharing your ideas and your code. Having a strong NET 2.0 background and writing on top of 10+ years old software stacks I see myself facing a steep learning curve ahead. With that experience I would do anything to move away from the old Ueberclass with static methods. I knew there exists something like an MVC/MVP pattern in the new GUI world, but I never really got myself involved until now. With touchscreens becoming a commodity nowadays we are re-basing our products, high precision medical device machinery, and want to welcome scientists with more intuitive user experiences.

Thanks again for your hard work!

OctoCoder wrote re: “Build Your Own MVVM Framework” is Online
on 03-25-2010 2:26 AM

I was like oh, another MVVM video but why not watch it while i clean up.  Definately a decision which gave me a fresh look at mvvm.

Anthony wrote re: “Build Your Own MVVM Framework” is Online
on 03-25-2010 3:47 PM

What  license are you releasing the code under? MIT?

Kathleen wrote re: “Build Your Own MVVM Framework” is Online
on 03-26-2010 8:59 AM

I just watched this talk on the video. Thanks so much for putting this together, it was great fun.

The problem of avoiding async code can be solved a couple of ways. My question is whether you explored System.Reactive and found it coming up short (in which case I'd love to know why) or whether you hadn't tried it in  place of the co-routies. In certian aspects it would be simpler. Perhaps not in other aspects.

Duncan wrote re: “Build Your Own MVVM Framework” is Online
on 03-30-2010 5:27 PM

Thanks for posting... great thought food.

My first reaction to encoding conventions like that was 'eewwww'. There has to be a better way... but you know I've been thinking about it for 2 days and still haven't come up with one.

What I really want to be able to do is register my Views directly into some kind of view manager using Xaml and tag them up with the ViewModel they relate to.

Assumptions:

A view is always written with a specific viewmodel in mind.

A new ui should be buildable without touching the viewmodels.

I don't want to have to rely on conventions like this.

I don't want to hard code a list of all the mappings.

Buggered if I can find a solution though.

What would be ideal would be:

[UserControl cst:MapsToModel="SomeViewModel"]

[/UserControl]

But... yeah...

So for now it looks like convention is the way to go :(

Christopher Bennage wrote re: “Build Your Own MVVM Framework” is Online
on 03-30-2010 11:36 PM

@Kathleen Reactive wasn't around (or at least wasn't well known) when the "coroutines" were added to Caliburn. Also, Rx has a different focus (events) from what was needed for Caliburn.  

Brownsblogging wrote My take on the ViewModelLocator pattern for MVVM
on 03-31-2010 10:51 PM

My take on the ViewModelLocator pattern for MVVM

Julian Birch wrote re: “Build Your Own MVVM Framework” is Online
on 04-01-2010 4:42 PM

Hi, I've done a write-up of the co-routine trick with a couple of possible variations.  I hope you like it.

Julian

www.colourcoding.net/.../rob-eisenbergs-co-routine-trick-in-retlang.aspx

Rob Eisenberg wrote re: “Build Your Own MVVM Framework” is Online
on 04-01-2010 5:08 PM

Julian, very nice! Believe it or not, I looked at Retlang a long time ago (it seems) when I was pondering how I would handle multi-threading in Caliburn. So, it was really fun to see how you combined the concepts.  Your final Action enumerator is very cool. :)

Juan Pedro wrote re: “Build Your Own MVVM Framework” is Online
on 04-04-2010 1:17 PM

Awesome piece of work! Rob, what should be the minimum changes in the framework to work with a WPF app instead of Silverlight.

Rob Eisenberg wrote re: “Build Your Own MVVM Framework” is Online
on 04-04-2010 1:48 PM

The framework should not require too many changes to work with WPF. Mainly, some of the controls registered in the ViewModelBinder don't exist in WPF.  You will have to remove/replace them. Other than that, you should be good to go.

Joan Miro wrote re: “Build Your Own MVVM Framework” is Online
on 04-06-2010 2:40 AM

What an excellent Mix video! Great sample MVVM framework, clearly explained and demonstrated. Thanks - it's given me a great number of ideas to try out.

Thanks again.

Nkosi Henry (from Trinidad & Tobago W.I.) wrote re: “Build Your Own MVVM Framework” is Online
on 04-06-2010 6:42 PM

Just when i think i have a grasp if MVVM i come across something new that simply blows my mind. I am ever grateful for having come across your video. It has surely peaked my interest that much more. It was also reassuring when i saw you using concepts that I have adopted. At least I know I'm on the right track.

Eric Bush wrote re: “Build Your Own MVVM Framework” is Online
on 04-07-2010 3:19 PM

I can't get the sample to build. Do I need to install Unity or MEF first?

'System.ComponentModel.Composition.Hosting.CompositionHost' does not contain a definition for 'Initialize'  IoC.cs               line 12

'System.Windows.Window' does not contain a definition for 'Closing' and no extension method 'Closing' accepting a first argument of type 'System.Windows.Window' could be found (are you missing a using directive or an assembly reference?)               App.xaml.cs line 25

Rob Eisenberg wrote re: “Build Your Own MVVM Framework” is Online
on 04-07-2010 3:36 PM

It sounds like you don't have the Silverlight 4 RC installed.  Can you confirm?

Eric Bush wrote re: “Build Your Own MVVM Framework” is Online
on 04-08-2010 11:53 AM

For my build issue above...Yes, I have it working now.

I did need the RC of VS 2010. I also installed the Silverlight 4 latest and the latest Silverlight toolkit.

Thanks.

Krzysztof Kozmic wrote Build your conventions
on 04-08-2010 12:26 PM

Continuing the theme of conventions in code; I talked about validating the conventions, but I didn't

Eric Bush wrote re: “Build Your Own MVVM Framework” is Online
on 04-08-2010 2:42 PM

Looking at the code I can't figure out how the ShellView transitioningContentControl gets the view model "ActiveScreen" property (in ScreenConductor) bound to a property of the control called View.ModelProperty. The XAML is

               <tl:TransitioningContentControl x:Name="ActiveScreen"

                     Transition="UpTransition"

                      Margin="40"/>

But, where is the attached propertyView.Model on it?

Rob Eisenberg wrote re: “Build Your Own MVVM Framework” is Online
on 04-08-2010 2:55 PM

That's a great question! Have a look in the ViewModelBinder.  You will notice that the convention for the TransitioningContentControl is to actually data bind to a *custom* attached property, View.Model. This behavior is the default for ContentControl as well. By doing this, we basically set up a mechanism by which we can compose the entire UI!

Eric Bush wrote re: “Build Your Own MVVM Framework” is Online
on 04-08-2010 3:14 PM

How does this line in the ViewModelBinder works?

               if(((FrameworkElement)foundControl).GetBindingExpression(boundProperty) != null)

                   continue;

Since the TransitioningContentControl does not contain this attached property.

It would seem you would have to have done the following to have it available.

              <tl:TransitioningContentControl x:Name="ActiveScreen"

                    Transition="UpTransition"

                     Margin="40"

vm:View.Model=\"{Binding}\"/>

Rob Eisenberg wrote re: “Build Your Own MVVM Framework” is Online
on 04-08-2010 3:21 PM

That line of code just checks to see if there is an existing binding on the provided property.  In other words, "is View.Model already databound for this control." Because, if it is, we don't want to override it. But, in this case, it isn't. So we want to add it.  It doesn't actually matter whether the property is on the control or not since DependencyObject basically acts like a property bag. So, if the property doesn't exist, neither does the binding expression.

Chris Shepherd wrote re: “Build Your Own MVVM Framework” is Online
on 04-20-2010 12:27 PM

Great talk!

During it you mentioned you had an idea for how to maintain 'blendability' when using conventions such as these. I was just wondering what you were planning ? :)

Jeremy Likness' Blog wrote Transactions with MVVM
on 04-22-2010 9:56 PM

One objection to MVVM I often hear is that it doesn't manage transactions well. I'm not talking about

Jeremy Likness' Blog wrote MVVM Coding by Convention (Convention over Configuration)
on 05-12-2010 6:26 AM

Convention-based programming is an interesting model. In essence, it attempts to reduce the potential

Rich wrote re: “Build Your Own MVVM Framework” is Online
on 06-02-2010 6:44 PM

Hey Rob, nice work man!  Definitely some code kung foo!

Say, like a few others, I'm concerned about this approach when it comes to plugins. I'm currently using a "glenn block" approach with MEF and DeploymentCatalog to add/remove Xaps.  I have found this mechanism to work quite well. That said, if I could couple that with your convention (and other) designs I could have the best of both worlds that would make plugin development quick and easy.

Do you have an example where you have separate "plugin" projects working with your design?  If you do, I'm all in...and it could well set a standard in how many SL apps are created.

Cheers!

Julian H wrote re: “Build Your Own MVVM Framework” is Online
on 06-07-2010 11:06 AM

Hi Rob

To reiterate what everybody has said.

Your MVVM presentation was great.

I am new to Silverlight and C#, so my ignorance some times becomes a bit of a stumbling block.

I have pulled your whole framework to pieces and implemented it piece by piece into my test application.

I think your idea of convention over configuaration is great.

I however am feeling like a mechanic who has stripped down an engine and does not know where all the parts go.

I have spent a lot of time learning RIA services so I want to keep those in my framework.

I am also naming content controls in a certain way so that I can fill these in using your strategy at run-time. So on every page I have a header and footer and these are plugged in by the framework at run time.

But now the type of problem I face is how do I get these components and their modelviews to communicate with each other.

Maybe what I am saying is: are you not thinking of doing more comment on the actual workings of the Mix framework - After all you did encourage us to build our own frameworks - now I feel like I am up the creek without a paddle. Help!

Would you think reviewing one small section at a time of the framework and perhaps soliciting comment and questions and incrementally building up the pieces.

I would be more than happy to subscribe to such a service.

Kind regards Julian H

Rob Eisenberg wrote re: “Build Your Own MVVM Framework” is Online
on 06-07-2010 11:21 AM

I am planning something :) But, I can't give you the details just yet. Stay tuned...

Mark Roxberry wrote re: “Build Your Own MVVM Framework” is Online
on 06-11-2010 12:11 PM

Excellent stuff!  I have a need for a lightweight MVVM architecture and this is a great inspiration.

How would you handle binding events?  I have views that I want to load data and do other things on load.  I was going to add another Bind in the ViewBinder base with EventInfo and maybe something like a ReflectiveEvent and extend it beyond getting data in the VM constructor.   Does this make sense or is there a better way, in your opinion?

Rob Eisenberg wrote re: “Build Your Own MVVM Framework” is Online
on 06-11-2010 12:28 PM

Please wait just a little bit longer...I have something up my sleeve... ;)

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)