Nikhil Kothari Software Architect Microsoft Corporation Blog httpwwwnikhilknet Twitter nikhilk Agenda Getting started on an application Endtoend introduction Going beyond the basics ID: 390922
Download Presentation The PPT/PDF document "Developing with WCF RIA Services Quickly..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Developing with WCF RIA Services Quickly and Effectively
Nikhil Kothari
Software Architect, Microsoft Corporation
Blog:
http://www.nikhilk.net
Twitter:
@
nikhilkSlide2
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 possibilitiesSlide3
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 applicationsSlide4
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?Slide5
Demo
An End-to-End Introduction to RIA ServicesSlide6
BookClub Application
Application
DB
Services
Data Access Layer
App
Logic
Presentation
Logic
Network
DomainService
Stateless CRUD + App Logic
class
BookShelfService
IQueryable
<Book>
GetBooks
()
void
ShareBook
(Book)
void UpdateBook(Book)void UnshareBook (Book)Validation, authorization, business rulesData Model class Book
DomainContextStateful view + Bindable Dataclass BookShelfContextEntitySet<Book> Books { get }EntityQuery<Book> GetBooksQuery()Entitiesclass BookData members + Validation
Data Model +
Metadata +Shared Code
DomainService.Query Invoke GetBooks() Compose query, execute, serialize resultsDomainService.SubmitChanges Authorize, Validate, Execute, Persist
var q = Context.GetBooksQuery()Context.Load(q);Context.Books.Add(newBook);Context.SubmitChanges();
Queries
and
ChangeSetsSlide7
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 testabilitySlide8
ViewModel + RIA Services
Application
Data Model
Services, Business Rules
View Model
App State, Operations, Notifications
Presentation
XAML, UI Logic
<
User
Control.DataContext
>
<
local:BookShelfModel
/>
</
UserControl.DataContext
>
<
ItemsControl
ItemsSource
=“{Binding Books}” /><Button Content=“Load” Command=“loadCommand” />public class BookShelfModel : INotifyPropertyChanged { BookShelfContext _bookShelf; public IEnumerable<Book> Books {
get; } public void LoadBooks(string) { // use _library to perform search }}public class Book : Entity { … }public class BookShelfContext : DomainContext
{ public EntitySet<Book> Books { get; }}Slide9
Sketching the ViewModel
Books
SelectedBook
(two-way)
SelectedBook
LoadBooks
()
LoadMoreBooks
()
SaveBooks
()
ShareBook
()
UnshareBook
()
EditBook()Slide10
Demo
Implementing the
ViewModel
Pattern with RIA ServicesSlide11
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
…Slide12
Designing DomainServices
- Identifying the Tasks
GetBooks
UpdateBook
UnshareBook
ShareBookSlide13
Designing
DomainServices
-Identifying the Tasks
RequestBook
GetBooksOfDay
SearchBooks
GetLatestBooksSlide14
Designing DomainServices
– Presentation Model TypesSlide15
DomainServices
+ Entities
Layering your
DomainServices
Data Access
Layer +
DAL Types
BookClub
ObjectContext
Reference
DataService
BookClub
Service
Book
Member
Request
Checkout
Category
BookInfo
IQueryable<Category> GetCategories()
IQueryable<BookInfo> GetBooks()IQueryable<BookInfo> SearchBooks()IQueryable<BookInfo> GetBooksOfDay()void RequestBook
(int bookID)
Category
Amazon
BookShelf Service
Book
IQueryable
<
BookInfo
>
GetBooks
()
void
ShareBook
()
void
UnshareBook
()
void
UpdateBook
()Slide16
Demo
Walkthrough of an Interesting
DomainService
ImplementationSlide17
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 loadingSlide18
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 latencySlide19
Scaling your DomainServices
App
Logic
Databases
ADO.NET,
ORMs (LTS, EF, …)
Lists/Objects
Repository
(
NHibernate
, …)
Services
REST/SOAP
(Azure, …)
.NET Clients
Silverlight, Phone,
WPF
Standards Clients
JavaScript
Server Rendering
HTML, Sitemaps
Services
SOAP, XML,
JSON,
OData
Unit Test CodeSlide20
Demo
RIA Services + Windows Phone 7Slide21
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 24001Slide22
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 Informationhttp://silverlight.net/riaservices - RIA Services OnlineBlogshttp://www.nikhilk.nethttp://blogs.msdn.com/brada
http://jeffhandley.com Slide23
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
ViewModelSlide24
Q&ASlide25Slide26
©
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.