Title: Enterprise Library Building an Application Block
1Enterprise LibraryBuilding an Application Block
- Ed Jezierski
- Solution ArchitectScott Densmore
- Software Engineer
- Ron JacobsProduct Manager
2Agenda
- Architectural Guidance from patterns practices
- Application Blocks
- Enterprise Library Vision
- Enterprise Library Application Blocks
- Configuration
- Cryptography
- Data Access
- Security
- Demonstration
- Questions
-
- Logging Instrumentation
- Exception Handling
- Caching
3patterns practicesArchitecture Guidance for
the Enterprise
Proven Based on field experience Authoritative
Offer the best advice available
Accurate Technically validated and tested
Actionable Provide the steps to success
Relevant Address real-world problems based on
customer scenarios
Available online http//www.microsoft.com/practi
ces Books available http//www.amazon.com/pract
ices
Application Blocks
Patterns
Reference Architectures
Atomic solutions to recurring problems
Sub-system-level guidance for common services
System-level guidance for common customer
scenarios
D
A
D
I
D
A
D
I
A
A
D
D
I
I
Guides Guidance for broad horizontal topics such
as security, performance, deployment and
operations
4Sound familiar?
- Having similar code pasted throughout your
applications - Writing components to enable and encourage
reusethen rewriting them to meet specific
application needs - Having components that should work well together,
but - Each component mandating inconsistent
requirements on the consuming application - Longing for a way to future-proof your software
library
5Enterprise Library Philosophy
- Consistency
- Apply consistent design patterns and
implementation approaches - Extensibility
- Include extensibility points allowing developers
to customize the behavior of the blocks by
plugging in their own code or customize by
directly modifying source code - Ease of Use
- Leverage a graphical configuration tool
- Provide a simpler installation procedure
- Include clear and complete documentation and
samples - Integration
- Application blocks should be designed to work
well together and tested to make sure that they
do. But it should also be possible to use the
application blocks individually
6Enterprise Library v1
Caching
Exceptions
Legend
Security
Data Access
Logging
Dependency
Plug-in
Crypto
Configuration
Config Tool
7Enterprise Library Vision
pp blocks
Partner blocks
Customer blocks
Block Specification
Community blocks
8Elements of an Application Block
- Core functionality
- Pluggable providers
- Factories
- Configuration
- Unit tests
- Quick Starts
- Guidance and reference documentation
9Core Functionality
- Central to its operation
- May be influenced via configuration settings, but
basic behavior cannot be changed without source
code modifications - Often internal, but when exposed to an
application, it is typically provided via a
single class, interface, or facade - Its OK to have core functionality not
everything must be replaceable or even
configurable!
10Core Functionality Examples
- Caching
- Cache implementation (hashtable) not exposed
- Scavenging algorithm not exposed
- Cache manager exposed as a class
- Exception Handling
- Exception policy exposed as a class with single
public static method (HandleException) - Logging and Instrumentation
- Log filters not exposed
11Pluggable Providers
- Associated with an application block capability,
defined by a provider type. - Caching Backingstore
- Data Access Database
- Exception Handling Exception Handler
- A provider is a specific implementation of a
provider type. Each application block includes
at least one provider implementation of each
provider type - Caching Database and isolated storage
backingstores - Data Access SQL, DB2 and Oracle databases
12Pluggable Providers
- Decouples the application block's core
functionality from specific implementation,
achieving the following goals - Variability
- Extensibility
- Encapsulation
- Portability across environments
- Minimized coupling between application blocks
- Specified in configuration data with type
information and a name
13Provider Implementations and Configuration
- Providers typically allow for configuration of
each specific implementation - Example the replace exception handler has a
configuration setting for the new exception type - The abstract base class ConfigurationProvider
defines the contract for initializing a provider
with configuration information - Decision point create a new provider
implementation, or configuration property of an
existing implementation
14Provider Factories
- Uses Plugin Fowler pattern to create providers
- Neither applications nor application blocks
require information about specific implementation
of provider - Specific implementation to be constructed
determined by configuration settings - Abstract base class (ProviderFactory) in
Configuration Application Block contains code to
instantiate configurable providers
15Provider Factories
- Static method to create provider objects
- Allow for creation of default provider (as
specified by configuration settings) - Allow for creation of named provider
' Create the default database instance Dim db As
Database DatabaseFactory.CreateDatabase() '
Use a named instance to map to configuration Dim
salesDb As Database DatabaseFactory.CreateDataba
se("Sales")
- Allows you to reconfigure and execute the
application without recompiling
16Configuration
- Allows you to easily adapt the application block
to meet the needs of different enterprise
scenarios - Creation and editing of configuration settings is
done with the Configuration Console - Configuration settings may be defined for an
application blocks core functionality and for
each provider type
17Configuration
- Using configuration settings to adapt an
application block to a particular situation has
two advantages - Characteristics of an application block can be
configured by different people at different times
in the application life cycle - The application block can be incrementally
adapted for increasingly complex situations
18Configuration
- Runtime configuration
- Object graphs that represent configuration
settings - Configuration Application Block reads settings
from storage and returns objects to application
block - XML File Storage Provider and Transformer require
that objects be serializable - Design-time configuration
- Allow settings to be displayed, changed and
validated using the Configuration Console
19Design-time and Runtime Relationship
20Design-Time Configuration
- Based upon System.ComponentModel
- Configuration node is of type Component
- The Configuration Console provides the Site
- Services are available through Config Block
- Configuration node classes for each node in the
configuration tree - Each node determines the properties to be
displayed when node is selected - Validation rules can be included for any property
21Configuration Nodes
- Determine how the Configuration Console displays
the hierarchy of configuration nodes - Determine which/how properties are exposed in the
graphical interface - Enable the Configuration Console to validate that
the values a user assigns to an application
block's properties are appropriate - Can contain references that point from one
application block to another (such as an
authorization database that points to a database
instance) - Contain references to the runtime data classes
22Configuration Design Manager
- Implements IConfigurationDesignManager interface
- Allows an application block to be added to an
applications configuration hierarchy - Creates menu items and commands that are invoked
as user interacts with the Configuration Console
to configure the application block - Responsible for loading and saving configuration
data - Assembly must be located in same directory as
Configuration Console executable
23Configuration Application Block Support
- The Configuration Application Block provides much
of the plumbing for runtime and design-time
configuration
24Configuration Console
Properties
Configuration Nodes
Validation Error
25Unit Tests
- Verify functionality of application block
- Verify that modifications to application block
have not cause regression - Enterprise Library developed using Test Driven
Development (TDD)
26Quick Starts
- Demonstrate common scenarios of application block
usage - Display output indicating what happened under
the covers - Detect common errors (e.g. user didnt perform
required setup) and display useful information - Goal Open solution, hit F5, and see it run
27Documentation
- Integrated into Visual Studio
- Guidance
- Introduction and goals
- Developing applications using the application
block - Design of the application block
- Extending the application block
- Deploying the application block
- Quick start walkthroughs
- Reference API
- Public and protected
- Summaries, parameters and return values
28A Simple Example Hello World Application Block
- Client application can use the application block
to return a greeting for a specified user - The implementation of how the greetings are
returned is encapsulated in a greeting provider - An application can use multiple greeting
providers, each identified by a unique name - The Configuration Console is used to select the
default greeting provider, used when the client
does not specify a name for the provider - Each greeting provider has a default message, set
by the Configuration Console
29Hello World Application Block Core Functionality
- Minimal to keep things simple
- Includes the interface definition
IGreetingProvider, which all greeting providers
must implement - Includes the class HelloWorldConfigurationView
- Derives from ConfigurationView
- Exposes the runtime configuration settings
required by the application blocks providers - Passed to the Initialize method of each provider
when it is created
30Hello World Application Block Configuration View
- Initialized with ConfigurationContext
public virtual GreetingProviderData
GetGreetingProviderData(string name) //
HelloWorldSettings is our runtime configuration
object HelloWorldSettings settings
GetHelloWorldSettings() return
settings.GreetingProvidersname
- Returns configuration data required by
application block
public virtual string GetDefaultGreetingProviderDa
taName() HelloWorldSettings settings
GetHelloWorldSettings() return
settings.DefaultGreeter
31Hello World Application Block Providers
- Text greeting provider
- Returns plain text greeting for specified user
- Greeting for a user is determined by
configuration settings - Includes configuration design-time support to
allow greetings to be entered and validated - Custom greeting provider
- Allows user to select the FQTN of a class that
implements IGreetingProvider - Configuration is provided via a property bag of
name-value pairs (no design-time support)
32Hello World Application Block Runtime
Configuration
- Requirements
- Block allows multiple greeting providers
- Each greeting provider has a name
- Text greeting provider can have multiple
greetings - A greeting is name and a message
- Configuration Information is represented as
serializable classes
33Runtime Configuration Data
- lt?xml version"1.0" encoding"utf-8"?gt
- lthelloWorldConfigurationgt
- ltxmlSerializerSection
- type"Microsoft.Practices.Samples.HelloWorld.C
onfiguration.HelloWorldSettings, - Microsoft.Practices.Samples.HelloWorld,
Version1.0.0.0, Cultureneutral, - PublicKeyTokennull"gt
- lthelloWorldSettings xmlnsxsd"http//www.w3.o
rg/2001/XMLSchema" - xmlnsxsi"http//www.w3.org/2001/XMLSchema-
instance" defaultGreeter"Casual Greetings" - xmlns"http//www.microsoft.com/practices/sa
mples/08-31-2004/helloworld"gt - ltgreetingProvidersgt
- ltgreetingProvider xsitype"TextGreetingPr
oviderData" name"Casual Greetings"
defaultGreeting"Hello World!"gt - ltgreetingsgt
- ltgreeting name"John" message"Hi
John." /gt - ltgreeting name"Maria" message"Ciao
Maria!" /gt - lt/greetingsgt
- lt/greetingProvidergt
- lt/greetingProvidersgt
- lt/helloWorldSettingsgt
- lt/xmlSerializerSectiongt
34Runtime Configuration Classes
- HelloWorldSettings
- Includes configuration section name, collection
of providers, and default greeting provider - GreetingProviderData (base class),
TextGreetingProviderData, CustomGreetingProviderDa
ta - Common settings and settings specific to
providers - TextGreetingDataCollection
- Collection of text greetings
- TextGreetingData
- Name and message
35Configuration Application Block Runtime Support
36Runtime Configuration Class Serialization
- Root object serialization
XmlRoot("helloWorldSettings", NamespaceHelloWorl
dSettings.ConfigurationNamespace) public class
HelloWorldSettings
XmlArray("greetings", NamespaceHelloWorldSetting
s.ConfigurationNamespace) XmlArrayItem(Typetype
of(TextGreetingData), NamespaceHelloWorldSettings
.ConfigurationNamespace) public
TextGreetingDataCollection Greetings get
return this.greetings
37Runtime Configuration Class Serialization
- XML include types for base classes
XmlType("greetingProvider", NamespaceHelloWorldS
ettings.ConfigurationNamespace) XmlInclude(typeo
f(CustomGreetingProviderData)) XmlInclude(typeof
(TextGreetingProviderData)) public abstract
class GreetingProviderData ProviderData
38Hello World Design-Time Configuration
- Required to allow the application block to be
configured with the Configuration Console
39Hello World Client
// Create default greeting provider (determined
by configuration) IGreetingProvider
defaultProvider GreetingFactory.GetGreetingProvi
der() // Create named instance IGreetingProvider
formalProvider GreetingFactory.GetGreetingProvi
der("Formal Greetings")
string greeting defaultProvider.SayGreeting(Joh
n)
40Additional Resources
- Improving Web Application Security
- http//msdn.microsoft.com/library/default.asp?url
/library/en-us/dnnetsec/html/ThreatCounter.asp - Improving .NET Application Performance and
Scalability - http//msdn.microsoft.com/library/default.asp?url
/library/en-us/dnpag/html/scalenet.asp - Application Architecture for .NET
- http//msdn.microsoft.com/library/default.asp?url
/library/en-us/dnbda/html/distapp.asp - PatternShare.org
- Enterprise Library Communityhttp//go.microsoft.c
om/fwlink/?linkid39209clcid0x09 - www.ronjacobs.com
- Slides
- Tech Tips
- Podcasts
41Announcing Enterprise Library 1.0
- http//www.microsoft.com/practices
Download it Today!
42Patterns and Practices Live!
- Slides, Hands On Labs, On Demand Webcasts
- Upcoming Live Webcasts
- 3/28 Building your own block
- 3/31 Enterprise Library Applied
- 4/12 Global Bank Baseline Architecture
- 4/14 Updater Application Block v2
http//www.pnplive.com
43http//www.microsoft.com/practices