Experimentally Testable Noncontextuality Inequalities Via ...
MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A...
-
Upload
shannon-perry -
Category
Documents
-
view
214 -
download
1
Transcript of MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A...
![Page 2: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/2.jpg)
INTROMVC
![Page 3: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/3.jpg)
ASP.NET MVC is…
A new Web Project Type for ASP.NET.An option.More control over your <html/>A more easily Testable Framework.Not for everyone.
![Page 4: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/4.jpg)
“ScottGu”
![Page 5: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/5.jpg)
When I was born…
![Page 6: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/6.jpg)
“The Gu”
![Page 7: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/7.jpg)
“His Gu-ness”
![Page 8: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/8.jpg)
“Sir”
![Page 9: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/9.jpg)
![Page 10: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/10.jpg)
![Page 11: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/11.jpg)
“Master Chief Gu”
![Page 12: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/12.jpg)
Demo – Hello MVC World
Don’t fall asleep, it’ll be worth it.
![Page 13: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/13.jpg)
What’s the Point?This is not Web Forms 4.0
It’s about alternatives. Car vs. Motorcycle.
FlexibleExtend it. Or not.
FundamentalPart of System.Web and isn’t going anywhere.
Plays Well With OthersFeel free to use NHibernate for Models, Brail for Views and Whatever for Controllers.
Keep it simple and DRY
![Page 14: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/14.jpg)
Goodness – Driving Goals
Maintain Clean Separation of ConcernsEasy Testing Red/Green TDD Highly maintainable applications by default
Extensible and PluggableSupport replacing any component of the system
![Page 15: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/15.jpg)
Goodness – Driving Goals
Enable clean URLs and HTMLSEO and REST friendly URL structures
Great integration within ASP.NETAll the same providers still workMembership, Session, Caching, etc.ASP.NET Designer Surface in VS2008
![Page 16: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/16.jpg)
RUDE Q&AMVC
![Page 17: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/17.jpg)
Ok, um, a choice. I’m paralyzed.In what cases should I stick with WebForms over MVC?
![Page 18: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/18.jpg)
What’s up with REST?
I hear ASP.NET MVC can do REST. When would I use MVC vs. ADO Data Extensions (Astoria) vs. WCF?
![Page 19: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/19.jpg)
Haven’t I heard this before?What is the difference between MVP and MVC?
![Page 20: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/20.jpg)
Widgets? Do we have those?What is the component story with MVC?
![Page 21: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/21.jpg)
Ship it.
When will MVC RTM?
![Page 22: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/22.jpg)
Introducing…
Microsoft Visual Business Enabler Studio 2008R3v2 September Technical Preview RefreshMSVBES2k8R3v2lptrczstr for short
![Page 23: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/23.jpg)
Will Ship Soon…
![Page 24: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/24.jpg)
Will Ship Soon…
![Page 25: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/25.jpg)
Is it safe?
What about security?
![Page 26: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/26.jpg)
Does it scale?
What about performance/scalability?
![Page 27: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/27.jpg)
HOW IT WORKSMVC
27
![Page 28: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/28.jpg)
MVCModel
ControllerView
![Page 29: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/29.jpg)
A Little More Detail
Model
Controller
View
• Browser requests /Products/• Route is determined• Controller is activated• Method on Controller is invoke• Controller does some stuff• Renders View, passing in
custom ViewData• URLs are rendered,
pointing to other Controllers
![Page 30: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/30.jpg)
Even More Detail – Request Flow
• You can futz at each step in the process
Request
![Page 31: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/31.jpg)
Demo – Request Lifecycle
Digging deeper…
![Page 32: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/32.jpg)
FEATURESMVC
![Page 33: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/33.jpg)
URL Routing – Pretty URIsDevelopers adds Routes to a global RouteTableMapping creates a RouteData - a bag of key/values
RouteTable.Routes.Add( new Route("blog/bydate/{year}/{month}/{day}",
new MvcRouteHandler()){ Defaults = new RouteValueDictionary { {"controller", "blog"}, {"action", "show"} }, Constraints = new RouteValueDictionary { {"year", @"\d{1.4}"}, {"month", @"\d{1.2}"}, {"day", @"\d{1.2}"}} })
![Page 34: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/34.jpg)
Demo – Routing
The route less travelled…
![Page 35: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/35.jpg)
ExtensibilityViewsControllersModelsRoutes
…are all Pluggable
![Page 36: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/36.jpg)
ViewEngineBaseView Engines render outputYou get WebForms by defaultCan implement your own
MVCContrib has ones for Brail, NvelocityNHaml is an interesting one to watch
View Engines can be used toOffer new DSLs to make HTML easierGenerate totally different mime/types
Images, RSS, JSON, XML, OFX, VCards, whatever.
![Page 37: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/37.jpg)
View Engine Base Class
ViewEngineBase
public abstract class ViewEngineBase { public abstract void RenderView(ViewContext
viewContext); }
![Page 38: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/38.jpg)
NHaml – Extreme Custom Views<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
AutoEventWireup="true" CodeBehind="List.aspx"
Inherits="MvcApplication5.Views.Products.List" Title="Products" %><asp:Content ContentPlaceHolderID="MainContentPlaceHolder"
runat="server"> <h2><%= ViewData.CategoryName %></h2> <ul> <% foreach (var product in ViewData.Products) { %> <li> <%= product.ProductName %> <div class="editlink"> (<%= Html.ActionLink("Edit", new { Action="Edit",
ID=product.ProductID })%>) </div> </li> <% } %> </ul> <%= Html.ActionLink("Add New Product", new { Action="New" }) %></asp:Content>
![Page 39: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/39.jpg)
NHaml – Extreme Custom Views
%h2= ViewData.CategoryName %ul
- foreach (var product in ViewData.Products) %li = product.ProductName .editlink = Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID }) = Html.ActionLink("Add New Product", new { Action="New" })
![Page 40: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/40.jpg)
HOW TO TEST ITMVC
![Page 41: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/41.jpg)
Interfaces and TDDMockable Intrinsics
HttpContextBase, HttpResponseBase, HttpRequestBase
Extensibility IControllerIControllerFactoryIRouteHandlerViewEngineBase
![Page 42: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/42.jpg)
Testing Controller ActionsNo requirement to test within ASP.NET runtime.
Use RhinoMocks or TypeMockCreate Test versions of the parts of the runtime you want to stub
[TestMethod]public void ShowPostsDisplayPostView() { TestPostRepository repository = new TestPostRepository(); TestViewEngine viewEngine = new TestViewEngine();
BlogController controller = new BlogController(…); controller.ShowPost(2);
Assert.AreEqual("showpost",viewEngine.LastRequestedView); Assert.IsTrue(repository.GetPostByIdWasCalled); Assert.AreEqual(2, repository.LastRequestedPostId);}
![Page 43: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/43.jpg)
Demo – TDD
Wasn’t this demo technically supposed to be first?
![Page 44: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/44.jpg)
Demo – Complete Application
It’s your thing. Do what you wanna do.
![Page 45: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/45.jpg)
What’s the Point?This is not Web Forms 4.0
It’s about alternatives. Car vs. Motorcycle.
FlexibleExtend it. Or not.
FundamentalPart of System.Web and isn’t going anywhere.
Plays Well With OthersFeel free to use NHibernate for Models, Brail for Views and Whatever for Controllers.
Keep it simple and DRY
![Page 46: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/46.jpg)
![Page 47: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/47.jpg)
![Page 48: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/48.jpg)
![Page 49: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/49.jpg)
HAI!IM IN YR NorthwindHOW DUZ I ListProducts YR idPRODUCTS = GETPRODUCTS idOMG FOUND YR PRODUCTSIF U SEZIM OUTTA YR Northwind
LOLCODE.NET
![Page 50: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/50.jpg)
HAI!WTF:I HAS A STRINGGIMMEH STRINGIM IN YR VAR UPPIN YR 0 TIL LENGTH OF STRINGVISIBLE “GIMMEE A ” STRING!!VARSTEPPINIM OUTTA YR VAROMGWTFHALP!
LOLCODE.NET
![Page 52: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/52.jpg)
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
![Page 53: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/53.jpg)
APPENDIXMVC
![Page 54: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/54.jpg)
Controller
Base Controller ClassBasic Functionality most folks will use
IController InterfaceUltimate Control for the Control Freak
IControllerFactoryFor plugging in your own stuff (IOC, etc)
![Page 55: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/55.jpg)
Basic Controller HandlingScenarios, Goals and Design
URLs route to controller “actions”, not pages – mark actions in Controller.Controller executes logic, chooses view.All public methods are accessible
public void ShowPost(int id) { Post p = PostRepository.GetPostById(id); if (p != null) { RenderView("showpost", p); } else { RenderView("nosuchpost", id); }}
![Page 56: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/56.jpg)
Controller Base Classpublic class Controller : IController { … protected virtual void Execute(ControllerContext
controllerContext); protected virtual void HandleUnknownAction(string
actionName); protected virtual bool InvokeAction(string actionName); protected virtual void InvokeActionMethod(MethodInfo
methodInfo); protected virtual bool OnError(string actionName, MethodInfo methodInfo, Exception exception); protected virtual void
OnActionExecuted(FilterExecutedContext filterContext);
protected virtual bool OnActionExecuting(FilterExecutedContext filterContext);
protected virtual void RedirectToAction(object values); protected virtual void RenderView(string viewName, string masterName, object viewData);}
![Page 57: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/57.jpg)
Controller – Regular APIspublic class Controller : IController { … protected virtual void Execute(ControllerContext
controllerContext); protected virtual void HandleUnknownAction(string
actionName); protected virtual bool InvokeAction(string actionName); protected virtual void InvokeActionMethod(MethodInfo
methodInfo); protected virtual bool OnError(string actionName, MethodInfo methodInfo, Exception exception); protected virtual void
OnActionExecuted(FilterExecutedContext filterContext);
protected virtual bool OnActionExecuting(FilterExecutedContext filterContext); protected virtual void RedirectToAction(object values);
protected virtual void RenderView(string viewName, string masterName, object viewData);}
![Page 58: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/58.jpg)
Controller – Customization APIs
public class Controller : IController { … protected virtual void Execute(ControllerContext
controllerContext); protected virtual void HandleUnknownAction(string
actionName); protected virtual bool InvokeAction(string actionName); protected virtual void InvokeActionMethod(MethodInfo
methodInfo); protected virtual bool OnError(string actionName, MethodInfo methodInfo, Exception exception); protected virtual void
OnActionExecuted(FilterExecutedContext filterContext);
protected virtual bool OnActionExecuting(FilterExecutedContext filterContext);
protected virtual void RedirectToAction(object values); protected virtual void RenderView(string viewName, string masterName, object viewData);}
![Page 59: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/59.jpg)
Controller – Test Hooks public class Controller : IController { … protected virtual void Execute(ControllerContext
controllerContext); protected virtual void HandleUnknownAction(string
actionName); protected virtual bool InvokeAction(string actionName); protected virtual void InvokeActionMethod(MethodInfo
methodInfo); protected virtual bool OnError(string actionName, MethodInfo methodInfo, Exception exception); protected virtual void
OnActionExecuted(FilterExecutedContext filterContext);
protected virtual bool OnActionExecuting(FilterExecutedContext filterContext);
protected virtual void RedirectToAction(object values); protected virtual void RenderView(string viewName, string masterName, object viewData);}
![Page 60: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/60.jpg)
Basic ViewsScenarios, Goals and Design:
Are for rendering/output. Pre-defined and extensible rendering helpers
Can use .ASPX, .ASCX, .MASTER, etc.Can replace with other view technologies:
Template engines (NVelocity, Brail, …).Output formats (images, RSS, JSON, …).Mock out for testing.
Controller sets data on the ViewLoosely typed or strongly typed data
![Page 61: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/61.jpg)
ViewEngineBaseView Engines render outputYou get WebForms by defaultCan implement your own
MVCContrib has ones for Brail, NvelocityNHaml is an interesting one to watch
View Engines can be used toOffer new DSLs to make HTML easier to writeGenerate totally different mime/types
ImagesRSS, JSON, XML, OFX, etc.VCards, whatever.
![Page 62: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/62.jpg)
View Engine Base Class
ViewEngineBase
public abstract class ViewEngineBase { public abstract void RenderView(ViewContext
viewContext); }
![Page 63: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/63.jpg)
NHaml – Extreme Custom Views<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
AutoEventWireup="true" CodeBehind="List.aspx"
Inherits="MvcApplication5.Views.Products.List" Title="Products" %><asp:Content ContentPlaceHolderID="MainContentPlaceHolder"
runat="server"> <h2><%= ViewData.CategoryName %></h2> <ul> <% foreach (var product in ViewData.Products) { %> <li> <%= product.ProductName %> <div class="editlink"> (<%= Html.ActionLink("Edit", new { Action="Edit",
ID=product.ProductID })%>) </div> </li> <% } %> </ul> <%= Html.ActionLink("Add New Product", new { Action="New" }) %></asp:Content>
![Page 64: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/64.jpg)
NHaml – Extreme Custom Views
%h2= ViewData.CategoryName %ul
- foreach (var product in ViewData.Products) %li = product.ProductName .editlink = Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID }) = Html.ActionLink("Add New Product", new { Action="New" })
![Page 65: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/65.jpg)
Controller Factory
Scenarios, Goals and Design:Hook creation of controller instance
Dependency Injection.Object Interception.
public interface IControllerFactory { IController CreateController(RequestContext context, string controllerName);}
protected void Application_Start(object s, EventArgs e) { ControllerBuilder.Current.SetControllerFactory( typeof(MyControllerFactory));}
![Page 66: MVC A new Web Project Type for ASP.NET. An option. More control over your More control over your A more easily Testable Framework. Not for everyone.](https://reader037.fdocuments.in/reader037/viewer/2022110211/56649eeb5503460f94bfcf32/html5/thumbnails/66.jpg)
View Engine
Scenarios, Goals and Design:Mock out views for testingReplace ASPX with other technologies
public interface IViewEngine { void RenderView(ViewContext context); }
Inside controller class: this.ViewEngine = new XmlViewEngine(...);
RenderView("foo", myData);