Share via

Model-Driven Development of .NET Enterprise Applications


Susan Entwisle and Steve Eadie
Electronic Data Systems (EDS)

May 2006

Applies to:
   Visual Studio 2005
   Visual Studio 2005 Domain Specific Language (DSL) Tools


Building an Entity Designer for Visual Studio
Code Generation Framework
Building an Enterprise Application with Entity Designer

Summary: Model-Driven Development represents the next logical step forward in software development methods and practices. It aims to facilitate the automatic construction of a software solution from a high-level domain-specific specification. This approach seeks to promote productivity, maintainability, expressiveness, and to aid in the management of complexity by supporting higher levels of abstraction and the systematic reuse of domain-specific assets. In this article, we explore the role of domain-specific languages and Visual Studio 2005 Domain Specific Language Tools (DSLs) and show how they can be used to automate the generation of an enterprise application for the .NET platform. (10 printed pages).


Over the last 30 years, the information technology industry has experienced constant and rapid advances in computing devices, software products and technologies, and changing requirements as consumers find new ways to use this technology. This is reflected in the industry's transition from primarily batch-oriented business applications hosted on the mainframe platform to distributed service-oriented applications that run on multiple computing platforms, such as laptops, handheld PDAs, and smart phones. Subsequently, advances in language paradigms, software design practices, and programming environments have been driven by the need to support reuse, adaptability, and the management of complexity within these software applications. These software characteristics are critical in order to support higher levels of agility, productivity, quality, maintenance, and evolution.

Like other engineering disciplines, the software development industry has used modeling as the basis to capture and communicate requirements, analysis, and design with its key stakeholders. However, often after the initial development of the software application these models are not maintained and the "code" becomes the model of the application. Furthermore, the analysis and design patterns contained within these models are not captured, standardized, and packaged for reuse across multiple software projects within the same or a similar application domain. Model-driven development attempts to address these issues by enabling reusable application domain knowledge, captured during domain engineering, to be represented in domain specific languages. These languages are meta-models that specify the application domain-modeling paradigm, including key concepts, relationships, constraints, and the rules governing code generation. Domain-specific languages can be represented either textually or visually within a domain model. Thus, they can be interpreted by humans, promoting communication about the intent of the software application, and processed by tools to facilitate the automated generation of the application. This approach supports improved project planning, promotes communication, increases quality, and reduces the risk and cost typically associated with software development.

Visual Studio 2005 Domain Specific Language Tools (DSLs) enable system integrators to extend the modeling platform to build custom visual designers for specific domains that are hosted within Visual Studio 2005. EDS have used this technology to create a visual designer for modeling the business entities within an enterprise application. Based on this model, a code generation framework manages the transition from the business entities in the model to the object-oriented C# implementation of the entities, data services, database, and unit tests for the application. The major advantage of this approach is EDS has been able to package knowledge about the construction of business entities for reuse in patterns, languages, and frameworks that can used within Visual Studio 2005. Electronic Data Systems .NET application developers can therefore leverage development tools that they are experts in while increasing productivity and quality through the use of the customized visual entity designer and the code generation framework.

Building an Entity Designer for Visual Studio

Notably, over the past decade UML has been the de facto standard for software modeling. The base constructs of the UML meta-model, such as classes, association, generalization, and so on, have little semantic meaning. Thus, in order to interpret and perform meaningful computations on a model the base constructs must be extended with domain-specific information. This approach provides the necessary semantic meaning and the constraints necessary to support meaningful automated code generation. The Domain Concept editor in the Domain Specific Languages Tools supports a UML-like notation that allows a software architect to perform this task by defining the domain-specific concepts, their attributes, and relationships between them. The domain model is persisted in an XML format. The domain model is used to generate a domain-specific API and to extend the Visual Studio development environment with the custom designer. This approach allows a software architect to create reusable domain-specific languages that can capture reusable analysis patterns and standards, such as the Healthcare HL7 standard, Sarbanes Oxley, and so on.

Figure 1 illustrates EDS' entity domain model that was created using the Domain Concept editor. The main concepts included within this domain model are: package, entity, entity attribute, and data services. Each of these concepts has been configured with a set of associated values, such as package namespace, entity name, database tablename, and so on. The key relationships within the domain model are generalization and association, which includes aggregation and composition.

Click here for larger image

Figure 1. Domain Concept Editor for entity domain model (click for larger image)

The Domain Specific Languages Designer Definition in the Domain Specific Languages tools is used with a domain model to both create the visual notation for the custom designer and to bind the visual elements to the underlying domain models in-memory store. The designer definitions are edited and persisted in XML format. The designer definition file allows the software architect to define the visual shapes that represent a domain concept, the connectors to represent relationships, constraints on the connectors that restrict what visual shapes can be connected, and the toolbox used within the designer. Below is a section of EDS' entity designer definition that defines the connector that is used to model an aggregation relationship. This example illustrates the use of constraints to define visual shapes that can be connected. Specifically, we have constrained the software developer to only be able to use an aggregate relationship connector between entity objects. These constraints are pivotal in reducing potential errors within model transformation and aid in improving the software developer's modeling experience.

<connector name="AggregationRelationshipLink">
  <color variability="Fixed" color="black" />
  <dashStyle variability="Fixed" dashStyle="solid"/>
    <connectorText name="Label" position="TargetBottom" defaultTextId=""/>
  <source arrowStyle="EmptyDiamond">
  <target arrowStyle="HollowArrow">

Figure 2 illustrates the custom entity designer hosted within Visual Studio. As highlighted, the custom entity designer leverages the Visual Studio development environment's standard user interface. This includes the Toolbox, Model Explorer, Properties Window, Validation Area, and the Design Surface. Each of these elements has been customized based on our defined domain model and designer definition. The custom entity model shown in Figure 2 illustrates a small subset of the business entities typically found within an order management system. Using the entity designer, the software developer can configure the business entities, and their properties and relationships, as required to meet their specific design requirements. This model, and others, developed using the entity designer can be used as input into EDS' code generation framework. The code generation framework accepts as input an XML representation of the model that is used to guide the automated generation of software artifacts, such as classes, database definitions, and so on, using templates. Domain Specific Languages Text Templates provide an ASP .NET like-syntax and transformation engine to enable software architects to generate text-based artifacts. EDS have used the text templates to write a custom XML serialization of the entity model, which is used as

input into EDS' code generation framework.

Click here for larger image

Figure 2. Entity Designer (click for larger image)

Code Generation Framework

EDS adopted a model-driven approach to software development approximately four years ago. This is EDS' standard approach for software development in order to support agility and the industrialization of software development. This approach is based on the EDS Accelerated Development Environment (ADE). The ADE represents a holistic approach to the software development process. It incorporates a highly integrated set of standard processes and tools for requirements gathering, analysis, design, testing, construction and deployment. This includes a base set of framework libraries, a code generation framework, and modeling tools that are hosted within Visual Studio. As illustrated in Figure 3 the code generation framework supports the transformation of a model to software artifacts using the following approach:

  1. The application's model is serialized into an XML file. This is typically initiated from within the application development environment.
  2. The code generation framework deserializes the XML file into an "in-memory store" representation.
  3. The code generation framework transforms the model into software artifacts that reflect the modeled requirements. The transformation uses text templates to generate software artifacts that use the ADE framework libraries. The text templates encapsulate best practices and patterns for architecting a .NET enterprise application.

Click here for larger image

Figure 3. Code Generation Framework overview (click for larger image)

The code generation framework also provides differencing tools to help the software developer manage changes in the model and in the previously generated software artifacts when they are regenerating a model. The major advantage of this is a software developer can perform code generation for a model while preserving changes that they may have manually made to previously generated software artifacts. For example, this allows a software developer to generate the source code for an entity and then add a business validation function prior to saving an entity's state. When this model is regenerated the software developer will be notified that there are differences between the newly generated source code generated from the model, compared to the updated source code that contains the new business validation function. The software developer can then use differencing tools to manage the changes prior to completing the code generation process. Upon completion of the code generation process the software artifacts are automatically moved into a Visual Studio solution.

Using the entity's model the code generation framework creates software artifacts for the Entities, Data Services, Data, and Unit Testing Layers.

Layer Description
Entities Contains public interface and implementation for the modeled entities. This includes the appropriate get/set methods for the attributes modeled on the entity and a primary key for the entity. Optionally, a public interface and implementation class can also be created to manage the entity as a collection.
Data Services Contains internal data adapters that encapsulate the basic CRUD commands for the model entities. The data adapters are not exposed outside of the data services layer and are invoked by the Data Services classes. The Data Services classes are responsible for managing persistency and concurrency for a model entity.
Data Contains SQL DDL and DML for the modeled entities. The DDL for the creation of a modeled entity table includes columns for the attributes model on the entity, a primary key and a concurrency stamp to support optimistic locking. The DML generated includes stored procedure commands to Select, Insert, Update, or Delete the individual rows of a modeled entity.
Unit Testing Contains test methods to validate the CRUD operations for each of the modeled entities. The data layer can also be optionally populated with random data using data scripts created during code generation.

Building an Enterprise Application with Entity Designer

In the sample model illustrated in Figure 4, we have a simple order management system with three business entities: Customer, PurchaseOrder, and CorporateCustomer. A Customer is associated with a one-to-many PurchaseOrder. A CorporateCustomer is derived from the Customer. This model can be easily extended to include new business entities, relationships, and data services using the standard toolbox, and it can be configured using the properties window.

Click here for larger image

Figure 4. Orders Management System entity model (click for larger image)

When software developers have finished designing the model they can initiate code generation using a Visual Studio plugin that provides access to the EDS code generation framework. Specifically, this plugin creates a custom serialization of the model using the text templating engine and then invokes EDS' code generation framework. The output of this code generation framework for the model illustrated, listed below, includes approximately 40 interfaces and classes and 24 database definitions and stored procedures.

Below is the PurchaseOrder interface; as shown it includes the appropriate get/set methods for this entity's defined attributes.

public interface IPurchaseOrder : IEntity
    string DateReceived { get; set; }
    string IsPrepaid { get; set; }
    string Number { get; set; }
    string Price { get; set; }
    Guid PurchaseOrderID { get; }
    Orders.Entities.ICustomerACol CustomerCol { get; }
    void Delete();
    void SetState(IPurchaseOrder fromEntity);

Below is the data definition generated to create the PurchaseOrder table. As shown the Customer entity's primary key is included in this table. An additional script is also generated to create a foreign key relationship to implement the modeled association between a Customer and a Purchase Order in the database.

CREATE TABLE dbo.PurchaseOrder
        PurchaseOrderID UniqueIdentifier NOT NULL
       ,PurchaseOrderCustomerID UniqueIdentifier NOT NULL
        ,ConcurrencyStamp UniqueIdentifier NOT NULL
        ,DateReceived VarChar(255) NOT NULL
        ,IsPrepaid VarChar(255) NOT NULL
        ,Number VarChar(255) NOT NULL
        ,Price VarChar(255) NOT NULL
ALTER TABLE dbo.PurchaseOrder ADD CONSTRAINT PK_PurchaseOrder_PurchaseOrderID PRIMARY KEY CLUSTERED (PurchaseOrderID)

The Purchase Order data services class operations are listed below. Data adapters are also created for each of the entities to support fetching and updating the data to and from the database.

public class PurchaseOrderDataSvc : EntityDataService
      public override IDbDataAdapter[] FillDataAdapters...
      public override IDbDataAdapter[] UpdateDataAdapters...
      public void Fetch(ref IPurchaseOrder purchaseOrder, IDictionary parameters)...
      public void Save(ref IPurchaseOrder purchaseOrder)...

Figure 5 illustrates the range of test cases that are generated for the Orders Management System. The automated generation of the test cases supports the use of test-driven development. This approach is emerging as one of the most successful productivity and quality enhancement techniques to be recently adopted by the software industry and supported in Visual Studio 2005.

Click here for larger image

Figure 5. Order Management Visual Studio 2005 unit tests (click for larger image)


The Microsoft Visual Studio 2005 and Domain Specific Language tools provide the modeling capabilities for architects to develop domain-specific designers. EDS are investigating use these features to build an Entity designer that leverages EDS' existing investment in model-driven development. This approach enables EDS to increase productivity and quality, and reduce cost in the delivery of client solutions through the reuse of assets that are based on best practices, patterns, and frameworks.


About the authors

Susan Entwisle is a Distinguished SE at EDS where she is a Software Architect in Asia Pacific Architect Practice working with the Accelerated Development Environment team responsible for EDS' standard .NET model-driven development tools and frameworks. Her main interests include model-driven development, software architecture and patterns, software reliability, and software methodologies.

Steve Eadie is a Software Architect within EDS's Portfolio Development responsible for EDS's work with Software Factories and Domain Specific Languages. His main interests include model-driven development, software methodologies, software architecture, and patterns and mobile computing.

© Microsoft Corporation. All rights reserved.