1 / 112

Welcome to the Enterprise Library Overview

Welcome to the Enterprise Library Overview. 21 st April 2005. Sound familiar?. Writing a component to make it simpler to call stored procedures Building a component that allows you to log errors to different sources

schram
Download Presentation

Welcome to the Enterprise Library Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome to the Enterprise Library Overview 21st April 2005

  2. Sound familiar? • Writing a component to make it simpler to call stored procedures • Building a component that allows you to log errors to different sources • Building framework / infrastructure components to generally simplify app development • Searching on the internet thinking • Most applications need something like this • People must have written hundreds of things like this • I wish I could find a solution for this that I could reuse • …wishing Microsoft had done some of this for you?

  3. Application Block History • Application blocks have been around for a couple of years • The block program evolved over time with many different teams • Blocks range from very simple helpers like the original data access block to powerful frameworks like UIP • It’s a good start but you can always do better...and you have been telling us what you want

  4. Application Block Feedback • Make blocks consistent • Make blocks work well together • Minimize dependencies • On other blocks • On infrastructure • Make it easier to configure blocks • Make evaluation and understanding of blocks easier • Make using blocks easier

  5. Enterprise 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

  6. Enterprise Library v1 Caching Exceptions Legend Security Data Access Logging Dependency Plug-in Crypto Configuration Config Tool

  7. Customer Y library Partner X library p&p Enterprise Library Customer Z library Enterprise Library Vision p&p blocks Partner blocks Customer blocks Block Specification Community blocks

  8. Enterprise Library is… A library of application blocks which solve common challenges A set of helper classes which work in any architectural style Architectural guidance embodied in code which ships with full source allowing you to modify and extend Available as a free download Enterprise Library is not… A part of the .NET Framework An application framework that imposes an architectural style A Microsoft product with support, compatibility and localization For sale Enterprise Library

  9. Enterprise Library v1 Caching Exceptions Legend Security Data Access Logging Dependency Plug-in Crypto Configuration Config Tool

  10. Sound familiar? • Debates about where to store configuration information • Custom in-house configuration components for reading configuration settings, each with different usage models and behaviors • Development of separate tools to allow you to create and modify configuration data in storage • Inexact understanding of how changes in the underlying configuration store will be applied in running application

  11. Configuration Scenarios • Application needs to read and/or write complex configuration data at runtime • Application which must store sensitive data (password) in configuration • Application or block with design time support in the form of property pages, wizards and validation to assist developers in getting configuration right • Administrator deploying an application needs to change configuration and you want to provide a better experience than using notepad to edit XML configuration files

  12. Configuration Application Block (Runtime) Improves integration Supports pluggable storage providers and transformations Improves ease of use Read & Write Model Supports object graphs Notifications when config store changes Improves Security Supports Encryption Configuration Tool (Design-time) Uses Configuration Application Block Improves ease of use Wizards Property Sheets Validation Improves Security Supports Encryption Masking Configuration Application Block • Provides a general purpose configuration runtime which allows applications to easily read and write configuration data from configurable storage locations

  13. What You Must Know

  14. Defining Configuration Data • You create a class which defines your configuration data • Must be serializeable (XmlSerializer) • Can be arbitrarily complex Public Class EditorFontData Private fontName As String Private fontSize As Double Private fontStyle As Integer End Class

  15. Configuration Console • The Configuration Console reads and writes the configuration metadata • Sections can be easily added and deleted • Properties are displayed for easy editing • Validation ensures properties have appropriate values

  16. Declaring a Configuration Section • The XML File Storage Provider has a property for the path and filename of the XML file that contains the configuration information • The path is relative to the location of the app.config file

  17. Reading Configuration Data • Single line of code to read configuration data • The transformer and/or storage provider are responsible for returning the expected type • XML Serializer Transformer deserializes XmlNodes into the object types Read a string Dim conString As String conString = DirectCast( ConfigurationManager.GetConfiguration("connectionstring", String ) // Read an object with multiple properties Dim configData As EditorFontData = _ DirectCast( ConfigurationManager.GetConfiguration("EditorSettings"), _ EditorFontData)

  18. Writing Configuration Information • The application block provides an API to allow you to write configuration section information • Entire section is written (no merge) • The meta-configuration file must contain a configuration section definition for the section to be written • Example: writing a string value string servername = "MyServer"; ConfigurationManager.WriteConfiguration("SalesData", servername);

  19. Writing Config Example Public Class EditorFontData Private fontName As String Private fontSize As Double Private fontStyle As Integer End Class Dim configData As EditorFontData = New EditorFontData configData.Name = fontDialog.Font.Name configData.Size = fontDialog.Font.Size configData.Style = Convert.ToInt32(fontDialog.Font.Style) ConfigurationManager.WriteConfiguration("EditorSettings", configData)

  20. Demo Reading / Writing Configuration Data Shortcut

  21. Enterprise Library v1 Caching Exceptions Legend Security Data Access Logging Dependency Plug-in Crypto Configuration Config Tool

  22. Sound familiar? • Writing (cutting and pasting) the same data access code throughout your data access layer • Matching stored procedure parameter definitions with the calling application code • Wondering if your code is properly closing connections • Writing a component to make it simpler to call stored procedures • Wrestling with where/how to store connection string information

  23. Data Access Needs • A simple and efficient way of working with commonly used databases • Transparency when developing for multiple types of databases • 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

  24. Data Access Application Block • Provides 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!) • Improve Security • Leverages the crypto block and configuration system to securely store connection strings • Improve ease of use • Easily call a stored procedure with one line of code

  25. What You Must Know ...in 3 easy steps

  26. Step 1: Define your configuration • You will need an app.config (or web.config) file for your application • Use the Enterprise Library Configuration tool to create the configuration for the data access application block • Use a post-build step to copy config files to the runtime directory • See http://www.ronjacobs.com/TipPostBuild.htm

  27. Step 2: Create an Instance of Database • Previous DAAB was accessed with static methods • Enterprise Library Data Access Application Block uses the Plugin [Fowler] pattern to create providers. • Allows us to support SQL Server, Oracle and IBM DB2 • ' Create the default database instance • Dim db As Database = DatabaseFactory.CreateDatabase() • ' Use a named instance to map to configuration • Dim salesDb As Database = DatabaseFactory.CreateDatabase("Sales")

  28. Invoke SQL Dynamic SQL Stored Procedure Transaction Support Select Return type Data Set Data Reader Scalar Connections and Connection string managed automatically Step 3: Executing SQL Commands // Invoke a SQL Command productDataSet = db.ExecuteDataSet(CommandType.Text, "SELECT ProductID, ProductName FROM Products");

  29. Stored Procedures • Create a Database Object Dim db As Database = DatabaseFactory.CreateDatabase(“Sales”) • Option 1: Pass the stored procedure name to the method Dim ds As DataSet = db.ExecuteDataSet("GetAllProducts") • Option 2: Create a command wrapper object Dim dbc As DBCommandWrapper = _ db.GetStoredProcCommandWrapper("GetAllProducts") Dim ds As DataSet = db.ExecuteDataSet(dbc)

  30. Stored Procedures with Input Parameters • Input-only parameters Dim ds As DataSet = db.ExecuteDataSet("GetProductsByCategory“, 12) • Input-only parameters with command wrapper Dim dbc As DBCommandWrapper = _ db.GetStoredProcCommandWrapper("GetProductsByCategory") dbCommandWrapper.AddInParameter("@CategoryID", DbType.Int32, 12) Dim ds As DataSet = db.ExecuteDataSet(dbc)

  31. Demo Data Access Block Shortcut

  32. Enterprise Library v1 Caching Exceptions Legend Security Data Access Logging Dependency Plug-in Crypto Configuration Config Tool

  33. Sound familiar? • Users are complaining about application performance • You have already spent the next year’s IT budget scaling out your database servers to handle the amount of requests for data • Your application cannot perform, or is severely degraded, without a live connection to the backend data source

  34. Why Cache? • Performance • Storing relevant data as close as possible to the data consumer avoids repetitive data creation, processing, and transportation • Scalability • Avoid wasting resources processing the same data, business functionality, and user interface fragments required by multiple users and processes • Reduce database requests, allowing more users to be served • Availability • Storing that data in another place, your application may be able to survive system failures such as network latency, Web service problems, or hardware failures

  35. Caching Scenarios • You are creating a smart client application that uses locally cached reference data to create requests and support offline operations • You are creating a Windows Service or Console application which needs a cache to improve performance

  36. 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 • Easy to use • Easy to configure, using the Enterprise Library Configuration Tool • Thread-safe • Ensures that the states of the in-memory cache and the backing store remain synchronized.

  37. Creating Configuration • Add the Caching Application Block to your application configuration • Create a cache manager for each set of data to be cached • Designate one as the default cache manager

  38. Cache Storage Guidance • Memory resident cache. Memory-based caching is usually used when: • An application is frequently using the same data • An application often needs to reacquire the data • Disk resident cache. Disk based caching is useful when: • You are handling large amounts of data • Data in the application services (for example, a database) may not always be available for reacquisition (for example, in offline scenarios) • Cached data lifetime must survive process recycles and computer reboots Caching Architecture Guide for .NET Framework Applications

  39. Caching Application Block Storage • Cache always exists in memory • Cache always has a backing store • Null backing store (in-memory only, not persistent) • Persistent storage • Persistent backing stores • Useful when cached data lifetime must survive process recycles and computer reboots • Isolated storage, Data Access Application Block • Contents always match in-memory cache • In-memory cache is loaded from backing store during cache initialization

  40. Creating the Cache in Code • Create the default cache manager CacheManager myCache = CacheManager.GetCacheManager(); • Create the cache manager named “Products” CacheManager productsCache = CacheManager.GetCacheManager(“Products”);

  41. Add Item to the Cache • Add an item to the cache with defaults productsCache.Add(“ProductID123”, productObject); • Defaults • Scavenging priority: Normal • No expiration • Notes • Adding a second item with the same key as an existing item replaces the existing item • When configured to use a persistent backing store, objects added to the cache must be serializable

  42. Get Item from the Cache • Cast returned object to correct type • Check for null (item not found in cache) public Product ReadProductByID(string productID) { Product product = (Product)cache.GetData(productID); if (product == null) { // Item not in cache } }

  43. Expiration Policies • Time-based expirations • Invalidate data based on either relative or absolute time periods • For use when volatile cache items—such as those that have regular data refreshes or those that are valid for only a set amount of time—are stored in a cache. • Notification-based expirations • Validity of a cached item based on the properties of an application resource, such as a file, a folder, or any other type of data source.

  44. Demo Caching Caching Quickstart

  45. Enterprise Library v1 Caching Exceptions Legend Security Data Access Logging Dependency Plug-in Crypto Configuration Config Tool

  46. Sound familiar? • Writing a component to make it simpler to log and trace application information • Different groups in your enterprise writing “new and improved” logging systems • Having multiple logging systems in different layers of the application • A component that logs locally, but doesn’t extend to a distributed logging system • Inflexible configuration options for logging • Recompiling code to change logging behavior

  47. Logging Needs • 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

  48. Logging & Instrumentation Application Block • Provides a simple model for logging events • Replaces the Enterprise Instrumentation Framework and the existing Logging Application Block • Configuration driven – you decide what messages are logged where at runtime. • Sinks provided include • Event Log • Database • Text File • MSMQ • Email • WMI • Create your own…

  49. Scenarios • Populating and raising events from code • Populating a log message with additional context information • Tracing activities and propagating context information • Direct different event types to different sinks • Filter events based on category or priority • Configure logging to be done synchronously or asynchronously • Customize how logging messages are formatted

  50. Populating and raising events • Log a message Logger.Write(“Something of note”); • How and where logging is done is determined by configuration • Convenient overloads allow you to set additional properties Logger.Write(“Something of note”, “DataAccessCategory”); Logger.Write("Something of note", "General", 1, 200, Severity.Information, "Sample Entry");

More Related