260 likes | 552 Vues
Developing with WCF RIA Services Quickly and Effectively. Nikhil Kothari Software Architect, Microsoft Corporation Blog: http://www.nikhilk.net Twitter: @ nikhilk. Agenda. Getting started on an application End-to-end introduction Going beyond the basics Implementing MVVM/ ViewModel
E N D
Developing with WCF RIA Services Quickly and Effectively Nikhil Kothari Software Architect, Microsoft Corporation Blog: http://www.nikhilk.net Twitter:@nikhilk
Agenda • Getting started on an application • End-to-end introduction • Going beyond the basics • Implementing MVVM/ViewModel • Designing the application logic • Tips and guidelines along the way • Sneak peek at future possibilities
The RIA Services Vision • Simplify n-tier data-driven application development • A higher level framework on top of existing building blocks • LINQ, Data Access Technologies, WCF, Metadata • Provide an application architecture that scales to fit needs of breadth line-of-business applications
What would you like to see? • http://www.nikhilk.net/RIA-Services-MIX10.aspx • Pick a real-world scenario; skip the drag/drop • An example of when UI is not mapped one-to-one with a database table • An example of projections across tables • An example where DAL types are not passed to the client • An example of using a stored procedure • When to use [Invoke] vs. Insert/Update/Delete methods? • How to implement the combobox/lookup table scenario? • How to make RIA Services work with MVVM?
BookClub Application • DomainContext • Stateful view + Bindable Data • class BookShelfContext • EntitySet<Book> Books { get } • EntityQuery<Book> GetBooksQuery() • Entities • class Book • Data members + Validation • DomainService • Stateless CRUD + App Logic • class BookShelfService • IQueryable<Book> GetBooks() • void ShareBook(Book) • void UpdateBook(Book) • void UnshareBook (Book) • Validation, authorization, business rules • Data Model • class Book Data Model + Metadata + Shared Code Services Application Presentation Logic App Logic Data Access Layer Network DB var q = Context.GetBooksQuery() Context.Load(q); Context.Books.Add(newBook); Context.SubmitChanges(); DomainService.Query Invoke GetBooks() Compose query, execute, serialize results DomainService.SubmitChanges Authorize, Validate, Execute, Persist Queries and ChangeSets
Thinking ViewModel aka MVVM • A pattern for separating application behavior out of the user interface • Motivation • Facilitate designer/developer workflow, and independent design/development activity • Encapsulate state and operations of application • Improve maintainability • Facilitate testability
ViewModel + RIA Services Application Presentation XAML, UI Logic View Model App State, Operations, Notifications Data Model Services, Business Rules
Sketching the ViewModel SaveBooks() LoadBooks() LoadMoreBooks() ShareBook() Books SelectedBook (two-way) SelectedBook EditBook() UnshareBook()
The Role of DomainServices • Encapsulate reusable application logic and expose it as a set of CRUD • Meaningful tasks unique to your application • Interesting implementation scenarios • Constraining results • Validation, authorization and business rules • Shaping data • Aggregating data • Caching • Triggering business processes • …
Designing DomainServices - Identifying the Tasks GetBooks ShareBook UpdateBook UnshareBook
Designing DomainServices -Identifying the Tasks GetLatestBooks GetBooksOfDay SearchBooks RequestBook
Layering your DomainServices DomainServices + Entities BookShelf Service BookClubService BookInfo Book IQueryable<BookInfo> GetBooks() void ShareBook() void UnshareBook() void UpdateBook() IQueryable<BookInfo> GetBooks() IQueryable<BookInfo> SearchBooks() IQueryable<BookInfo> GetBooksOfDay() void RequestBook(intbookID) ReferenceDataService Category IQueryable<Category> GetCategories() Data Access Layer + DAL Types Amazon BookClubObjectContext Book Request Checkout Category Member
Walkthrough of an Interesting DomainService Implementation Demo
Recap: Tips and Guidelines • Constrain your queries • Parameters, business rules, result limits • Define specific operations on your domain service that match your application semantics • Use validation to enforce rules, and provide useful user experience • Member, Entity, Operation, Server-only, Async • Use authorization to restrict access to data and operations • Handle errors – any Load/Submit could fail • Separate out reference data to facilitate sharing and optimal loading
Recap: Some More Tips • Focus on the tasks that define your application • Customize your DomainServices • Group logically related tasks per DomainService • Create custom entity types designed for use between client and server when appropriate • Expose sufficient and minimum amount of information • Aggregate, re-shape, project on the server • Consider security, band-width and latency
Scaling your DomainServices Databases ADO.NET, ORMs (LTS, EF, …) .NET Clients Silverlight, Phone, WPF Standards Clients JavaScript App Logic Lists/Objects Repository (NHibernate, …) Server Rendering HTML, Sitemaps Services REST/SOAP (Azure, …) Services SOAP, XML, JSON, OData Unit Test Code
Related Talks • CL08 – Microsoft Silverlight 4 Business Applications • CL50 – Search Engine Optimization for Microsoft Silverlight • FT15 – Accessing Data in a Microsoft Connected Web Application • EX14 - Understanding the Model-View-ViewModel Pattern • RIA Services Meetup at 8pm today in 24001
Roadmap and Further Information • Bits • Today: Feature-complete RC build that works with SL4 and VS2010 RC • V1: Ship with SL4 on top of .NET 4/VS2010 • Hosters starting to get on-board (eg. DiscountASP, OrcsWeb) • More Information • http://silverlight.net/riaservices - RIA Services Online • Blogs • http://www.nikhilk.net • http://blogs.msdn.com/brada • http://jeffhandley.com
Call to Action • Get a jumpstart on your next Silverlight-based LOB/data-driven app • RIA Services builds on WCF and Silverlight 4 and provides end-to-end solutions • Takes care of services infrastructure, binding infrastructure • Implement well-architected manageable application, and work well for designer/developer workflow • RIA Services is complemented by patterns such as task-centric design approaches and ViewModel
© 2010 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.