You are previewing Expert C# 2008 Business Objects.
O'Reilly logo
Expert C# 2008 Business Objects

Book Description

Do you want to create .NET applications that provide high performance and scalability? Do you want to employ object-oriented programming techniques in a distributed environment? Do you want to maximize the reuse and maintainability of your code? Then this book is for you.

In Rockford Lhotka's Expert C# 2008 Business Objects, you'll learn how to use advanced .NET Framework capabilities alongside OO design and programming to create scalable, maintainable object-oriented applications. Better still, this book includes CSLA .NET 3.6, a widely used framework on which you can base your application development. By using the concepts and framework in the book, you can focus more on your business issues and less on technology.

Using VS 2008 and C# 3.0, Rockford Lhotka shows you how CSLA .NET 3.6 allows great flexibility in object persistence, so business objects can use virtually any data sources available. The CSLA framework supports 1-, 2- and n-tier models through the concept of mobile objects. This provides the flexibility to optimize performance, scalability, security, and fault tolerance with no changes to code in the UI or business objects.

Business objects based on CSLA.NET 3.6 automatically gain many advanced features that simplify the creation of Windows forms, web forms, WPF, WCF, WF, and web services interfaces, and LINQ.

Table of Contents

  1. Copyright
  2. About the Author
  3. About the Technical Reviewers
  4. Acknowledgments
  5. Introduction
  6. 1. Distributed Architecture
    1. 1.1. Logical and Physical Architecture
      1. 1.1.1. N-Tier and SOA
      2. 1.1.2. Complexity
      3. 1.1.3. Relationship Between Logical and Physical Models
      4. 1.1.4. A 5-Layer Logical Architecture
      5. 1.1.5. Applying the Logical Architecture
      6. 1.1.6. The Way Ahead
    2. 1.2. Managing Business Logic
      1. 1.2.1. Potential Business Logic Locations
      2. 1.2.2. Business Objects
      3. 1.2.3. Mobile Objects
    3. 1.3. Architectures and Frameworks
    4. 1.4. Conclusion
  7. 2. Framework Design
    1. 2.1. Basic Design Goals
      1. 2.1.1. Validation and Business Rules
      2. 2.1.2. Tracking Whether the Object Has Changed
      3. 2.1.3. Integrated Authorization
      4. 2.1.4. Strongly Typed Collections of Child Objects
      5. 2.1.5. N-Level Undo Capability
      6. 2.1.6. Simple and Abstract Model for the UI Developer
      7. 2.1.7. Supporting Data Binding
      8. 2.1.8. Object Persistence and Object-Relational Mapping
      9. 2.1.9. Custom Authentication
    2. 2.2. Designing the Framework
      1. 2.2.1. Business Object Creation
      2. 2.2.2. N-Level Undo Functionality
      3. 2.2.3. Data Binding Support
      4. 2.2.4. Business and Validation Rules
      5. 2.2.5. Data Portal
      6. 2.2.6. Custom Authentication
      7. 2.2.7. Integrated Authorization
      8. 2.2.8. Helper Types and Classes
    3. 2.3. Namespace Organization
    4. 2.4. Conclusion
  8. 3. Object-Oriented Application Design
    1. 3.1. Responsibility-Driven Design
      1. 3.1.1. Use-Case or Story-Based Analysis
      2. 3.1.2. Objects with Responsibilities
      3. 3.1.3. Objects Exist for Use Cases
      4. 3.1.4. Normalization of Behavior
    2. 3.2. Application Requirements
      1. 3.2.1. Use Cases
    3. 3.3. Object Design
      1. 3.3.1. Initial Design
      2. 3.3.2. Revising the Design
      3. 3.3.3. Custom Authentication
    4. 3.4. Using CSLA .NET
    5. 3.5. Database Design
      1. 3.5.1. Creating the Databases
      2. 3.5.2. PTracker Database
      3. 3.5.3. Security Database
    6. 3.6. Conclusion
  9. 4. CSLA .NET Object Stereotypes
    1. 4.1. Basic Terminology and Object Graph Structure
    2. 4.2. Business Object Life Cycle
      1. 4.2.1. Object Creation
      2. 4.2.2. Object Retrieval
      3. 4.2.3. Updating Editable Objects
      4. 4.2.4. Disposing and Finalizing Objects
    3. 4.3. Business Class Structure
      1. 4.3.1. The Serializable or DataContract Attribute
      2. 4.3.2. Common Regions
      3. 4.3.3. Non-public Default Constructor
    4. 4.4. Conclusion
  10. 5. CSLA .NET Object Templates
    1. 5.1. Business Class Structure
      1. 5.1.1. Editable Root Business Objects
      2. 5.1.2. Editable Child Business Objects
      3. 5.1.3. Switchable Objects
      4. 5.1.4. Editable Root Collection
      5. 5.1.5. Editable Child Collection
      6. 5.1.6. Read-Only Business Objects
      7. 5.1.7. Read-Only Child Objects
      8. 5.1.8. Read-Only Collection
      9. 5.1.9. Read-Only Child Collection
      10. 5.1.10. Command Objects
      11. 5.1.11. Name/Value List Objects
      12. 5.1.12. Dynamic Editable Collection
      13. 5.1.13. Dynamic Editable Root Objects
      14. 5.1.14. Criteria Objects
    2. 5.2. Conclusion
  11. 6. Business Framework Implementation
    1. 6.1. CSLA .NET Project Structure
      1. 6.1.1. Project Directory Structure
      2. 6.1.2. Project Settings
      3. 6.1.3. Project Signing
      4. 6.1.4. Supporting Localization
    2. 6.2. Csla Namespace
      1. 6.2.1. ApplicationContext
      2. 6.2.2. BusinessBase
      3. 6.2.3. BusinessListBase
      4. 6.2.4. CommandBase
      5. 6.2.5. CriteriaBase
      6. 6.2.6. DataPortal
      7. 6.2.7. EditableRootListBase
      8. 6.2.8. NameValueListBase
      9. 6.2.9. PropertyInfo
      10. 6.2.10. ReadOnlyBase
      11. 6.2.11. ReadOnlyListBase
      12. 6.2.12. SingleCriteria
      13. 6.2.13. SmartDate
      14. 6.2.14. Utilities
    3. 6.3. Csla.Core Namespace
      1. 6.3.1. BusinessBase
      2. 6.3.2. ExtendedBindingList
      3. 6.3.3. IBusinessObject Interface
      4. 6.3.4. ICommandObject Interface
      5. 6.3.5. IEditableBusinessObject Interface
      6. 6.3.6. IEditableCollection Interface
      7. 6.3.7. IReadOnlyObject Interface
      8. 6.3.8. IReadOnlyCollection Interface
      9. 6.3.9. ISavable Interface
      10. 6.3.10. ISmartField Interface
      11. 6.3.11. ISupportUndo Interface
      12. 6.3.12. ITrackStatus Interface
      13. 6.3.13. IUndoableObject Interface
      14. 6.3.14. ObjectCloner Class
      15. 6.3.15. ReadOnlyBindingList
    4. 6.4. Conclusion
  12. 7. Property Declarations
    1. 7.1. Declaring Properties
      1. 7.1.1. Property Declaration Options
      2. 7.1.2. RegisterProperty and Inheritance
    2. 7.2. PropertyInfoManager
    3. 7.3. Field Manager
      1. 7.3.1. FieldManager Property
      2. 7.3.2. FieldDataManager Class
    4. 7.4. Conclusion
  13. 8. Object Status Management
    1. 8.1. Object Status Properties
      1. 8.1.1. ITrackStatus Interface
      2. 8.1.2. IsNew
      3. 8.1.3. IsSelfDirty
      4. 8.1.4. IsDirty
      5. 8.1.5. IsSelfValid
      6. 8.1.6. IsValid
      7. 8.1.7. IsSavable
      8. 8.1.8. IsDeleted
    2. 8.2. Conclusion
  14. 9. Parent-Child Relationships
    1. 9.1. Parent Editable Object
      1. 9.1.1. Parent-Child Interaction
      2. 9.1.2. IParent Interface
      3. 9.1.3. Declaring Child Properties
    2. 9.2. Parent Editable Collection
      1. 9.2.1. Parent-Child Interaction
    3. 9.3. Conclusion
  15. 10. Data Binding
    1. 10.1. Windows Forms
      1. 10.1.1. Object Data Binding
      2. 10.1.2. Collection Data Binding
      3. 10.1.3. Controls and Helper Objects
      4. 10.1.4. Working with Multiple Root Objects
    2. 10.2. WPF
      1. 10.2.1. Object Data Binding
      2. 10.2.2. Collection Data Binding
      3. 10.2.3. Controls and Helper Objects
    3. 10.3. Web Forms
      1. 10.3.1. Controls and Helper Objects
    4. 10.4. Conclusion
  16. 11. Business and Validation Rules
    1. 11.1. Types of Rules
    2. 11.2. Csla.Validation Namespace
      1. 11.2.1. RuleHandler Delegate
      2. 11.2.2. RuleArgs Class
      3. 11.2.3. DecoratedRuleArgs Class
      4. 11.2.4. RuleMethod Class
      5. 11.2.5. RuleDescription Class
      6. 11.2.6. ValidationRules Class
      7. 11.2.7. BrokenRule Class
      8. 11.2.8. BrokenRulesCollection Class
      9. 11.2.9. ValidationException
    3. 11.3. Common Validation Rules
      1. 11.3.1. CommonRules
    4. 11.4. Conclusion
  17. 12. Authentication and Authorization
    1. 12.1. Authentication
      1. 12.1.1. Csla.ApplicationContext.User Property
      2. 12.1.2. Windows Authentication
      3. 12.1.3. Custom Authentication
    2. 12.2. Authorization
      1. 12.2.1. Type Level Authorization
      2. 12.2.2. Property and Method Level Authorization
    3. 12.3. Conclusion
  18. 13. N-Level Undo
    1. 13.1. Using Undo
    2. 13.2. Implementing Undo
      1. 13.2.1. ISupportUndo Interface
      2. 13.2.2. NotUndoableAttribute Class
      3. 13.2.3. UndoableBase Class
      4. 13.2.4. BusinessBase Class
      5. 13.2.5. BusinessListBase Class
    3. 13.3. Conclusion
  19. 14. LINQ to CSLA
    1. 14.1. Reducing Code with LINQ
    2. 14.2. Overview of LINQ to CSLA .NET
      1. 14.2.1. Binding to Results from LINQ to Objects
      2. 14.2.2. Indexed LINQ Queries
    3. 14.3. LINQ and Projection
      1. 14.3.1. Identity Projections and LinqBindingList<T>
      2. 14.3.2. Understanding LinqBindingList
    4. 14.4. Overview of Indexed Search Using CSLA .NET
      1. 14.4.1. Serialization and Indexing
      2. 14.4.2. Index Mode
    5. 14.5. The IQueryable Implementation for CSLA .NET
      1. 14.5.1. Understanding Expression Trees
      2. 14.5.2. Digging into IQueryProvider
      3. 14.5.3. LinqBindingList
    6. 14.6. Indexed LINQ and CSLA .NET
      1. 14.6.1. Managing the Index Set
      2. 14.6.2. Expression Evaluation
      3. 14.6.3. The Indexing Object Model
    7. 14.7. Conclusion
  20. 15. Persistence and the Data Portal
    1. 15.1. Data Portal Design
      1. 15.1.1. Separation of Business Logic and Data Access
      2. 15.1.2. Consistent Coding Model for Root and Child Objects
      3. 15.1.3. Channel Adapter and Message Router Patterns
      4. 15.1.4. Distributed Transaction Support
      5. 15.1.5. Context and Location Transparency
      6. 15.1.6. Authorizing Server Calls
      7. 15.1.7. Asynchronous Behaviors
      8. 15.1.8. Object Factories
    2. 15.2. Base Class Support
      1. 15.2.1. Factory Methods and Criteria
      2. 15.2.2. Save Methods
      3. 15.2.3. Updating Child Objects with the Field Manager
      4. 15.2.4. Updating Editable Collections
    3. 15.3. Reflection and Dynamic Method Invocation
      1. 15.3.1. The MethodCaller Class
      2. 15.3.2. The LateBoundObject Class
    4. 15.4. Channel Adapter
      1. 15.4.1. The RunLocal Attribute
      2. 15.4.2. The DataPortal Class
      3. 15.4.3. The DataPortal<T> Class
      4. 15.4.4. The IDataPortalServer Interface
      5. 15.4.5. The IDataPortalProxy Interface
      6. 15.4.6. The LocalProxy Class
      7. 15.4.7. The WcfProxy Class
      8. 15.4.8. The WcfPortal Class
    5. 15.5. Distributed Transaction Support
      1. 15.5.1. The Transactional Attribute
      2. 15.5.2. The Csla.Server.DataPortal Object
      3. 15.5.3. The ServicedDataPortal Class
      4. 15.5.4. The TransactionalDataPortal Class
    6. 15.6. Message Router
      1. 15.6.1. The DataPortalSelector Class
      2. 15.6.2. The SimpleDataPortal Class
      3. 15.6.3. The FactoryDataPortal Class
      4. 15.6.4. The FactoryLoader Property
      5. 15.6.5. The ChildDataPortal Class
    7. 15.7. Context and Location Transparency
      1. 15.7.1. The DataPortalContext Class
      2. 15.7.2. The DataPortalResult Class
      3. 15.7.3. Csla.Server.DataPortalException
    8. 15.8. Conclusion
  21. 16. Other Framework Features
    1. 16.1. Date Handling with SmartDate
      1. 16.1.1. Initializing the Struct
      2. 16.1.2. Supporting Empty Dates
      3. 16.1.3. Conversion Functions
      4. 16.1.4. Text Functions
      5. 16.1.5. Date Functions
      6. 16.1.6. Database Format
    2. 16.2. Data Access
      1. 16.2.1. Managing Database Connections and Contexts
      2. 16.2.2. SafeDataReader
      3. 16.2.3. DataMapper
    3. 16.3. Windows Workflow Foundation
      1. 16.3.1. Starting a Workflow from an Object
      2. 16.3.2. WorkflowManager Class
    4. 16.4. Conclusion
  22. 17. Business Object Implementation
    1. 17.1. ProjectTracker Objects
    2. 17.2. Setting Up the Project
    3. 17.3. Business Class Implementation
      1. 17.3.1. Project
      2. 17.3.2. ProjectResources
      3. 17.3.3. ProjectResource
      4. 17.3.4. Assignment
      5. 17.3.5. RoleList
      6. 17.3.6. Resource and Related Objects
      7. 17.3.7. ProjectList and ResourceList
      8. 17.3.8. Roles
      9. 17.3.9. Role
      10. 17.3.10. Implementing Exists Methods
    4. 17.4. Custom Authentication
      1. 17.4.1. PTPrincipal
      2. 17.4.2. PTIdentity
    5. 17.5. Conclusion
  23. 18. Example Data Access
    1. 18.1. Data Access Layer Design
      1. 18.1.1. Data Access Models
      2. 18.1.2. Balancing Design Issues
    2. 18.2. Data Access Objects
      1. 18.2.1. Using LINQ to SQL
      2. 18.2.2. The ProjectTracker.DalLinq Project
    3. 18.3. Business Class Implementation
      1. 18.3.1. Project
      2. 18.3.2. ProjectResources
      3. 18.3.3. ProjectResource
      4. 18.3.4. RoleList
      5. 18.3.5. ProjectList and ResourceList
      6. 18.3.6. Roles
      7. 18.3.7. Implementing Exists Methods
    4. 18.4. Conclusion
  24. 19. Windows Presentation Foundation UI
    1. 19.1. Custom Authentication in WPF
    2. 19.2. Interface Design
      1. 19.2.1. User Control Framework
      2. 19.2.2. Value Converters
      3. 19.2.3. Application Configuration
      4. 19.2.4. PTWpf Project Setup
      5. 19.2.5. The MainForm Window
      6. 19.2.6. The Login Window
      7. 19.2.7. The RolesEdit Form
      8. 19.2.8. The ResourceList Form
      9. 19.2.9. The ProjectList Form
      10. 19.2.10. The ProjectEdit Form
    3. 19.3. Conclusion
  25. 20. Web Forms UI
    1. 20.1. Web Development and Objects
    2. 20.2. State Management
      1. 20.2.1. State on the Web Server
      2. 20.2.2. Transferring State to or from the Client
      3. 20.2.3. State in a File or Database
    3. 20.3. Interface Design
      1. 20.3.1. Application Configuration
      2. 20.3.2. PTWeb Site Setup
      3. 20.3.3. Master Page
      4. 20.3.4. Login Page
    4. 20.4. Business Functionality
      1. 20.4.1. RolesEdit Form
      2. 20.4.2. ProjectList Form
      3. 20.4.3. ProjectEdit Form
    5. 20.5. Conclusion
  26. 21. WCF Service Interface
    1. 21.1. Choosing Between Client/Server and SOA
    2. 21.2. Overview of WCF Services
      1. 21.2.1. Elements of a WCF Service
      2. 21.2.2. Custom Authentication
    3. 21.3. Designing a WCF Service Interface
      1. 21.3.1. Service Design
      2. 21.3.2. Application Configuration
      3. 21.3.3. PTWcfService Site Setup
      4. 21.3.4. Service Contract and Implementation
    4. 21.4. Web Service Consumer Implementation
      1. 21.4.1. Generating a WCF Information Page
      2. 21.4.2. A Simple Smart Client
    5. 21.5. Conclusion