SlideShare uma empresa Scribd logo
1 de 27
.Net Ria Services for Silverlight Ian Blackburn Download RIA Services and documentation from http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&displaylang=en This presentation is a summary of the ~200 page document from there (plus some examples ;-)
Overview www.bbits.co.uk
Where do RIA Services Exist? www.bbits.co.uk
Presentation Technologies and DALs  The current preview illustrates the pattern primarily through the end-to-end experience with Silverlight and EF or Linq to Sql but RIA Services are designed to work other Presentation and DALS as well www.bbits.co.uk
Getting Started www.bbits.co.uk
The DomainService Class This is the main class for authoring operations  Such as CRUD behaviours It can be generated code in the first instance. You add your custom application logic to this class The [EnableClientAccess] attribute causes the tools to generate the corresponding client-tier classes when the project is built www.bbits.co.uk
The DomainContext Class A client side DomainContext class is generated for each DomainService This provides basic services such as invocation of operations, accumulation of results, object identity and change tracking  www.bbits.co.uk
Sharing Code Between Client and Server Code that is written in the server side can be reused in the client side.  To do this create a new class in the server side with a .shared.cs or .shared.vb suffix  Mark the class and methods you want to share with the [Shared] attribute After you build the solution, Visual Studio will copy this file to the Silverlight client application: www.bbits.co.uk
Creating Query Methods in the Service Define Query Methods in your Domain Service These must: return a single instance T, or an IEnumerable<T> or IQueryable<T> where T is a valid Entity type takes 0 or more parameters  Optionally be adorned with the QueryAttribute
Using Generated Query Methods in Silverlight When a query method is defined in the domain service, the code generator automatically creates  A query factory method named [NameOfQueryMethod]Query The entity Type of the query method  You use it by: createinganEntityQuery instance Applying LINQ query operators to it as needed Passing the query instance into DomainContext.Load
Example Note that the “orderby” is still happening on the server, and the Load is asynchronous
Support Query Operators in Silverlight EntityQuery exposes only a subset of LINQ query operators.  These are:  Where  OrderBy / ThenBy Skip / Take
Metadata classes To add some validation rules that are applied on both tiers, you create a metadata class for the Domain Service affectionately called the “buddy class” This can be generated when you create the domain service by checking the box shown Or you can just add the MetadataType attribute manually to an entity class www.bbits.co.uk
Using Include on MetaData You need to mark the Suppliers metadata with an equivalent Include attribute so the correct code is generated on the client
Adding Validation rules to the Metadata class www.bbits.co.uk This is achieved through attributes on the properties of the class on the server This causes the generated entity class in the client to have the same validation applied
Modifying Data If you use the DomainService class wizard to generate DomainService class, then the generated service class has Create/Read/Update/Delete (CRUD) operations  already
EntityContainer, EntityList and Change Tracking  Entities loaded into a DomainContext are stored and change tracked by its EntityContainer This is the Entities collection on the context object An EntityContainer manages a set of EntityLists there is a 1:1 mapping between EntityLists and the entity Types exposed by your service You can get a list of entities for a particular type using GetEntityList<T> You can inspect the Entity.EntityState of an entity to determine the state of the entity Unmodified, Modified, New, Deleted
Change Sets (Unit of Work)  A change set is a set of one or more entity operations to be processed as a single unit of work and can contain Entity Insert/Update/Delete operations  Custom domain operations When SubmitChanges is called on the context the changes are all sent to the service all together  You can get the current ChangeSet using the GetChanges method of the EntityContainer You can discard all pending changes, by calling  RejectChanges on the context.
Server Side Change Set Processing
Error Handling  You can throw validation exceptions in the Domain Service and then handle them in the client SubmitOperation completed event
Other Supported Features Concurrency Handling Concurrency errors are reported from the DomainService to the client You can handle them in the SubmitOperation completed event You can also create a Resolve method on your service to deal with resolution Transactions  Support No built in support from the client, but you can of course wrap your domain methods in transactions Identity Management  The Key attribute on entities is used to keep track of  local entities Whenever an entity is loaded if there is a cached instance locally with the same identity or key value(s) the local instance will be retained, and the newly read instance is discarded You can change this behaviour with the MergeOption in the context Load method
Custom Methods and Service Operations Using Custom Methods You can create custom server methods in addition to basic create/update/delete operations These also support tracking on entities and deferred execution (e.g. When SubmitChanges is called) Mark them with the [Custom] attribute Call from the context or the entity itself in the client Service Operations  More closely related to traditional web service Use the [ServiceOperation] attribute Don’t support tracking of deferred execution
Other features Silverlight DomainDataSource Use declarative code to define the interactions between your UI and the data  Supports filtering, sorting, grouping, editing... Restrict Access to DomainService Operations  You can authenticate using the membership system in asp.net Then configure access against operations roles and users Code Generated Hook Points  Partial methods are supported in the generated code to give extensibility points E.g. OnCreated, OnPropertyNameChanged
Other Features .NET RIA Services Class Libraries permits packaging business logic into N-tier class library components rather than the Silverlight client and Web Site Ado.Net Data Services Stated goal is to align the two technologies such that Microsoft .NET RIA Services uses the same protocol as ADO.NET Data Services  Business Applications Templates VS templates that builds on the Silverlight Navigation Application and using .NET RIA Services and provides support for Authentication and User Registration
Questions?
Concurrency Error
Naming Conventions Insert  “Insert”, “Add”, “Create” prefixes  Method signature : void InsertX(T entity), where T is an entity Type  Update  “Update”, “Change”, “Modify” prefixes  Method signature : void UpdateX(T current), where T is an entity Type  Delete  “Delete”, “Remove” prefixes  Method signature : void DeleteX(T entity), where T is an entity Type  Query  Method signature returning a singleton, IEnumerable<T> , IQueryable<T> where T is an entity Type, and taking zero or more parameters  Resolve  “Resolve” prefix  Method signature : boolResolveX(T curr, T original, T store, boolisDelete) where T is an entity type

Mais conteúdo relacionado

Mais de mark mann

MEF in Silverlight 4 - a guided tour
MEF in Silverlight 4 - a guided tourMEF in Silverlight 4 - a guided tour
MEF in Silverlight 4 - a guided tourmark mann
 
Silverlight UK User Group #11 Introduction
Silverlight UK User Group #11 IntroductionSilverlight UK User Group #11 Introduction
Silverlight UK User Group #11 Introductionmark mann
 
Silverlight UK User Group #10 Introduction
Silverlight UK User Group #10 IntroductionSilverlight UK User Group #10 Introduction
Silverlight UK User Group #10 Introductionmark mann
 
Designer-Developer Interaction
Designer-Developer InteractionDesigner-Developer Interaction
Designer-Developer Interactionmark mann
 
PRISM and Silverlight
PRISM and SilverlightPRISM and Silverlight
PRISM and Silverlightmark mann
 
SilverlightPulse.NET [Silverlight UK User Group]
SilverlightPulse.NET [Silverlight UK User Group]SilverlightPulse.NET [Silverlight UK User Group]
SilverlightPulse.NET [Silverlight UK User Group]mark mann
 

Mais de mark mann (6)

MEF in Silverlight 4 - a guided tour
MEF in Silverlight 4 - a guided tourMEF in Silverlight 4 - a guided tour
MEF in Silverlight 4 - a guided tour
 
Silverlight UK User Group #11 Introduction
Silverlight UK User Group #11 IntroductionSilverlight UK User Group #11 Introduction
Silverlight UK User Group #11 Introduction
 
Silverlight UK User Group #10 Introduction
Silverlight UK User Group #10 IntroductionSilverlight UK User Group #10 Introduction
Silverlight UK User Group #10 Introduction
 
Designer-Developer Interaction
Designer-Developer InteractionDesigner-Developer Interaction
Designer-Developer Interaction
 
PRISM and Silverlight
PRISM and SilverlightPRISM and Silverlight
PRISM and Silverlight
 
SilverlightPulse.NET [Silverlight UK User Group]
SilverlightPulse.NET [Silverlight UK User Group]SilverlightPulse.NET [Silverlight UK User Group]
SilverlightPulse.NET [Silverlight UK User Group]
 

Último

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

.NET RIA Services For Silverlight

  • 1. .Net Ria Services for Silverlight Ian Blackburn Download RIA Services and documentation from http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&displaylang=en This presentation is a summary of the ~200 page document from there (plus some examples ;-)
  • 3. Where do RIA Services Exist? www.bbits.co.uk
  • 4. Presentation Technologies and DALs The current preview illustrates the pattern primarily through the end-to-end experience with Silverlight and EF or Linq to Sql but RIA Services are designed to work other Presentation and DALS as well www.bbits.co.uk
  • 6. The DomainService Class This is the main class for authoring operations Such as CRUD behaviours It can be generated code in the first instance. You add your custom application logic to this class The [EnableClientAccess] attribute causes the tools to generate the corresponding client-tier classes when the project is built www.bbits.co.uk
  • 7. The DomainContext Class A client side DomainContext class is generated for each DomainService This provides basic services such as invocation of operations, accumulation of results, object identity and change tracking www.bbits.co.uk
  • 8. Sharing Code Between Client and Server Code that is written in the server side can be reused in the client side. To do this create a new class in the server side with a .shared.cs or .shared.vb suffix Mark the class and methods you want to share with the [Shared] attribute After you build the solution, Visual Studio will copy this file to the Silverlight client application: www.bbits.co.uk
  • 9. Creating Query Methods in the Service Define Query Methods in your Domain Service These must: return a single instance T, or an IEnumerable<T> or IQueryable<T> where T is a valid Entity type takes 0 or more parameters Optionally be adorned with the QueryAttribute
  • 10. Using Generated Query Methods in Silverlight When a query method is defined in the domain service, the code generator automatically creates A query factory method named [NameOfQueryMethod]Query The entity Type of the query method You use it by: createinganEntityQuery instance Applying LINQ query operators to it as needed Passing the query instance into DomainContext.Load
  • 11. Example Note that the “orderby” is still happening on the server, and the Load is asynchronous
  • 12. Support Query Operators in Silverlight EntityQuery exposes only a subset of LINQ query operators. These are: Where OrderBy / ThenBy Skip / Take
  • 13. Metadata classes To add some validation rules that are applied on both tiers, you create a metadata class for the Domain Service affectionately called the “buddy class” This can be generated when you create the domain service by checking the box shown Or you can just add the MetadataType attribute manually to an entity class www.bbits.co.uk
  • 14. Using Include on MetaData You need to mark the Suppliers metadata with an equivalent Include attribute so the correct code is generated on the client
  • 15. Adding Validation rules to the Metadata class www.bbits.co.uk This is achieved through attributes on the properties of the class on the server This causes the generated entity class in the client to have the same validation applied
  • 16. Modifying Data If you use the DomainService class wizard to generate DomainService class, then the generated service class has Create/Read/Update/Delete (CRUD) operations already
  • 17. EntityContainer, EntityList and Change Tracking Entities loaded into a DomainContext are stored and change tracked by its EntityContainer This is the Entities collection on the context object An EntityContainer manages a set of EntityLists there is a 1:1 mapping between EntityLists and the entity Types exposed by your service You can get a list of entities for a particular type using GetEntityList<T> You can inspect the Entity.EntityState of an entity to determine the state of the entity Unmodified, Modified, New, Deleted
  • 18. Change Sets (Unit of Work) A change set is a set of one or more entity operations to be processed as a single unit of work and can contain Entity Insert/Update/Delete operations Custom domain operations When SubmitChanges is called on the context the changes are all sent to the service all together You can get the current ChangeSet using the GetChanges method of the EntityContainer You can discard all pending changes, by calling RejectChanges on the context.
  • 19. Server Side Change Set Processing
  • 20. Error Handling You can throw validation exceptions in the Domain Service and then handle them in the client SubmitOperation completed event
  • 21. Other Supported Features Concurrency Handling Concurrency errors are reported from the DomainService to the client You can handle them in the SubmitOperation completed event You can also create a Resolve method on your service to deal with resolution Transactions Support No built in support from the client, but you can of course wrap your domain methods in transactions Identity Management The Key attribute on entities is used to keep track of local entities Whenever an entity is loaded if there is a cached instance locally with the same identity or key value(s) the local instance will be retained, and the newly read instance is discarded You can change this behaviour with the MergeOption in the context Load method
  • 22. Custom Methods and Service Operations Using Custom Methods You can create custom server methods in addition to basic create/update/delete operations These also support tracking on entities and deferred execution (e.g. When SubmitChanges is called) Mark them with the [Custom] attribute Call from the context or the entity itself in the client Service Operations More closely related to traditional web service Use the [ServiceOperation] attribute Don’t support tracking of deferred execution
  • 23. Other features Silverlight DomainDataSource Use declarative code to define the interactions between your UI and the data Supports filtering, sorting, grouping, editing... Restrict Access to DomainService Operations You can authenticate using the membership system in asp.net Then configure access against operations roles and users Code Generated Hook Points Partial methods are supported in the generated code to give extensibility points E.g. OnCreated, OnPropertyNameChanged
  • 24. Other Features .NET RIA Services Class Libraries permits packaging business logic into N-tier class library components rather than the Silverlight client and Web Site Ado.Net Data Services Stated goal is to align the two technologies such that Microsoft .NET RIA Services uses the same protocol as ADO.NET Data Services Business Applications Templates VS templates that builds on the Silverlight Navigation Application and using .NET RIA Services and provides support for Authentication and User Registration
  • 27. Naming Conventions Insert “Insert”, “Add”, “Create” prefixes Method signature : void InsertX(T entity), where T is an entity Type Update “Update”, “Change”, “Modify” prefixes Method signature : void UpdateX(T current), where T is an entity Type Delete “Delete”, “Remove” prefixes Method signature : void DeleteX(T entity), where T is an entity Type Query Method signature returning a singleton, IEnumerable<T> , IQueryable<T> where T is an entity Type, and taking zero or more parameters Resolve “Resolve” prefix Method signature : boolResolveX(T curr, T original, T store, boolisDelete) where T is an entity type