16.08.2012 Views

dotnetrocks 0638 rob eisenberg

dotnetrocks 0638 rob eisenberg

dotnetrocks 0638 rob eisenberg

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

advanced features on top of method invocation<br />

because we let the framework sort of do it for us. I<br />

could say without that you’ve either got to go to the<br />

code-behind or you've got to do something like people<br />

who use a pattern called a Relay Command or<br />

Delegating Command where they create a kind of<br />

wrapper command object that wraps the method and<br />

then proxies it through to the view so that they can<br />

actually data-bind it. Basically, it just results in some<br />

kind of silly boilerplate code that you just have to<br />

mindlessly type in order to connect these pieces<br />

together. So we just say, let’s let the framework do<br />

that for you, and on top of that because the<br />

framework is doing this, we can add even more<br />

advanced functionality on top of that. That's one of<br />

those smaller level patterns that we sort of implement<br />

behind the scenes so the developers don't even need<br />

to think about that.<br />

Carl Franklin: So one of the conventions that<br />

you prefer, Caliburn.Micro prefers, is ViewModel-first<br />

development. Tell us about that.<br />

Rob Eisenberg: So there's typically two<br />

different ways to approach p<strong>rob</strong>lems when you're<br />

trying to work out a solution in your user interface,<br />

and it really has to do with the way your approach the<br />

pattern mentally and a little bit of the way the<br />

framework sort of create features and puts them<br />

together. So there's View-first and ViewModel-first.<br />

Carl Franklin: Okay.<br />

Rob Eisenberg: And with View-first you would<br />

start by literally creating your View and then creating<br />

your ViewModel, and the framework would do things<br />

in that order. In that type of a scenario, the View is<br />

really driving things just a little bit more in terms of the<br />

interactions, in terms of activating and deactivating<br />

different parts of the UI, that you want a lot of that to<br />

be in the ViewModel but by the nature of sort of that<br />

workflow and the way things are instantiated and put<br />

together, the View ends up driving a little bit more. In<br />

ViewModel-first, you have the ViewModel created first<br />

and then based on that you associate a View with it<br />

and it puts the ViewModel in a position to even a<br />

greater degree, sort of drive how the Views are<br />

composed and how they function and so on and so<br />

forth.<br />

Carl Franklin: But if you think about it, Viewfirst<br />

is, well, it's certainly how I've done most of my<br />

development starting back in the days of Visual Basic<br />

when you had a great designer that, you know, you sit<br />

down with a customer essentially with VB and say,<br />

"Okay, so what kinds of things do you want this to<br />

do?" Based on that, you sort of come up with the UI<br />

first. It seems a more natural way to develop for me<br />

because you're really talking about the user's<br />

requirements.<br />

Rob Eisenberg MVVMs Us with Caliburn.Micro!<br />

February 17, 2011<br />

Rob Eisenberg: Absolutely. And practically,<br />

when you're actually developing, you would p<strong>rob</strong>ably<br />

have those things happening at the same time.<br />

Carl Franklin: Sure.<br />

Rob Eisenberg: The important part is that the<br />

framework itself, when it goes at runtime and actually<br />

puts these things together, it starts with the<br />

ViewModel and locates the View and composes them,<br />

does some other fancy stuff, and as a result some of<br />

the way composition occurs within your user interface<br />

is more controlled at runtime by the ViewModel and<br />

that can actually make certain user interface<br />

scenarios a little bit easier to engineer. So it can be a<br />

little bit of perspective from the developer's point of<br />

view when they're thinking about solving the p<strong>rob</strong>lem,<br />

but practically when you are actually building your UI<br />

you may actually build out the View-first and design<br />

with your customer. But at runtime you want the<br />

ViewModel to actually drive everything as opposed to<br />

the View sort of partially driving it with the ViewModel<br />

doing some other part.<br />

Carl Franklin: Okay.<br />

Rob Eisenberg: So it really has to do with what<br />

happens at runtime and how the developer thinks<br />

about those interactions between the two.<br />

Carl Franklin: This portion of .NET Rocks! is<br />

brought to you by our friends at Telerik. So you know<br />

all about the power of ASP.NET MVC, but you might<br />

be in need of some good tools to enhance your<br />

productivity. Well, our friends at Telerik just shipped<br />

the latest release of the Telerik extensions for<br />

ASP.NET MVC, 18 jQuery-based native MVC<br />

extensions. Now you can enhance productivity by<br />

remaining in control of your Views without having to<br />

write all HTML, CSS, and JavaScript by hand. Did I<br />

mention that the Telerik MVC extensions are also free<br />

and open source? Plus, now you can check all MVC<br />

online demos in both ASPX and Razor Views since<br />

the extensions offers full support for ASP.NET MVC<br />

3.0 and the Razor View Engine. Download your free<br />

copy today at www.telerik.com/freemvc, and don't<br />

forget to thank them for supporting .NET Rocks!<br />

So let's talk about the View resolution which, as you<br />

say in the docs, is the first convention you're likely to<br />

encounter.<br />

Rob Eisenberg: So it's pretty simple. When we<br />

were building a lot of apps and looking at the way<br />

other people were building a lot of apps, we noticed<br />

that people followed a very simple naming<br />

convention. If they have like a customer edit<br />

ViewModel, they would typically have a customer edit<br />

View. So they were doing some manual work to<br />

instantiate the two and to set the DataContext and<br />

Transcription by PWOP Productions, http://www.pwop.com Page 6 of 13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!