Microsoft® .NET: Architecting Applications for the Enterprise

Book description

Make the right architectural decisions up front—and improve the quality and reliability of your results. Led by two enterprise programming experts, you’ll learn how to apply the patterns and techniques that help control project complexity—and make systems easier to build, support, and upgrade—right from the start.



Get pragmatic architectural guidance on how to:

  • Build testability, maintainability, and security into your system early in the design

  • Expose business logic through a service-oriented interface

  • Choose the best pattern for organizing business logic and behavior

  • Review and apply the patterns for separating the UI and presentation logic

  • Delve deep into the patterns and practices for the data access layer

  • Tackle the impedance mismatch between objects and data

  • Minimize development effort and avoid over-engineering—and deliver more robust results


  • Get code samples on the Web.

    Table of contents

    1. Acknowledgments
      1. Dino’s Credits
      2. Andrea’s Credits
    2. Introduction
      1. What Is Architecture?
      2. Who This Book Is For
      3. Companion Content
      4. Hardware and Software Requirements
      5. Find Additional Content Online
      6. Support for This Book
        1. Questions and Comments
    3. I. Principles
      1. 1. Architects and Architecture Today
        1. What’s a Software Architecture, Anyway?
          1. Applying Architectural Principles to Software
            1. Defining the Architecture from a Standard Viewpoint
            2. Examining Key Architecture-Related Points in ANSI/IEEE 1471
            3. Defining the System from a Standard Viewpoint
            4. Describing the Architecture
            5. Validating the Architecture
          2. What’s Architecture and What’s Not
            1. No System Is a Monolith
            2. Defining the Borderline Between Architecture and Implementation
            3. Dealing with Hard-to-Change Decisions
          3. Architecture Is About Decisions
            1. Changing the Organization of the Business Logic
            2. Switching to a Different Library
            3. Changing the Constructor’s Signature
            4. Changing a Member’s Modifiers
          4. Requirements and Quality of Software
            1. Examining the ISO/IEC 9126 Standard
            2. Functional Requirements
            3. Nonfunctional Requirements
            4. Gathering Requirements
            5. Specifications
            6. Methodology and the Use of Requirements
        2. Who’s the Architect, Anyway?
          1. An Architect’s Responsibilities
            1. Acknowledging the Requirements
            2. Breaking Down the System
            3. Identifying and Evaluating Technologies
            4. Formulating Specifications
          2. How Many Types of Architects Do You Know?
          3. Common Misconceptions About Architects
            1. The Architect Is an Analyst
            2. The Architect Is a Project Manager
            3. The Architect Never Writes Any Code
        3. Overview of the Software Development Process
          1. The Software Life Cycle
            1. Processes
            2. Activities
          2. Models for Software Development
            1. Traditional Methodologies
            2. Agile Methodologies
            3. Microsoft Solutions Framework
        4. Summary
        5. Murphy’s Laws of the Chapter
      2. 2. UML Essentials
        1. UML at a Glance
          1. Motivation for and History of Modeling Languages
            1. UML Predecessors
            2. Versions and Standards of UML
            3. The Strengths and Weaknesses of UML
            4. UML in Practice
          2. UML Modes and Usage
            1. UML as a Sketch
            2. UML as a Blueprint
            3. UML as a Programming Language
            4. How We Use UML in Our Own Real World
        2. UML Diagrams
          1. Use-Case Diagrams
            1. A Look at the Notation
            2. Generic Relationships
            3. Inclusion
            4. Extension
            5. Generalization
          2. Class Diagrams
            1. A Look at the Notation
            2. Attributes
            3. Operations
            4. Associations
            5. Generalization
            6. Dependency
          3. Sequence Diagrams
            1. A Look at the Notation
            2. Life and Death of an Object
            3. Asynchronous Messages
            4. Standing in the Way of Control
        3. Summary
        4. Murphy’s Laws of the Chapter
      3. 3. Design Principles and Patterns
        1. Basic Design Principles
          1. For What the Alarm Bell Should Ring
            1. Rigid, Therefore Fragile
            2. Easier to Use Than to Reuse
            3. Easier to Work Around Than to Fix
          2. Structured Design
            1. From Spaghetti Code to Lasagna Code
            2. Cohesion
            3. Coupling
          3. Separation of Concerns
            1. Identifying the Concerns
            2. Modularity
            3. Information Hiding
            4. SoC and Programming Paradigms
        2. Object-Oriented Design
          1. Basic OOD Principles
            1. Find Pertinent Objects First
            2. Favor Low Coupling
            3. Favor Code Reuse
          2. Advanced Principles
            1. The Open/Closed Principle
            2. Liskov’s Substitution Principle
            3. The Dependency Inversion Principle
        3. From Principles to Patterns
          1. What’s a Pattern, Anyway?
            1. Design Patterns
            2. How to Work with Design Patterns
            3. Where’s the Value in Patterns, Exactly?
            4. Applied Design Patterns
            5. Architectural Patterns
          2. Patterns vs. Idioms
            1. What’s an Idiom, Anyway?
            2. Sample Idioms
            3. Idiomatic Design
            4. Idiomatic Design: Structures or Classes?
            5. Idiomatic Design: Do Not Use List<T> in Public Signatures
          3. Dependency Injection
            1. From DIP to Inversion of Control
            2. IoC Frameworks
            3. IoC Containers in Action
        4. Applying Requirements by Design
          1. Testability
            1. Software Testing
            2. Software Contracts
            3. Unit Testing
            4. Unit Testing in Action
            5. Dealing with Dependencies
            6. From Fakes to Mocks
          2. Security
            1. Security as a (Strict) Requirement
            2. Security Development Lifecycle
            3. Foundations of SDL: Layering
            4. Foundations of SDL: Componentization
            5. Foundation of SDL: Roles
            6. Threat Model
            7. Security and the Architect
            8. Final Security Push
        5. From Objects to Aspects
          1. Aspect-Oriented Programming
            1. Cross-Cutting Concerns
            2. Processing Aspects
            3. Inside AOP Aspects
            4. AOP in .NET
          2. AOP in Action
            1. Enabling Policies
            2. Defining Policies
            3. Defining Handlers
        6. Summary
        7. Murphy’s Laws of the Chapter
    4. II. Design of the System
      1. 4. The Business Layer
        1. What’s the Business Logic Layer, Anyway?
          1. Dissecting the Business Layer
            1. The Domain’s Object Model
            2. The Domain Entities
            3. Business Rules
            4. Validation
            5. Business Processes and Workflows
          2. Where Would You Fit the BLL?
            1. Layer vs. Tier
            2. Why Should You Care About Layers?
            3. Why Should You Care About Tiers?
            4. Exposing BLL to the World
            5. Hosting BLL
          3. Business and Other Layers
            1. BLL Distribution and Measurements
            2. Gray Area #1: Data Formatting
            3. Gray Area #2: CRUD Operations
            4. Gray Area #3: Stored Procedures
          4. Patterns for Creating the Business Layer
            1. Why Patterns for the BLL?
            2. Procedural Patterns
            3. Object-Based Patterns
            4. Differences at a Glance
            5. Object-Based vs. Procedural Patterns
            6. A Quick Measure of Complexity
        2. The Transaction Script Pattern
          1. Generalities of the TS Pattern
            1. When to Use TS
            2. What’s Good About TS
            3. What’s Bad About TS
          2. The Pattern in Action
            1. Designing Business Components
            2. Implementing Business Components
            3. Business Components as Command Objects
            4. Considerations About the Command Pattern
            5. Static and Instance Methods
            6. Passing Data to Transaction Scripts
        3. The Table Module Pattern
          1. Generalities of the TM Pattern
            1. When to Use TM
            2. What’s Good About TM
            3. What’s Bad About TM
            4. Gimme a Quick Answer: TS or TM?
          2. The TM Pattern in Action
            1. Internals of a Business Component
            2. Typical Structure of a Business Component
            3. Typed DataSets
            4. Table Adapters
            5. The Table Data Gateway Pattern
        4. The Active Record Pattern
          1. Generalities of the AR Pattern
            1. When to Use AR
            2. What’s Good About AR
            3. What’s Bad About AR
          2. The AR Pattern in Action
            1. A Typical Active Record Class
            2. The Foreign-Key Mapping Pattern
            3. Data Conversion
            4. The Row Data Gateway Pattern
            5. LINQ-to-SQL
            6. Is LINQ-to-SQL an Active Record?
            7. Castle ActiveRecord
        5. The Domain Model Pattern
          1. Generalities of the DM Pattern
            1. When to Use DM
            2. What’s Good About DM
            3. What’s Bad About DM
          2. The DM Pattern in Action
            1. Designing the Domain Model
            2. The Logic in the Domain Objects
            3. Persistence Ignorance
            4. Entities and Value Objects
            5. The Repository Pattern
            6. Mapping Objects to Tables
            7. The Special Case Pattern
        6. Summary
        7. Murphy’s Laws of the Chapter
      2. 5. The Service Layer
        1. What’s the Service Layer, Anyway?
          1. Responsibilities of the Service Layer
            1. What the Service Layer Is Intended For
            2. Orchestrating the System’s Behavior
          2. What’s a Service, Anyway?
            1. What’s Service Orientation?
            2. Our Definition of a Service
            3. Service vs. Class
            4. Is Every Class a Service?
          3. Services in the Service Layer
            1. From Code-Behind to Services
            2. Benefits of a Service Layer
            3. Macro and Micro Services
        2. The Service Layer Pattern in Action
          1. Generalities of the Service Layer Pattern
            1. Real-World Examples of a Service Layer
            2. When to Use a Service Layer
            3. What’s Good About a Service Layer
            4. What’s Bad About a Service Layer
            5. Where Does a Service Layer Fit?
          2. The Service Layer Pattern in Action
            1. Designing a Service Layer Class
            2. Implementing a Service Layer Class
            3. Dealing with Roles and Security
            4. Service Layer and Transaction Script
            5. Domain Logic and Application Logic
        3. Related Patterns
          1. The Remote Façade Pattern
            1. Motivation for Using the Remote Façade Pattern
            2. The Remote Façade Pattern and the Service Layer
          2. The Data Transfer Object Pattern
            1. Motivation for Using the Pattern
            2. Data Transfer Object and Service Layer
          3. The Adapter Pattern
            1. Motivation for Using the Adapter Pattern
            2. The Adapter Pattern and the Service Layer
          4. DTO vs. Assembly
            1. Examining Some DTO Facts
            2. DTO in Action: Load an Order
            3. DTO in Action: Update an Order
            4. When You Can Do Without DTOs
            5. What You Gain and What You Lose
        4. Service-Oriented Architecture
          1. Tenets of SOA
            1. Boundaries Are Explicit
            2. Services Are Autonomous
            3. Use Contracts, Not Classes
            4. Compatibility Is Based on Policy
            5. A Summary of the Tenets
          2. What SOA Is Not
            1. SOA Is Not a Revolution
            2. SOA Is Not a Technology
            3. SOA Is Not a Web Service
            4. SOA Is Not a Goal
          3. SOA and the Service Layer
            1. SOA in Practice
            2. What’s Good About Using SOA in the Service Layer
            3. SOA Antipatterns
            4. CRUDy Interfaces
            5. Chatty Interfaces
        5. The Very Special Case of Rich Web Front Ends
          1. Refactoring the Service Layer
            1. Why Rich Web-Based Clients Are a Problem
            2. Refactoring for Functionality
            3. Refactoring for Security
          2. Designing an AJAX Service Layer
            1. Script-Enabling ASP.NET XML Web Services
            2. Script-Enabling WCF Services
            3. Generating JavaScript Proxies
            4. JSON vs. XML
          3. Securing the AJAX Service Layer
            1. Detecting Outsiders
            2. Login Pages Never Go Out of Style
            3. Checking Identity and Authorization in the Service
        6. Summary
        7. Murphy’s Laws of the Chapter
      3. 6. The Data Access Layer
        1. What’s the Data Access Layer, Anyway?
          1. Functional Requirements of the Data Access Layer
            1. Database Independence
            2. Configurable as a Plug-in
            3. Persisting the Application’s Object Model
          2. Responsibilities of the Data Access Layer
            1. CRUD Services
            2. Query Services
            3. Transactions Management
            4. Handling Concurrency
            5. Putting It All Together: The Data Context
          3. The Data Access Layer and Other Layers
            1. The DAL and the Business Layer
            2. The DAL and the Service Layer
            3. The DAL and the Presentation Layer
        2. Designing Your Own Data Access Layer
          1. The Contract of the DAL
            1. The Separated Interface Pattern
            2. Program to a (DAL) Interface
            3. Abstracting the Capabilities of a DAL
          2. The Plugin Pattern
            1. Generalities of the Plugin Pattern
            2. The DAL Factory in Action
            3. Building a DAL Plugin
            4. Service Locator vs. Plugin
          3. The Inversion of Control Pattern
            1. Injecting a Reference to the DAL
            2. Inversion of Control in Action Through Unity
            3. Dependency Injection Mechanisms
            4. Inversion of Control vs. Plugin
          4. Laying the Groundwork for a Data Context
            1. The IDataContext Interface
            2. A Common Class for the Data Context
        3. Crafting Your Own Data Access Layer
          1. Implementing the Persistence Layer
            1. The Gateway to Storage
            2. A Factory for Data Mappers
            3. Inside Data Mappers
            4. Bridging Types and Tables
            5. Cross-Table Operations
          2. Implementing Query Services
            1. A Repository of Objects
            2. Implementing a Repository
            3. Basic Query Capabilities
            4. Query by Criteria
          3. Implementing Transactional Semantics
            1. Defining a Unit of Work
            2. Scheduled Actions
            3. Managing DAL Transactions
          4. Implementing Uniquing and Identity Maps
            1. Getting Unique Objects
            2. Implementing an Identity Map
            3. Uniquing Is Not Like Caching
            4. An Identity Map Looks, Walks, and Quacks Like a Cache
            5. Caching and Queries: A Not So Powerful Duo
          5. Implementing Concurrency
            1. Don’t Worry, Be Optimistic
            2. Specializing the Data Mapper
            3. Creating a Proxy for the Entity
            4. Using a Timestamp Column
          6. Implementing Lazy Loading
            1. On-Demand Data Loading
            2. Hard-Coded Fetch Plans
            3. Specifying a Dynamic Fetch Plan
        4. Power to the DAL with an O/RM Tool
          1. Object/Relational Mappers
            1. Do I Really Need an O/RM Tool?
            2. If Only We Could Have an Object-Oriented DBMS
            3. Creating an O/R Mapping Layer
            4. Sample O/RM Tools
          2. Using an O/RM Tool to Build a DAL
            1. The O/RM Is Your Data Context
            2. Object Services with an O/RM
            3. Transactions with an O/RM
            4. Querying with an O/RM
            5. The Domain Model and Persistence Ignorance
            6. Why Is Persistence Ignorance So Desirable?
        5. To SP or Not to SP
          1. About Myths and Stored Procedures
            1. Myth: Stored Procedures Are Faster Than SQL Code
            2. Myth: Stored Procedures Are More Secure Than SQL Code
            3. Myth: Stored Procedures Can Be Used to Fend Off SQL Injection
            4. Myth: Stored Procedures Can Be Used to Reduce Brittleness of SQL Code
            5. What Stored Procedures Are For
            6. Should You Use Stored Procedures?
          2. What About Dynamic SQL?
            1. Embedding SQL Statically
            2. The Turning Point Created by O/R Mappers
            3. Do You Still Need a DBA?
        6. Summary
        7. Murphy’s Laws of the Chapter
      4. 7. The Presentation Layer
        1. User Interface and Presentation Logic
          1. Responsibilities of the Presentation Layer
            1. Independence from Graphics
            2. Independence from UI Technology
            3. Support for Testing
            4. Independence from a Model of the Data
          2. Responsibilities of the User Interface
            1. Useful Data Display
            2. Comfortable Data Entry
            3. General Appearance
          3. Common Pitfalls of a Presentation Layer
            1. RADness in the Presentation
            2. Boundaries of the Presentation Layer
            3. What Users Get Is What You Want
        2. Evolution of the Presentation Patterns
          1. The Model-View-Controller Pattern
            1. Moving Away from Autonomous Views
            2. MVC: Pattern or Paradigm?
            3. Generalities of the MVC Pattern
            4. The Model in MVC
            5. The View in MVC
            6. The Controller in MVC
            7. Model2: A Web Variation of MVC
          2. The Model-View-Presenter Pattern
            1. Generalities of the MVP Pattern
            2. The Model in MVP
            3. The View in MVP
            4. The Presenter in MVP
            5. MVP and Enterprise-Class Applications
          3. The Presentation Model Pattern
            1. The Model in PM
            2. The View in PM
            3. The Presenter in PM
          4. Choosing a Pattern for the User Interface
            1. My Focus Is the Web
            2. My Focus Is Windows
            3. I Need to Support Multiple GUIs
        3. Design of the Presentation
          1. What Data Is Displayed in the View?
            1. Creating a Contract for the View
            2. How Much Logic Do You Want in the View?
            3. Do You Want a Passive View?
            4. Implementing the Contract in the View
          2. Processing User Actions
            1. Connecting View and Presenter
            2. Building the Presenter
            3. Executing User Actions
            4. The Presenter and the Service Layer
            5. Selecting the Next View
            6. Cardinality of Views, Presenters, and Application Controllers
        4. Idiomatic Presentation Design
          1. MVP in Web Presentations
            1. The Web Client Software Factory
            2. The ASP .NET MVC Framework
          2. MVP in Windows Presentations
            1. The Smart Client Software Factory
            2. The MVC# Framework
            3. Windows Presentation Foundation
        5. Summary
        6. Murphy’s Laws of the Chapter
    5. A. Final Thoughts
      1. Mantra #1—It Depends
      2. Mantra #2—Requirements Are Lord Over All
      3. Mantra #3—Program to an Interface
      4. Mantra #4—Keep It Simple but Not Simplistic
      5. Mantra #5—Inheritance Is About Polymorphism, Not Reuse
      6. Mantra #6—Not the DAL? Don’t Touch SQL Then
      7. Mantra #7—Maintainability First
      8. Mantra #8—All User Input Is Evil
      9. Mantra #9—Post-Mortem Optimization
      10. Mantra #10—Security and Testability Are by Design
    6. B. The Northwind Starter Kit
      1. Motivation for Creating NSK
        1. Downloading NSK
        2. NSK Requirements
        3. The Northwind Database
      2. What’s in NSK?
        1. The Data Folder
        2. The Business Folder
        3. The Presentation Folder
      3. Future Evolution of NSK
    7. C. About the Authors
      1. Dino Esposito
      2. Andrea Saltarello
    8. Index
    9. About the Authors
    10. Copyright

    Product information

    • Title: Microsoft® .NET: Architecting Applications for the Enterprise
    • Author(s): Dino Esposito and Andrea Saltarello
    • Release date: October 2008
    • Publisher(s): Microsoft Press
    • ISBN: 9780735626096