Blocks can be used with or without configuration files
Factories build up block objects using data from the configuration files
Objects can be “newed up” directly with primitive data types
Configuration stored in standard XML .config files by default
Alternative “Configuration Sources” can be used
Ships with System, File, Manageable and SQL configuration sources
Configuration Design & Tooling
Configuration tools eliminate the need to edit the blocks’ XML configuration files
Quickly add default configuration for a block
Strongly typed properties and providers
Validate configuration before you save
Encrypt configuration files
Specify settings that are unique to different environments (development, test, production, etc.)
Visual Studio-integrated editor and standalone console are provided
Configuration Design-time subsystem can be used in your own applications and blocks to provide a similar experience for users of your own blocks and extensions
Instrumentation
All Enterprise Library blocks include instrumentation to assist in development, testing and operations
Event Log events
Performance Counters
WMI events
All instrumentation is disabled by default, but each type can be individually enabled using the configuration tool
Installing instrumentation requires admin rights, and can be done using installutil.exe
Instrumentation code contained in Common assembly can be reused in your apps
Object Builder
Shared component used in several p&p deliverables
Responsible for building objects inside the application blocks
Invoking the necessary custom factory using data from configuration
Configuring instrumentation for the blocks
Can be leveraged from your own apps, but understanding ObjectBuilder is not required to use Enterprise Library
More information and downloads at http://codeplex.com/objectbuilder
You need to log business and operations data to various destinations, which are externally configurable
You need to provide tracing to support production debugging
You need to provide auditing for increased security
You need to be able to specify which messages go where, and how they are formatted
You need to be able to log messages to a wide variety of destinations
Logging Application Block
Provides a simple model for logging events
Strongly typed, extensible log schema
Built on top of System.Diagnostics
Configuration driven – you decide what messages are logged where at runtime.
Use any .NET TraceListener, including supplied formatter-aware listeners:
EventLog, Database, Flat File, Rolling Flat File, MSMQ, E-mail, WMI, XML or create your own
Tracer class lets you time key activities and correlate any enclosed events
Logging - Examples
Dim log As LogEntry = New LogEntry
log.Message = “Your message here…”
log.Priority = 1
log.EventId = 100
log.Categories.Add("UI")
log.Categories.Add("Debug")
Logger.Write(log)
// Or if you prefer one line... Customer cust = GetCustomer(123); // Log the customer – will call cust.ToString() for the log entry Logger.Write(cust, category, priority);
You need a simple and efficient way of working with commonly used databases
Transparency when developing for multiple types of databases
SQL Server, SQL Server CE, Oracle, OLE-DB, ODBC, …
A way to place an indirection between a logical database instance and a physical database instance
An easy way to adjust and validate the database configuration settings
Data Access Application Block
Provides simplified access to the most often used features of ADO.NET with applied best practices
Improve Consistency
Write code that works against multiple database brands (caveats apply!)
Integrate with System.Transactions functionality
Improve ease of use
Easily call a stored procedure with one line of code
Let the block manage the lifetime of database connections
Work with database connection strings stored in configuration or specified in code
Data Access - Examples Public Function GetProductsInCategory(ByVal Category As Integer) As DataSet ' Create the Database object, using the database instance with the ' specified logical name. This is mapped to a connection string in ' the configuration file Dim db As Database = DatabaseFactory.CreateDatabase("Sales") ' Invoke the stored procedure with one line of code! return db.ExecuteDataSet("GetProductsByCategory", Category) ' Note: connection was closed by ExecuteDataSet method call End Function public Dataset GetProductsInCategory(string connectionString, int category) { // Create the Database object, using the specified connection string SqlDatabase db = new SqlDatabase(connectionString); // Invoke the stored procedure with one line of code! return db.ExecuteDataSet("GetProductsByCategory", category); // Note: connection was closed by ExecuteDataSet method call }
You are creating a smart client application that uses locally cached reference data to create requests and support offline operations
You are building an application that requires cache data to be durable across application restarts
Note: ASP.NET cache (System.Web.Caching) can be used across multiple application types and is generally a better choice for applications that don’t require the cache to be persisted
Caching Application Block
Provides a flexible and extensible caching mechanism that can be used at all layers of an application
Supports backing stores that persist cache data into a database or isolated storage, so the data can survive app restarts
Thread-safe
Ensures that the states of the in-memory cache and the backing store remain synchronized.
You need to encrypt sensitive data using a symmetric key before storing in the database and decrypt when reading
You need to encrypt information (without using keys) for use on a single machine
You need to create a hash of a password to store in a database and be able to compare that hash with a user supplied hash to see if you have a match without storing the user password
Cryptography Application Block
Improves Security
Provides a simplified approach to implementing common cryptography scenarios
Improves Ease Of Use
Provides operations on both strings and byte streams
You need to cache authentication or authorization data for the duration of a logon session
Note: The original release of the Enterprise Library Security Application Block also supported Authentication, Profile and Roles. This is now supported by the .NET Membership and Profile class, so this functionality has been removed from the block.
Security Application Block + ASP.NET
Encapsulate common application security tasks
Present a standard, provider model for common security tasks
Minimize the need for custom security-related code
Incorporate best practices for application security
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
Policy Injection Example public class BankAccount : MarshalByRefObject { // Constructors and fields omitted [ValidationCallHandler] public void Deposit([RangeValidator(typeof(Decimal), "0.0", RangeBoundaryType.Exclusive, "0.0", RangeBoundaryType.Ignore)] decimal depositAmount) { balance += depositAmount; } } BankAccount account = PolicyInjection.Create<BankAccount>(customerId); account.Deposit(1234.56M); Write classes that extend MBRO or implement an interface Apply Handlers using attributes if desired Apply Policies using configuration if desired Create objects using PolicyInjection class Call your methods the usual way
Automation
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
Application Block Software Factory
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 don’t want to modify the code.
Resources
Download Enterprise Library and related resources from:
0 comments
Post a comment