Enterprise Library 3.0: Whats New - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Enterprise Library 3.0: Whats New

Description:

Type Conversion (e.g. string can be converted to a DateTime) ... E.g String Length must not be between 5 and 10 characters. Composing Validation Rules ... – PowerPoint PPT presentation

Number of Views:232
Avg rating:3.0/5.0
Slides: 36
Provided by: TomHol1
Category:

less

Transcript and Presenter's Notes

Title: Enterprise Library 3.0: Whats New


1
Enterprise Library 3.0 Whats New?
2
The Story So Far
  • Application Blocks are reusable, extensible
    source-code components that provide guidance for
    common development challenges
  • Enterprise Library is a collection of general
    purpose application blocks
  • Caching, Configuration, Cryptography, Data
    Access, Exception Handling, Logging, Security
  • Emphasis on Consistency, Extensibility, Ease of
    Use and Integration
  • Originally designed for .NET Framework 1.1
    (January/June 2005 releases) and updated for .NET
    Framework 2.0 (January 2006 release)
  • Enterprise Library has become a standard for .NET
    development and is often used as a basis for
    custom frameworks

3
Goals of Enterprise Library 3.0
  • Address top feedback received for existing
    application blocks
  • Provide new application blocks to support
    additional development challenges
  • Support integration with relevant features of
    .NET Framework 3.0
  • Improve the experience around key development
    activities
  • Simplify the development of new application
    blocks and extensions
  • Retain compatibility with Enterprise Library 2.0

4
Enterprise Library 3.0 New Features At a Glance
  • New application blocks
  • Validation Application Block
  • Policy Injection Application Block
  • Improvements to existing application blocks
  • Data Access Application Block
  • Logging Application Block
  • .NET Framework 3.0 integration
  • Logging, Exception Handling and Validation
    Application Blocks
  • Configuration improvements
  • Visual Studio-integrated configuration tool
  • Environmental Overrides
  • Manageable Configuration Source
  • Automation
  • Application Block Software Factory
  • Strong Naming Guidance Package

5
Enterprise Library 3.0 Application Blocks
Core
6
New Application Blocks
7
Validation Application Block Goals
  • Specify your validation rules once
  • In configuration
  • Using attributes
  • Programmatically
  • Easily validate data from anywhere in your
    application
  • Programmatically
  • Integrated into Windows Forms, ASP.NET or WCF
  • Composable validation logic
  • Built-in library of common primitive validation
    rules
  • Combine validation rules on type members and
    using Boolean logic
  • Apply multiple validation rule sets to the same
    types

8
Supplied Validation Rules
  • Validation Application Block includes the
    following rules
  • Not Null (value must not be null)
  • Contains Characters (e.g. does not contain any of
    /\?)
  • Regular Expression (e.g. value is a valid e-mail
    address)
  • Range (e.g. must be from 10-20 or 1/1/1950 to
    12/31/1999)
  • Relative DateTime (e.g. birth date is more than
    18 years ago)
  • String Length (e.g. string is at least 8
    characters long)
  • Domain (e.g. must be one of John, Paul, George,
    Ringo)
  • Enum Conversion (e.g. string can be converted to
    a value in the Color enum type)
  • Type Conversion (e.g. string can be converted to
    a DateTime)
  • Property Comparison (e.g. MaxDate MinDate)
  • All validation rules can be negated
  • E.g String Length must not be between 5 and 10
    characters

9
Composing Validation Rules
  • You can build complex validation rule sets by
    combining multiple primitive rules
  • Combining rules with Boolean AND / OR logic
  • Assigning different validators to different
    members of a type
  • Specifying how nested objects or collections are
    to be validated
  • A single type may have multiple rule sets that
    can be used in different contexts
  • For example, Valid for displaying or Valid for
    persisting
  • For example, Valid Customer or Preferred Customer

10
Specifying Validation Rules using Attributes
  • Attributes allow you to specify validation rules
    directly within the type being validated
  • Validation logic cannot be changed without
    recompiling
  • You must own the source code of the type

StringLengthValidator(1, 50, Ruleset"RuleSetA",
MessageTemplate"Last Name must be 1-50
characters") public string LastName get
return lastName set lastName value
RegexValidator(_at_"\w(-.'\w)_at_\w(-.
\w)\.\w(-.\w)", MessageTemplate"Invalid
e-mail address", Ruleset"RuleSetA") publi
c string Email get return email
set email value ObjectValidator("Rul
eSetA", Ruleset"RuleSetA") public Address Addre
ss get return address set addr
ess value
11
Specifying Validation Rules using Configuration
  • Validation rules are stored in XML and can be
    edited with the Enterprise Library configuration
    tool
  • Validation logic can be changed without
    recompiling
  • You dont need to own the source code of the
    type

12
Validating Data Programmatically
  • Regardless of how you specify rules, objects are
    validated in the same way
  • If validation fails, you get a collection of
    ValidationResult objects
  • Each result includes a message, tag, references
    to the object and property being validated, and a
    reference to the original validator.

Validator validator
ValidationFactory.CreateValidator("Rules
et") ValidationResults results validator.Valid
ate(customer)if (!results.IsValid)
foreach (ValidationResult result in results
) Console.WriteLine("Message0,
Key1, "Tag2", result.Message,
result.Key.ToString(),
result.Tag null ? "null" "\""
result.Tag.ToString() "\"")
13
Integrating with WinForms, ASP.NET or WCF
  • Supplied Integration Adapters make it easier to
    validate data in UI layers and service
    boundaries
  • Windows Forms and ASP.NET integration allow you
    to associate a control with the validation rules
    for a particular type and member
  • Validation failures are displayed alongside the
    control being validated
  • Includes events for converting user input to the
    correct type for validation
  • WCF integration implemented as a WCF Behavior
    that validates data at the service interface
    layer
  • Rules are defined within data contract types or
    using attributes on the service contract

14
Policy Injection Application Block - Goals
  • Separate cross-cutting concerns from business
    logic
  • Use interception and injection to apply policies
    at runtime
  • Allow policies to be defined using configuration
    or attributes
  • Include matching rules for common scenarios
  • Applies policies at fine-grained level (searching
    for specific members or attributes) or
    coarse-grained (all types in a namespace or
    assembly)
  • Include handlers that integrate with Enterprise
    Library to implement common cross-cutting
    concerns
  • Validation, Logging, Authorization, Exception
    Handling, Caching, Performance Counters
  • Allow users to use custom interception mechanisms

15
Policy Injection Application Block Basics
  • Policy Injection Application Block provides a
    factory for creating or wrapping policy-enabled
    objects
  • If policies are defined in attributes or
    configuration, a proxy is returned in lieu of the
    real object
  • When calling policy-enabled members, a handler
    pipeline is executed before and after the real
    member is called
  • Each handler can read and manipulate the data
    going in and out of the call

16
Defining Policies
  • Policies defined in configuration consist of a
    set of matching rules and the definition of the
    handler pipeline
  • Matching rules are predicates that specify which
    members the policy should apply to
  • Handlers can also be applied directly to types
    and members using attributes

ValidationCallHandler public void Deposit( Ra
ngeValidator(typeof(Decimal),
"0.0", RangeBoundaryType.Exclusive,
"0.0", RangeBoundaryType.Ignore)
decimal depositAmount) balance depositA
mount
17
Supplied Handlers
  • Validation Handler
  • Validates parameters to a method using validation
    rules defined for the types or as attributes
    attached to the parameters. If validation fails,
    an exception is returned and the method is not
    called.
  • Logging Handler
  • Logs before and/or after the method is called,
    optionally including the call stack, parameter
    values, return values, exceptions and call
    execution time
  • Authorization Handler
  • Uses the specified Authorization provider to
    check if the current user (thread principal) is
    authorized to perform the operation. If
    authorization fails, an exception is returned and
    the method is not called.

18
Supplied Handlers (continued)
  • Exception Handling Handler
  • If the method throws an exception, the exception
    is processed using the Exception Handling
    Application Block and the returned exception is
    sent back to the called
  • Caching Handler
  • Checks if the method has recently been called,
    and if so, returns the cached return value
    instead of calling the method. If not, the method
    is called and the return value is cached for
    future use
  • Performance Counter Handler
  • Increments a number of performance counters to
    measure the number of times the method is called,
    the rate at which it is called, the average call
    duration and the number of exceptions thrown

19
Improvements to Existing Application Blocks
20
Data Access Application Block
  • SQL Server Compact Edition provider
  • New SqlCeDatabase class that integrates with the
    SQL CE managed provider
  • TransactionScope integration
  • Prevents escalation to DTC when multiple updates
    are made to the same database within a
    TransactionScope context
  • Batch updates
  • UpdateDataset now supports an updateBatch size
    parameter

21
Logging Application Block
  • Rolling Flat File Trace Listener
  • Automatically creates a new file based on file
    size or date/time
  • Improved Text Formatter
  • Reflected Property Token, to retrieve data out of
    custom LogEntry types
  • Display timestamps in local or UTC time

22
.NET Framework 3.0 Integration
23
WCF Integration
  • Exception Handling Application Block
  • ExceptionShieldingBehavior can be specified on a
    service contract
  • Calls the Exception Handling Application Block to
    shield exceptions from the caller
  • Logging Application Block
  • EntLibLoggingProxyTraceListener can be configured
    to enable the Logging Application Block to
    process WCF trace events
  • XmlTraceListener can be used with the block to
    output events in the format consumable by WCF
    diagnostics tools
  • Validation Application Block
  • ValidationBehavior can be specified on a service
    contract to enable validation of data contracts

24
Configuration Improvements
25
Visual Studio-integrated Configuration Tool
  • Edit configuration from within the IDE
  • Launched from .config files in the Solution
    Explorer
  • Can be configured to point to different sets of
    assemblies

26
Environmental Overrides
  • Simplifies management of configuration files
    across multiple environments
  • Separates master configuration files from
    environment-specific delta files
  • Specify which settings to override on a
    node-by-node basis
  • Merge configuration files using the configuration
    tool or a command-line tool

27
Manageable Configuration Source
  • Configuration Source designed to make it easier
    to build more manageable applications
  • Based on the FileConfigurationSource, allowing
    applications to read configuration from any
    .config file, plus
  • Administrators may publish changes to
    applications configuration using Group Policy
  • The resulting merged configuration is published
    using WMI to enable querying through operations
    tools such as Microsoft Operations Manager
  • No code changes required by developers to support
    this!

28
Automation
29
Application Block Software Factory
  • Enterprise Library 3.0 includes a new software
    factory for building your own application blocks
    and extensions to existing application blocks
  • Features include
  • Code generation in either C or Visual Basic
    .NET
  • Solution templates for Application Blocks and
    Provider Libraries
  • Recipes to create custom providers for Enterprise
    Library application blocks
  • Including Validators, Trace Listeners, Exception
    Handlers and Authorization Providers
  • Strongly-typed or property bag-based
    configuration
  • Recipes to create new factories, provider bases
    and providers for your own blocks
  • Recipes to create design-time configuration code
    from runtime configuration classes

30
Application Block Software Factory
31
Strong Naming Guidance Package
  • Strong-naming Enterprise Library is recommended,
    but complex
  • 90 projects, including design-time and tests
  • Use of InternalsVisibleTo attribute for
    testing
  • Strong Naming Guidance Package automates
  • Generating strong-name key pairs
  • Specifying that projects should be strong-named
  • Updating InternalsVisibleTo to include public
    key
  • Can be run on Enterprise Library or any other
    solution
  • Enterprise Library 3.0 also ships with pre-built,
    strong-named assemblies which you can use if you
    dont want to modify the code.

32
finally
33
Migration from previous versions
  • This release is 100 API compatible with the
    previous January 2006 release of Enterprise
    Library
  • Configuration formats for existing blocks are
    unchanged, but assembly version numbers and
    possibly public key tokens will need to be
    changed
  • Multiple versions of Enterprise Library can be
    installed on the same machine, but cannot be used
    together in the same application
  • Enterprise Library 3.0 can be used with either
    .NET Framework 2.0 or .NET Framework 3.0
    installed
  • WCF-specific functionality requires .NET
    Framework 3.0

34
Resources
  • Download Enterprise Library and related resources
    from
  • http//msdn.microsoft.com/practices
  • Join the Enterprise Library Community at
  • http//codeplex.com/entlib
  • Read blogs from the Enterprise Library team at
  • http//msdn.microsoft.com/practices/Comm/EntLibBlo
    gs/

35
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com