Presentation is loading. Please wait.

Presentation is loading. Please wait.

© Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Noam King CTO Sela College

Similar presentations


Presentation on theme: "© Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Noam King CTO Sela College"— Presentation transcript:

1 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Noam King CTO Sela College http://blogs.microsoft.co.il/blogs/noam Noam King CTO Sela College http://blogs.microsoft.co.il/blogs/noam

2 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Classic ASP.NET

3 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Why should I care? 3 main reasons : –Build applications faster –Scale easily –Test better

4 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Two main players Dynamic Data –Build a presentation layer based on a database schema in just a few minutes MVC – Clean separation of Layers

5 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel What are you going to see ? Dynamic Data projects MVC Framework Customizing DDC and MVC MVC and Dynamic data altogether Much more…

6 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel

7 What Is Dynamic Data? An easy powerful way to build a data-driven Web site Allows you to get started quickly using scaffolding completely customized UI through templates and pages Validation and business rules specified on data model flow through to UI Flexible URL routing, based on data schema and separate from the physical page New DDC make scenarios like sorting, paging, editing, and filtering remarkably easy to implement Now in Microsoft.NET Framework 3.5 SP1

8 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Dynamic Data – First Steps

9 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Scaffolding // Global.asax: Application_Start model.RegisterContext (typeof(NorthwindDataContext), new ContextConfiguration() { ScaffoldAllTables = true }); // WARNING: This enables scaffolding for every table in the model. To enable scaffolding on a per-table or per-column basis, you can use attributes on the model: [MetadataType(typeof(ProductMeta))]public partial class ProductMeta [ScaffoldTable(true)]{ public partial class Product [ScaffoldColumn(true)] { public object UnitPrice { get; set; } …} } // WARNING: This enables scaffolding for every table in the model. To enable scaffolding on a per-table or per-column basis, you can use attributes on the model: [MetadataType(typeof(ProductMeta))]public partial class ProductMeta [ScaffoldTable(true)]{ public partial class Product [ScaffoldColumn(true)] { public object UnitPrice { get; set; } …} }

10 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Routing // Global.asax: Application_Start RouteTable.Routes.routes.Add (new DynamicDataRoute("{table}/{action}.aspx") { Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }), Model = model }); RouteTable.Routes.routes.Add (new DynamicDataRoute("{table}/List.aspx") { Action = PageAction.List, ViewName = "List", Model = model }); RouteTable.Routes.Add(new DynamicDataRoute("MyCategoryDetail/{CategoryID}") { Model = model, Table = "Categories", Action = "Details" });

11 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Scaffolding And Routing

12 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Data Model Annotations System.ComponentModel.DataAnnotations namespace –Scaffold attribute // as seen in previous demo –Display attributes DisplayField DisplayFormat DisplayColumn Description –Validation attributes Required Range RegularExpression StringLength DataType (e.g., E-mail, phone number, …)

13 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MetaModel And MetaTable MetaModel –RegisterContext methods –Access to MetaTable objects MetaTable –Schema information, MetaColumns –Attributes collection // Model annotations –Scaffold property –ListActionPath and GetActionPath() method –GetQuery() method

14 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Metadata And Data Model Validation

15 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel UI Customization Dynamic Data provides UI customization at many levels (from least to most control) PageTemplatesFieldTemplatesUIHint/DataType on ModelCustomPages UIHints on DynamicField/DynamicControl

16 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Field Template Controls Allow customization of columns using template based controls –Based on the type of the column –Source code for standard templates is provided –Can be overriden with DataType and UIHint attributes or properties Easy to create –Implement method to set and get values

17 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Dynamic Data Controls DynamicDataManager GridView, DetailsView –DynamicDataField ListView, FormView –DynamicControl LinqDataSource, EntitiesDataSource –DynamicControlParameter –DynamicQueryStringParameter DynamicValidator DynamicFilter (UserControl), FilterRepeater

18 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel UI Customization

19 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Dynamic Data Wizard Preview Scenario: Quickly create partial classes and custom pages for Dynamic Data Current features –Generates a data model from a database –Generates partial classes based on data model –Creates custom List, details pages based on model –Uses ListView control for CSS-friendly markup Preview download available: –http://code.msdn.microsoft.com/dynamicdatahttp://code.msdn.microsoft.com/dynamicdata

20 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Dynamic Data Wizard Preview Upcoming features –Ability to run within existing Web site –Ability to choose existing data model –Entities data model support –Master page and CSS support –Edit and insert forms –Additional layouts (div, ul)

21 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Dynamic Data Wizard

22 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Migrating Existing Pages Scenario: Reduce code in existing pages Validation –Move validation to data model instead of in individual pages. Change in one place affects entire site Field templates –Add custom controls in one place instead of in each of your pages –Enable custom controls on model

23 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Migrating Existing Pages

24 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel DDC – Short Summary Easy to Create Easy to Customize Everything Easy to integrate

25 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Dynamic Data Roadmap Support for more data sources ADO.NET Data Services (also known as Project code name “Astoria”) Plain CLR objects Binding using ObjectDataSource Support for more UI customization Attribute for ordering columns Localized display name and description attributes Insert page take defaults from fitlers More field templates Enum based columns Images from database Support for many to many columns Support for object inheritence (Linq and Entity Framework)

26 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Additional Resources Dynamic Data home: –http://www.asp.net/dynamicdatahttp://www.asp.net/dynamicdata Code Gallery releases: –http://code.msdn.microsoft.com/dynamicdatahttp://code.msdn.microsoft.com/dynamicdata Product Team contacts and blogs: –scott.hunter@microsoft.comscott.hunter@microsoft.com http://blogs.msdn.com/scothu –david.ebbo@microsoft.comdavid.ebbo@microsoft.com http://blogs.msdn.com/davidebb –bradmi@microsoft.combradmi@microsoft.com http://blogs.msdn.com/webdevtools

27 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel

28 So… What is MVC? Model ControllerView Browser requests /Artists/ 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

29 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC – First Steps

30 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel What MVC is not ? Not the new Web Forms 4.0 Not replacing Web Forms, but Adds to it It can not use Web Controls Not a whole new engine but sits on ASP.NET engine Not the best solution for REST

31 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel What MVC is? Maintain Clean Separation of Concerns –Easy Testing –Red/Green TDD –Highly maintainable applications by default Extensible and Pluggable –Support replacing any component of the system –Enables Inversion Of Control (IOC) / Dependency Injection (DI)

32 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel What MVC is ? (cont.) Enable clean URLs and HTML –SEO and REST friendly URL structures Great integration within ASP.NET –All the same providers still work –Membership, Session, Caching, etc. –ASP.NET Designer Surface in VS2008 Tooling Support –Intellisense, Refactoring, Debugging –Project Templates –.aspx View pages have Visual Studio designer support

33 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Flow Request ControllerController Step 1 Incoming request directed to Controller

34 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Flow ControllerController Model Step 2 Controller processes request and forms a data Model

35 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Flow ControllerController ViewView Step 3 Model is passed to View

36 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Flow ControllerController ViewView Step 4 View transforms Model into appropriate output format

37 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Flow ResponseResponse ControllerController ViewView Step 5 Response is rendered

38 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Request Flow – in more detail Request HTTP Routing Route Route Handler Http Handler Controller View Engine View Response

39 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Customization

40 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Routing Engine Map incoming URLs to the application and route them so that the right Controller and Action method executes to process them Construct outgoing URLs that can be used to call back to Controllers/Actions

41 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Routing Demo

42 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Action Filters Inject code interceptors into the request of a MVC controller Package-up and re-use functionality in a clean declarative way Predefined Action Filters Custom Filters

43 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Action Filters

44 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel TempData

45 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel TempData

46 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Ajax Support Ajax is not just “Update Panel” You can use –Page methods –Web Services They all require you to write a lot of javascript MVC Ajax helps with Forms and ActionLinks !!

47 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Ajax Support

48 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Extensibility Views Controllers Models Routes …are all Pluggable

49 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel ViewEngines View Engines render output You get WebForms by default Can implement your own –MVCContrib has ones for Brail, Nvelocity –NHaml is an interesting one to watch View Engines can be used to –Offer new DSLs to make HTML easier –Generate totally different mime/types Images, RSS, JSON, XML, OFX, VCards, whatever.

50 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel View Engine IViewEngine public interface ViewEngineBase { public void RenderView(ViewContext viewContext); }

51 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel NHaml – Extreme Custom Views <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="List.aspx" Inherits="MvcApplication5.Views.Products.List" Title="Products" %> CodeBehind="List.aspx" Inherits="MvcApplication5.Views.Products.List" Title="Products" %> ( ) ( ) </asp:Content>

52 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel 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" }) - 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" })

53 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Extensibility

54 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Testing 1,2,3… Mockable Intrinsics –HttpContextBase, HttpResponseBase, HttpRequestBase Extensibility –IController –IControllerFactory –IRouteHandler –ViewEngineBase

55 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Testing Controller Actions No requirement to test within ASP.NET runtime. –Use Moq or RhinoMocks or TypeMock –Create Test versions of the parts of the runtime you want to stub

56 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Testing

57 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Dynamic Data and MVC Initial release targets web forms Later release will include MVC support Same concepts apply –Model metadata –Page templates –Field templates

58 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Dynamic Data and MVC

59 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC RC Views without Code-Behind Html Helpers with Expression Support Scaffolding Support FileResult, JavaScriptResult and more… Much more to come…

60 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Roadmap –Improved Action Invoker - Refactorings to enable Async, DLR, and Dynamic Action Filters –Dynamic Action Filters - Provide ability to apply filters at runtime, and not just compile time via attributes. –Subcontrollers - More details to follow. –Asynchronous Controller Actions - Provide an asynchronous programming model for controller actions.

61 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Roadmap –Sessionless controllers - Allow controllers to not use session state on a controller by controller basis (without this, you can turn session on or off for the entire site) –MVC Declarative Helpers/Designers - Allow using declarative design time markup for action links, repeater, etc… (These would be a thin veneer over our current helpers) –ScriptManager-Lite - Some means for script manager style support for embedded scripts

62 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel MVC Roadmap –MVC Ajax Extenders - Ajax.Extend method along with some included extenders –Ajax View Package - Package up multiple views to be rendered on the client

63 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Sexy Microsoft Framework Easy from the first date, yet respectful Staying young in and The right way to do get the job done. Customizable all over. Inventing and not Reinventing

64 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Resources My Blog – Noam King http://blogs.microsoft.co.il/blogs/noamk http://blogs.microsoft.co.il/blogs/noamk Scott Guthrie Blog http://weblogs.asp.net/scottgu/http://weblogs.asp.net/scottgu/ Phil Hack http://haacked.com/http://haacked.com/ The Official ASP.NET Site http://www.asp.net/ http://www.asp.net/ Stephen Walther’s blog http://weblogs.asp.net/stephenwalther/archive/2008/03/19/tdd- test-driven-development-with-visual-studio-2008-unit- tests.aspx http://weblogs.asp.net/stephenwalther/archive/2008/03/19/tdd- test-driven-development-with-visual-studio-2008-unit- tests.aspx

65 © Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel


Download ppt "© Copyright SELA Software & Education Labs Ltd. 14-18 Baruch Hirsch St. Bnei Brak 51202 Israel Noam King CTO Sela College"

Similar presentations


Ads by Google