<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: MVC Best Practices</title>
	<atom:link href="http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Wed, 19 Jun 2013 12:45:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1973</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Fri, 30 Oct 2009 15:19:49 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1973</guid>
		<description>@Seb

Ah, just now saw that his presentation was based on yours...thanks for the link!</description>
		<content:encoded><![CDATA[<p>@Seb</p>
<p>Ah, just now saw that his presentation was based on yours&#8230;thanks for the link!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastien Lambla</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1972</link>
		<dc:creator>Sebastien Lambla</dc:creator>
		<pubDate>Fri, 30 Oct 2009 12:55:13 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1972</guid>
		<description>Jimmy,

in the original presentation I created, I introduce the concept of PresentationModels, a secondary controller who&#039;s responsibility is to encapsulate the display logic out of the views and that receives the model returned by the controller, which solves nicely the problem of testable presentation logic.

You can see the original at http://developerdayscotland.com/sessions/09-SebastienLambla/mvc-bestpractices.pdf and http://serialseb.blogspot.com/2009/05/my-mvc-best-practices-talk.html</description>
		<content:encoded><![CDATA[<p>Jimmy,</p>
<p>in the original presentation I created, I introduce the concept of PresentationModels, a secondary controller who&#8217;s responsibility is to encapsulate the display logic out of the views and that receives the model returned by the controller, which solves nicely the problem of testable presentation logic.</p>
<p>You can see the original at <a href="http://developerdayscotland.com/sessions/09-SebastienLambla/mvc-bestpractices.pdf" rel="nofollow">http://developerdayscotland.com/sessions/09-SebastienLambla/mvc-bestpractices.pdf</a> and <a href="http://serialseb.blogspot.com/2009/05/my-mvc-best-practices-talk.html" rel="nofollow">http://serialseb.blogspot.com/2009/05/my-mvc-best-practices-talk.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1971</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Fri, 30 Oct 2009 01:33:16 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1971</guid>
		<description>@EricTN

Do you want another controller that does login/logout functionality?  We have our own way of doing it, almost unique per project...

@Simone

Yeah, we&#039;ve started doing more of the &quot;precalculated logic&quot; as well, it&#039;s turning out pretty nicely!</description>
		<content:encoded><![CDATA[<p>@EricTN</p>
<p>Do you want another controller that does login/logout functionality?  We have our own way of doing it, almost unique per project&#8230;</p>
<p>@Simone</p>
<p>Yeah, we&#8217;ve started doing more of the &#8220;precalculated logic&#8221; as well, it&#8217;s turning out pretty nicely!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simone Chiaretta</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1970</link>
		<dc:creator>Simone Chiaretta</dc:creator>
		<pubDate>Thu, 29 Oct 2009 00:24:54 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1970</guid>
		<description>@Jimmy, thank you commenting with a blog post :)
Just making a few comments on the two things we kind of disagree on:

1 - actionfilters: what if the magic strings were not exposed to the developers but &quot;hidden&quot; behind a &quot;widget&quot; library?

2 - HtmlHelpers: yeah, I know, the helper pattern sucks, but I guess it&#039;s better than sticking complex conditions mixed with HTML. That&#039;s why the following best practice was to &quot;choose your viewengine carefully&quot; :)
Another option, which I prefer, is trying to avoid all conditions in the view, and have these conditions already evaluated in the ViewModel. And have the view only handle plain boolean values.</description>
		<content:encoded><![CDATA[<p>@Jimmy, thank you commenting with a blog post <img src='http://lostechies.com/jimmybogard/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Just making a few comments on the two things we kind of disagree on:</p>
<p>1 &#8211; actionfilters: what if the magic strings were not exposed to the developers but &#8220;hidden&#8221; behind a &#8220;widget&#8221; library?</p>
<p>2 &#8211; HtmlHelpers: yeah, I know, the helper pattern sucks, but I guess it&#8217;s better than sticking complex conditions mixed with HTML. That&#8217;s why the following best practice was to &#8220;choose your viewengine carefully&#8221; <img src='http://lostechies.com/jimmybogard/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Another option, which I prefer, is trying to avoid all conditions in the view, and have these conditions already evaluated in the ViewModel. And have the view only handle plain boolean values.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EricTN</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1969</link>
		<dc:creator>EricTN</dc:creator>
		<pubDate>Wed, 28 Oct 2009 20:54:43 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1969</guid>
		<description>Could you please provide a simple sample MVC2 application that has a simple replacement for the functionality provided by the Account Controler that you state should be immediately deleted.  Thanks!</description>
		<content:encoded><![CDATA[<p>Could you please provide a simple sample MVC2 application that has a simple replacement for the functionality provided by the Account Controler that you state should be immediately deleted.  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Sampson (Sampy)</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1968</link>
		<dc:creator>Mike Sampson (Sampy)</dc:creator>
		<pubDate>Wed, 28 Oct 2009 18:47:04 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1968</guid>
		<description>The idea of how to send the result of composed &quot;controller&quot; actions to the View layer is something I spend a lot of time thinking about and grappling with. By &quot;controller&quot; I mean all the pieces that do work in the controller layer for the view: the actual Action method, filters, defaut values, etc.

I think of the ViewData object as a box that I&#039;m handing to the View that has everything it needs to get it&#039;s job done. Inside the box are lots of other, smaller boxes. Each piece of the View layer (the actual View, partial views, master page) all know what they&#039;re looking for in the box based on it&#039;s type. Each one gets what it needs with out asking for it via it&#039;s .Model property. Just declare your ViewModel type and you&#039;ll get what you need automatically. You build this on the ViewData dictionary.

Hating the ViewData dictionary with it&#039;s &quot;magic strings&quot; is pretty common but I think that it is wrong to throw it out the window completely. You shouldn&#039;t be playing in it at a low level but building code on top of it that makes your access to the contents strongly typed can enable some really good composition scenarios. Use type names as keys and build some glue in your view engine and you can have great, declartive composition in your View layer just like in your Controller layer.

While ViewData[&quot;MyKey&quot;] is pretty fragile, that doesn&#039;t mean touching the dictionary is wrong.</description>
		<content:encoded><![CDATA[<p>The idea of how to send the result of composed &#8220;controller&#8221; actions to the View layer is something I spend a lot of time thinking about and grappling with. By &#8220;controller&#8221; I mean all the pieces that do work in the controller layer for the view: the actual Action method, filters, defaut values, etc.</p>
<p>I think of the ViewData object as a box that I&#8217;m handing to the View that has everything it needs to get it&#8217;s job done. Inside the box are lots of other, smaller boxes. Each piece of the View layer (the actual View, partial views, master page) all know what they&#8217;re looking for in the box based on it&#8217;s type. Each one gets what it needs with out asking for it via it&#8217;s .Model property. Just declare your ViewModel type and you&#8217;ll get what you need automatically. You build this on the ViewData dictionary.</p>
<p>Hating the ViewData dictionary with it&#8217;s &#8220;magic strings&#8221; is pretty common but I think that it is wrong to throw it out the window completely. You shouldn&#8217;t be playing in it at a low level but building code on top of it that makes your access to the contents strongly typed can enable some really good composition scenarios. Use type names as keys and build some glue in your view engine and you can have great, declartive composition in your View layer just like in your Controller layer.</p>
<p>While ViewData["MyKey"] is pretty fragile, that doesn&#8217;t mean touching the dictionary is wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Roberts</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1967</link>
		<dc:creator>Ryan Roberts</dc:creator>
		<pubDate>Wed, 28 Oct 2009 18:12:03 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1967</guid>
		<description>I think inherited view models may break down unpleasantly if/when or if they do not match the visual inheritance of the site. For the pretty simple things I have been using it for it has been fine so far. </description>
		<content:encoded><![CDATA[<p>I think inherited view models may break down unpleasantly if/when or if they do not match the visual inheritance of the site. For the pretty simple things I have been using it for it has been fine so far. </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1966</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Wed, 28 Oct 2009 16:54:22 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1966</guid>
		<description>@gc

We&#039;ll still go RenderAction route, but we have a RequiresPermission attribute that&#039;ll render nothing if the user doesn&#039;t have permission.  This was kinda tailored to our requirements, so it might not fit your situation.

@Ryan

That&#039;s a pretty cool concept - we do something a lot more basic and hard-code (i.e., interface called IRequireInitialization :P)  But I still don&#039;t like inheritance/composition in the view model, I just get annoyed with orthogonal concerns represented in one object, and with a mapping operation going on too, it might not work with how we set up our pipeline.  I can definitely see the value of doing this approach though.</description>
		<content:encoded><![CDATA[<p>@gc</p>
<p>We&#8217;ll still go RenderAction route, but we have a RequiresPermission attribute that&#8217;ll render nothing if the user doesn&#8217;t have permission.  This was kinda tailored to our requirements, so it might not fit your situation.</p>
<p>@Ryan</p>
<p>That&#8217;s a pretty cool concept &#8211; we do something a lot more basic and hard-code (i.e., interface called IRequireInitialization <img src='http://lostechies.com/jimmybogard/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )  But I still don&#8217;t like inheritance/composition in the view model, I just get annoyed with orthogonal concerns represented in one object, and with a mapping operation going on too, it might not work with how we set up our pipeline.  I can definitely see the value of doing this approach though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Roberts</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1965</link>
		<dc:creator>Ryan Roberts</dc:creator>
		<pubDate>Wed, 28 Oct 2009 16:10:42 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1965</guid>
		<description>I use simple behaviours to deal with common elements on view models (http://pastie.org/673466). They are executed after the controller action using a common base controller.

public class LoginBehavior : IBehavior&lt;BaseViewModel&gt;
{
 public void Apply(BaseViewModel sourceModel)
    {
      sourceModel.Login.CurrentMember = MemberContext.CurrentMember
          .Present&lt;Member&gt;();
  }
}

You end up with pretty good SOC for dealing with bits of the view model that are not directly the responsibility of the controller action.</description>
		<content:encoded><![CDATA[<p>I use simple behaviours to deal with common elements on view models (<a href="http://pastie.org/673466" rel="nofollow">http://pastie.org/673466</a>). They are executed after the controller action using a common base controller.</p>
<p>public class LoginBehavior : IBehavior<baseviewmodel><br />
{<br />
 public void Apply(BaseViewModel sourceModel)<br />
    {<br />
      sourceModel.Login.CurrentMember = MemberContext.CurrentMember<br />
          .Present<member>();<br />
  }<br />
}</p>
<p>You end up with pretty good SOC for dealing with bits of the view model that are not directly the responsibility of the controller action.</member></baseviewmodel></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gc</title>
		<link>http://lostechies.com/jimmybogard/2009/10/28/mvc-best-practices/#comment-1964</link>
		<dc:creator>gc</dc:creator>
		<pubDate>Wed, 28 Oct 2009 15:55:15 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/10/28/mvc-best-practices.aspx#comment-1964</guid>
		<description>I agree on the RenderAction approach, I&#039;d much rather have a separate internal request to render widgets such as the currently logged in user&#039;s status in the header etc.

But what if all the views should check on the current user&#039;s permissions in order to render or not render some of their content. How do you handle logic like that? 

Currently I have all my ViewModels inherit from a base ViewModel which has a property that can be checked for the user&#039;s permissions and is being populated on every request by a custom Controller Action Invoker, but so far it has only given me headache and it&#039;s much too fragile and harder to test (specially when a Viewmodel contains list of child Viewmodels and they need to have those data populated too)

What&#039;s your approach to situations like this?</description>
		<content:encoded><![CDATA[<p>I agree on the RenderAction approach, I&#8217;d much rather have a separate internal request to render widgets such as the currently logged in user&#8217;s status in the header etc.</p>
<p>But what if all the views should check on the current user&#8217;s permissions in order to render or not render some of their content. How do you handle logic like that? </p>
<p>Currently I have all my ViewModels inherit from a base ViewModel which has a property that can be checked for the user&#8217;s permissions and is being populated on every request by a custom Controller Action Invoker, but so far it has only given me headache and it&#8217;s much too fragile and harder to test (specially when a Viewmodel contains list of child Viewmodels and they need to have those data populated too)</p>
<p>What&#8217;s your approach to situations like this?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
