Data Access Layer (DAL) App Logic Database View Web Service App Logic App Logic Trust Boundary

Preview:

Citation preview

mini

Mini

WCF RIA Services

Bátyai KrisztiánMVP|MCT|MCPD 4.0Webmine Kft.

Mini

Menetrend

o WCF RIA Services bemutatásao OFF: Navigáció & Témák & Autentikációo Lekérdezések (& Autorizáció)o CRUD műveleteko Business Logic & Validáció

Mini

WCF RIA Services bemutatása

Mini

N-rétegű alkalamzás fejlesztés

Mit akarunk általában csinálni?

o felhasználók kezeléseo adatok o megjelenítéseo listázásao szerkesztése

o üzleti szabályok érvényesítéseo stb.

Mit teszünk az idő nagy részében?

o infrastruktúrát gyártunk(infrastruktúra===framework, componensek, helper osztályok)(change-tracking,validáció...)o saját megoldáso meglépvő out-of-box és/vagy 3rd

party megoldások illesztése

Mini

RIA Services N rétegű alkalmazás fejlesztés

Data Access Layer (DAL)

App Logic

Database

View

Web Service

AppLogic

TrustBoundary

Mini

Skálázhatóság, illeszthetőség

AppLogic

DatabasesADO.NET,ORMs (LTS, EF, …)

CLR Lists/ObjectsRepository(nHibernate, …)

ServicesREST/SOAP(Azure, …)

XML, JSON, Binary

.NET ClientsSilverlight, WPF

Standards ClientsJavaScript

Server RenderingHTML, SEO,Printing, …

ServicesWCF

Unit Test Code

Mini

Áttekintés

Rich Internet Application

DB

Services

Data Access Layer

AppLogic

PresentationLogic

Network

DomainServiceStateless CRUD + App Logic

class PlateViewDomainServiceIQueryable<Restaurant> GetRestaurants()IQueryable<Restaurant> SearchRestaurant(string)void AddRestaurant(Restaurant)Validation and authorization rules,

Application workflows, …

Data Model class Book

DomainContextStateful view + Bindable Data

class PlateViewDomainServiceEntityList<Restaurant> Books { get }EntityQuery<Restaurant> GetRestaurantQuery()EntityQuery<Restaurant> SearchRestaurantQuery(string)

class RestaurantData members + Validation

Data Model +Metadata +

Shared Code

DomainContext

DataService

Under the covers infrastructure

Mini

WCF Ria Services & WCF

DomainService(LinqToEntitiesDomainService

<T>)

DomainServiceHost

WCF ServiceWCF

Service Contract

WCR RIAServices

WCF

DomainContext

DomainClient

WCFWCF

Service Contract

1101001..

...<Entity>

Mini

Navigáció & Témák& Autentikáció

Mini

SL&RIA Alkalmazás témák

SL&RIA Alkalmazás témák

DEMO

Mini

Autentikáció

o Out-of-box ASP.Net Application Services

o Out-of-box WCF Ria Autentikáció

<%@ ServiceHost Language="C#" Service="System.Web.ApplicationServices.AuthenticationService" Debug="true" %>

[EnableClientAccess]public class AuthenticationDomainService1 : AuthenticationBase<User>{...}

WebContext webContext = new WebContext();webContext.Authentication = new FormsAuthentication();//webContext.Authentication = new WindowsAuthentication();this.ApplicationLifetimeObjects.Add(webContext);

Autentikáció

DEMO

Mini

Lekérdezések

Mini

A lekérdezés szereplői

DomainServiceStateless

DataModell

DALL2S EF REST/SOAP

POCO

SQL

DomainContextStateFull

UI VIEW

UI - VMEntity+Metadat

a

Entity+Metadat

a

Entity-Containe

r

Server Client

Mini

A lekérdezés folyamata

DomainServiceStateless

DataModell

DALL2S EF REST/SOAP

POCO

SQL

DomainContextStateFull

UI VIEW

UI - VMEntity+Metadat

a

Entity+Metadat

a

Entity-Containe

r

Server Client

1. Query request

2. EntityQuery<T>

3. dc.Load(eq)4. Async request

5. Async response

6. Binding

Mini

Query definíció

o Elnevezésselo Visszatérési érték: IQueryable<T>, IEnumerable<T>

o QueryAttributeo IsComposable

Domain Queries

DEMO

Mini

Kliens oldali cache

DomainContext

DomainService

Load(q) Query result)

Entity+Metadat

a

Entity-Containe

r

Entity-Containe

r

EntitySetEntity

SetEntitySet

EntitySet<T>• IEnumerable<T>• INotifyCollectionChanged• IRevertibleChangeTracking• IChangeTracking• ...

EntityEntit

yEntity

Kliens oldali cache

DEMO

Mini

Kliens oldali LINQ használata

EntityQuery<T>

Domain Service

EntityQuery<T>• QueryName• Parameters• Query• IsComposable

Query• Where• Skip• Take• OrderBy

SQL

Base Query +

Client Query

Kliens oldali LINQ használata

DEMO

Mini

Objektum hierarchiák

Server Side

Entity

Server Side

Metadata

Domain Service

foo1 foo1

Server Client

EntityContainer

Objektum hierarchiák lekérdezése

DEMO

Mini

CRUD műveletek

Mini

Kliens oldali működés

DomainContext

EntityContainer

EntitySet

Entity

EntityChangeSet

ChangeSetEntry

DomainClient

SubmitChanges()

Mini

Változás-követés

EntityContainer

EntitySet

Entity

• IRevertibleChangeTracking• HasChanges• GetChanges()

• IRevertibleChangeTracking• HasChanges

• IRevertibleChangeTracking• HasChanges• EntityState, GetOriginal()

• AcceptChanges• RejectChanges• Add()• Attach()• ...

Mini

DomainSerivce

Server oldali működés

001101101DomainClient

WCF

WCF

Submit(ChangeSet)• AuthorizeChangeSet()• ValidateChangeSet()• ExecuteChangeSet()• CRUD• PersistChangeSet()

EntityChangeSet

ChangeSetEntry

Mini

CRUD definíció

o Elnevezésselo Visszatérési érték:voido Paraméter: Entityo Prefix: Insert,Update,Delete v. Add,Change,Remove

o Attribute*

CRUD

DEMO

Mini

Business Logic & Validáció

Mini

RIA Services N rétegű alkalmazás fejlesztés

Data Access Layer (DAL)

App Logic

Database

View

Web Service

AppLogic

TrustBoundary

• Business Logic• Validation

Mini

Business Logic & Validáció

o Business Logico Invoke Operationso Shared files

o Validációo Out-of-Box Validationo (Custom) Server Validationo Client & Server (shared) Validationo Entity Level Validationo Async Server Validation with InvokeMethod in Client

Mini

Business Logic

o Invoke Operationso ~WCF operationo No change trackingo Async

o Shared fileso Visual Studio Tool

Invoke OperationShared Code

DEMO

Mini

Out-of-Box Validation

o Server Sideo Metadata modello Required,Range,etc.

o Client Sideo System.ComponentModel.DataAnnotations.*o Entity.ValidateProperty()o INotifyErrorDataInfo

Out-of-Box Validation

DEMO

Mini

(Custom) Server Validation

o ValidationException

Mini

(Custom) Server Validation

o CustomValidationAttribute

(Custom) Server Validation

DEMO

Mini

Client & Server (shared) Validation

.shared

.cs

Client & Server (shared) Validation

DEMO

Entity Level validáció

DEMO

Async Server validációa kliens oldalon

DEMO

Mini

Összefoglalás

Kihívás Megoldás

Középső réteg kialakítása Domain Services (with WCF)LINQ + EF + POCO + stb.

Code/Logic megosztás Desing-time tools

Async kommunikáció Out-of-box WCF + DomainContext

Rétegeken átívelő validáció Metadata, code share, SL komponensek

Security: authentication & authorization Out-of-box ASP.Net+customization

Mini

Using RIA Services effectivelyDoo Require authentication / roleso Authenticate w/ https

o Utilize query compositiono Filter, sort, page

o Consider custom update

o Factor into multiple DomainService classes / libraries

o Handle errors on server

o Use declarative validation

Don’to Deploy with anon access

o Expose non-essential entities/ operations or allow free-form access to data

o Use a single large DomainService class

© 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.

Demo Title

NameTitleGroup

DEMO

Slide for Showing Developer’s Software Code

o Use this layout to show software codeo The font is Consolas, a monospace fonto The slide doesn’t use bullets but levels can be indented

using the “Increase List Level” icon on the Home menu

Mini

PowerPoint Guidelines

o Font, size, and color for text have been formatted for you in the Slide Master

o This template uses Segoe UI, a standard Windows Vista and Office 2007 font

o Use the color palette shown below

Sample FillSample FillSample Fill

Sample FillSample FillSample Fill

Slide for Showing Developer’s Software Code

o Use this layout to show software codeo The font is Consolas, a monospace fonto The slide doesn’t use bullets but levels can be indented

using the “Increase List Level” icon on the Home menu

Demo Title

NameTitleGroup

DEMO

Video Title

VIDEO

Partner Title

NameTitleCompany

PARTNER

Customer Title

NameTitleCompany

CUSTOMER

Announcement Title

ANNOUNCING

Slide for Showing Developer’s Software CodeUse this layout to show software codeThe font is Consolas, a monospace fontThe slide doesn’t use bullets but levels can be indented using the “Increase List Level” icon on the Home menu

Recommended