📒
OpenRiaServices
  • Start
  • Prerequisites for Open Ria Services
    • Walkthrough: Installing and Configuring SQL Server 2008 R2 Express with Advanced Services
    • Walkthrough: Installing the AdventureWorks OLTP and LT sample databases
  • Creating Open Ria Services Solutions
    • Walkthrough: Taking a Tour of Open Ria Services
    • Walkthrough: Creating a Open Ria Services Solution
    • Walkthrough: Creating a Open Ria Service with the Code First Approach
    • Walkthrough: Using the Silverlight Business Application Template
    • Walkthrough: Creating a Open Ria Services Class Library
    • Walkthrough: Localizing a Business Application
    • How to: Create a Domain Service that uses POCO-defined Entities
    • How to: Add or Remove a Open Ria Services Link
    • Using the Domain Service Wizard
  • Building Secure Applications with Open Ria Services
  • Deploying and Localizing a Open Ria Services Solutions
    • Troubleshooting the Deployment of a Open Ria Services Solution
    • Troubleshooting the Deployment of a Open Ria Services Solution
    • Walkthrough: Localizing a Business Application
  • Middle Tier
    • Domain Services
      • Walkthrough: Adding Query Methods
      • How to: Add Business Logic to the Domain Service
      • How to: Create a Domain Service that uses POCO-defined Entities
      • How to: Use HTTPS with a Domain Service
    • Data
      • Compositional Hierarchies
      • Presentation Models
      • Inheritance in Data Models
      • Complex Types
      • Shared Entities
      • Walkthrough: Sharing Entities between Multiple Domain Services
      • How to: Add Metadata Classes
      • How to: Validate Data
      • Managing Data Concurrency
    • Shared Code
      • How to: Share Code through Source Files
      • Walkthrough: Creating a Open Ria Services Class Library
  • Silverlight Clients
    • Client Code Generation
    • DomainContext and Operations
    • DomainDataSource
    • Error Handling on the Client
    • Customizing Generated Code
      • How to: Add Computed Properties on the Client
  • Accessing non-Silverlight Clients
    • ASP.NET Clients
    • Walkthrough: Using the Domain Service in ASP.NET Applications
  • Authentication, Roles, and Profiles
    • How to: Enable Authentication in Open Ria Services
    • How to: Enable Roles in Open Ria Services
    • How to: Enable Profiles in Open Ria Services
    • How to: Create a Custom Authorization Attribute
    • Walkthrough: Using Authentication Service with Silverlight Business Application
    • Walkthrough: Using Authentication Service with Silverlight Navigation Application
  • End-to-EndScenarios
    • Walkthrough: Retrieving and Displaying Data From a Domain Service
    • Walkthrough: Editing Data From a Domain Service
    • Walkthrough: Displaying Data in a Silverlight Business Application
    • Walkthrough: Displaying Related Data in a Silverlight Business Application
Powered by GitBook
On this page
  • Shared Source Files
  • Shared Naming Convention
  • Linked Files
  • Shared Assemblies

Was this helpful?

  1. Middle Tier

Shared Code

PreviousManaging Data ConcurrencyNextHow to: Share Code through Source Files

Last updated 4 years ago

Was this helpful?

[ This document was written for WCF Services Version 1 Service Pack 2 and might not be up to date Please see or for a list of changes since WCF RIA Services ]

Open Ria Services enables you to write application logic that is shared between the middle tier and the presentation tier and so provides identical functionality on both the server and the client. Code can be shared either with source files or assemblies.

Unlike the automatic code generation process described in the topic, shared code is not altered during compilation. Instead, the code is either copied or shared verbatim between the tiers. Shared code allow you to define pieces of logic or partial class extensions for your entities that are defined once on the server, but that get code generated on the client as well, so that the same logic is available for use in both places.

Shared Source Files

You can add source files to the middle tier and then explicitly designate those files for sharing with the presentation tier. There are two approaches to sharing source files between the tiers. The first approach is to name the source files according to a shared naming convention: *.shared.cs (for C#) or *.shared.vb (for Visual Basic). The second approach is to use the linked files feature in Visual Studio.

Shared Naming Convention

When you use the shared naming convention (*.shared.cs or *.shared.vb) to share files, you implement a "push" model for sharing source code files. The shared files are actively copied from the middle-tier project to the client project during compilation. The shared naming convention works for sharing files only when a Open Ria Services link exists between the client and server projects.

The shared naming convention has the following advantages:

Shared Naming Convention Advantages

Description

Built-in support

No further action by the developer is required to keep the shared files synchronized.

Transparent

The name clearly indicates the file is intended for sharing.

Self-maintained

As new shared files are added, all client projects linked to the middle tier are automatically updated when the solution is compiled.

Easy-to-understand debugging experience

The developer can set breakpoints in the server or client versions of the file.

The shared naming convention has the following disadvantages:

Shared Naming Convention Disadvantages

Description

New concept

The developer must be aware of the shared naming convention.

Files are copied

The shared files are physically copied to client projects, which means that a developer may accidentally edit the copied version and lose changes during the next compilation.

Linked Files

Linked files is an existing feature of Visual Studio and is not unique to Open Ria Services. A Open Ria Services link between projects can exist, but it is not required to use linked files. When you use the linked files approach, you implement a "pull" model for sharing source code files. The client project does not contain a copy of the file. Instead, the client project just references the file in the server project.

You can also link both the server and the client projects to a file in another project.

The linked file approach has the following advantages:

Linked Files Advantages

Description

Existing Visual Studio feature

The developer does not have to learn a new convention.

File is not copied

The file only exists in the server project. Therefore, the developer cannot change a copied version of the client and lose those changes during the next compilation.

The linked file approach has the following disadvantages:

Linked Files Disadvantages

Description

Requires explicit user action

The developer must link each shared file.

No self-maintenance

Each client project must be updated as shared files are added or removed.

Lacks transparency

The developer must examine the project file to determine which files are shared.

Awkward debugging experience

It is not easy to determine which tier prompted a breakpoint.

Shared Assemblies

Instead of sharing source files between projects, you can compile code into a class library and then share the library through assembly references. You use the Open Ria Services class libraries to make sure that the assemblies are compatible, even when used with different frameworks (such as the .NET Framework version 4 and Silverlight 5).

The following diagram shows an n-tier application that uses Open Ria Services class libraries to share code. The middle tier and the client tier use assembly references to the class libraries.

For more information, see .

For more information, see .

For more information about Open Ria Services class libraries, see and Walkthrough: Creating a Open Ria Services Class Library.

How to: Share Code through Source Files
How to: Share Code through Source Files
Creating Open Ria Services Solutions
Release Notes
Changelog
Client Code Generation
Shared File
Linked File
Linked Files
Class Library Structure