Architecting an ASP.NET MVC Solution
Andrea Saltarello
CEO @ managed/designs
andysal@gmail.com
http://twitter.com/andysal74
http://slideshare.net/andysal
Who I am
1. CEO @ Managed Designs, striving to discover the perfect «sustainable
software development process»
• Customer has to be satisfied and pay
• Supplier has to have a reasonable markup
• Team members should be satisfied with their work
2. Founder and leader of UGIdotNET (first Italian .NET User Group): I
need to share experiences in a peer to peer way
3. (Co)Author (together with Dino) of .NET: Architecting Applications for
the Enterprise, by Microsoft Press
4. Basically, a software developer 
Architecture: back to basics
The fundamental organization of a system embodied in its
components, their relationships to each other, and to the
environment, and the principles guiding its design and evolution.
[ISO/IEC 42010]
2014: Web vs. Architecture
Those «components» are (at least) the front end and the back end(s),
whilst the «environment» is the Internet.
• Solution architecture
– Blueprint/pattern (e.g.: thin client, SPA)
– Visual Studio project(s)
• Front end architecture
• Back end architecture
• Cross cutting concerns (e.g.: security)
FRONT END
.Net DeveloperDays 2014
To SPA, or not to SPA?
«It depends» 
Pro:
• Responsiveness
• Less bandwith usage
Cons:
• Need for client side toolkit(s)
• SEO
It does not have to (and it shouldn’t) be an «all or nothing» decision
.Net DeveloperDays 2014
DEMO
AngularJS
What’s (in) a page, anyway?
As humans, it’s easy to understand the meaning of a page’s content, but
how can we have browsers and crawlers be aware of it, too?  Taxonomy
is the key.
• Bootstrap (http://getbootstrap.com) allows us to map html elements
onto a set of conceptual UI items
• Microdata (a.k.a. Microformats - http://www.schema.org) allow
crawlers to understand our document’s structure and index them
accordingly
– SEO
– Screen readers
.Net DeveloperDays 2014
DEMO
Bootstrap
LESS feat. Bootstrap
Microdata
Google Webmaster Tools feat Microdata
BACK END
.Net DeveloperDays 2014
By «MVC», you mean Model 2
In the Model 2 approach, end user requests are managed by a servlet that
controls the flow, and uses components such as JavaBeans or EJBs to
access and manipulate the data. It then uses JSPs to render the application
content in a Web browser. [Java doc @ Oracle]
N.B.: Assert.AreSame(“servlet”, “controller”); // 
.Net DeveloperDays 2014
Implementing Model 2 with ASP.NET MVC
In the Model 2 approach, end user requests are managed by a controller
that controls the flow, and uses worker services to access and manipulate
the data, which are returned as view models. It then uses views to render
the application content in a Web browser. [Andrea Saltarello ]
Tips:
• Use the Force routing, Luke!
• Always implement a UrlBuilder
DEMO
Model 2
Let’s talk «Application content» (reprise)
“application content” can both be a page or some kind of data such as:
files, sitemaps, json, … That’s what ActionResults are there for 
• ViewResult
• JsonResult
• ContentResult
• YourOwnPersonalResult (e.g.: MvcMate)
We could also use WebAPI… Until vNext comes 
.Net DeveloperDays 2014
Sitemaps
Sitemaps are an easy way for webmasters to inform search engines about
pages on their sites that are available for crawling. In its simplest form, a
Sitemap is an XML file that lists URLs for a site along with additional
metadata about each URL (when it was last updated, how often it usually
changes, and how important it is, relative to other URLs in the site) so that
search engines can more intelligently crawl the site.
[http://www.sitemaps.org/]
Important: both Bing and Google do support them
DEMO
Services
MvcMate
Sitemaps
Model 2: the icing on the cake stack
• Model 2 <3 IoC
• Model 2 <3 CQRS
• Model 2 <3 LET
.Net DeveloperDays 2014
DEMO
IoC
CQRS
LET
Crawler aware security
We know how to:
• have crawlers discovering our resources URLs…
• have crawlers better understand our application’s contents…
Is there a way to have crawlers doing those lovely tasks even on login
protected content? Authorization filter you need, Luke! 
DEMO
Custom AuthorizationFilter
Demo code
[MVCM] MvcMate, https://mvcmate.codeplex.com (custom ActionResults).
– Binary package available for free on NuGet: http://www.nuget.org/packages/MvcMate/
[MERP] Merp, https://naa4e.codeplex.com/ (AngularJS, Bootstrap)
[UGI] UGIdotNET; have a look at the source code (Bootstrap and HTML+Microdata) of:
– Home page: http://www.ugidotnet.org
– Sitemap: http://www.ugidotnet.org/sitemap
– News page: http://www.ugidotnet.org/news/1369/Rilasciato-ReSharper-8-1
– Video page: http://www.ugidotnet.org/video/107800840/CPP03--Functional-
Techniques-in-C++
Architecting an ASP.NET MVC Solution

Architecting an ASP.NET MVC Solution

  • 2.
    Architecting an ASP.NETMVC Solution Andrea Saltarello CEO @ managed/designs andysal@gmail.com http://twitter.com/andysal74 http://slideshare.net/andysal
  • 3.
    Who I am 1.CEO @ Managed Designs, striving to discover the perfect «sustainable software development process» • Customer has to be satisfied and pay • Supplier has to have a reasonable markup • Team members should be satisfied with their work 2. Founder and leader of UGIdotNET (first Italian .NET User Group): I need to share experiences in a peer to peer way 3. (Co)Author (together with Dino) of .NET: Architecting Applications for the Enterprise, by Microsoft Press 4. Basically, a software developer 
  • 4.
    Architecture: back tobasics The fundamental organization of a system embodied in its components, their relationships to each other, and to the environment, and the principles guiding its design and evolution. [ISO/IEC 42010]
  • 5.
    2014: Web vs.Architecture Those «components» are (at least) the front end and the back end(s), whilst the «environment» is the Internet. • Solution architecture – Blueprint/pattern (e.g.: thin client, SPA) – Visual Studio project(s) • Front end architecture • Back end architecture • Cross cutting concerns (e.g.: security)
  • 6.
  • 7.
    To SPA, ornot to SPA? «It depends»  Pro: • Responsiveness • Less bandwith usage Cons: • Need for client side toolkit(s) • SEO It does not have to (and it shouldn’t) be an «all or nothing» decision .Net DeveloperDays 2014
  • 8.
  • 9.
    What’s (in) apage, anyway? As humans, it’s easy to understand the meaning of a page’s content, but how can we have browsers and crawlers be aware of it, too?  Taxonomy is the key. • Bootstrap (http://getbootstrap.com) allows us to map html elements onto a set of conceptual UI items • Microdata (a.k.a. Microformats - http://www.schema.org) allow crawlers to understand our document’s structure and index them accordingly – SEO – Screen readers .Net DeveloperDays 2014
  • 10.
  • 11.
  • 12.
    By «MVC», youmean Model 2 In the Model 2 approach, end user requests are managed by a servlet that controls the flow, and uses components such as JavaBeans or EJBs to access and manipulate the data. It then uses JSPs to render the application content in a Web browser. [Java doc @ Oracle] N.B.: Assert.AreSame(“servlet”, “controller”); //  .Net DeveloperDays 2014
  • 13.
    Implementing Model 2with ASP.NET MVC In the Model 2 approach, end user requests are managed by a controller that controls the flow, and uses worker services to access and manipulate the data, which are returned as view models. It then uses views to render the application content in a Web browser. [Andrea Saltarello ] Tips: • Use the Force routing, Luke! • Always implement a UrlBuilder
  • 14.
  • 15.
    Let’s talk «Applicationcontent» (reprise) “application content” can both be a page or some kind of data such as: files, sitemaps, json, … That’s what ActionResults are there for  • ViewResult • JsonResult • ContentResult • YourOwnPersonalResult (e.g.: MvcMate) We could also use WebAPI… Until vNext comes  .Net DeveloperDays 2014
  • 16.
    Sitemaps Sitemaps are aneasy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site. [http://www.sitemaps.org/] Important: both Bing and Google do support them
  • 17.
  • 18.
    Model 2: theicing on the cake stack • Model 2 <3 IoC • Model 2 <3 CQRS • Model 2 <3 LET .Net DeveloperDays 2014
  • 19.
  • 20.
    Crawler aware security Weknow how to: • have crawlers discovering our resources URLs… • have crawlers better understand our application’s contents… Is there a way to have crawlers doing those lovely tasks even on login protected content? Authorization filter you need, Luke! 
  • 21.
  • 22.
    Demo code [MVCM] MvcMate,https://mvcmate.codeplex.com (custom ActionResults). – Binary package available for free on NuGet: http://www.nuget.org/packages/MvcMate/ [MERP] Merp, https://naa4e.codeplex.com/ (AngularJS, Bootstrap) [UGI] UGIdotNET; have a look at the source code (Bootstrap and HTML+Microdata) of: – Home page: http://www.ugidotnet.org – Sitemap: http://www.ugidotnet.org/sitemap – News page: http://www.ugidotnet.org/news/1369/Rilasciato-ReSharper-8-1 – Video page: http://www.ugidotnet.org/video/107800840/CPP03--Functional- Techniques-in-C++