Getting Started with Enterprise Library 4.x in ASP.NET Pawas Goyal +91 9967502429.

Slides:



Advertisements
Similar presentations
Enterprise development reference architecture (EDRA) -Deepti Seelamsetti.
Advertisements

DEV392: Extending SharePoint Products And Technologies Through Web Parts And ASP.NET Clint Covington, Program Manager Data And Developer Services - Office.
Building Enterprise Applications Using Visual Studio ®.NET Enterprise Architect.
CSLA Presenter Sergey Barskiy, senior consultant at Magenic Technologies your questions Send an in order.
Leveraging Enterprise Library in Your Applications Keith Elder Quicken Loans Manager, Sr. Software Engineer Microsoft MVP Keith a t keithelder dot net.
11.1 © 2004 Pearson Education, Inc. Exam Planning, Implementing, and Maintaining a Microsoft Windows Server 2003 Active Directory Infrastructure.
Tom Hollander Solution Architect Solutions Development Centre Microsoft Australia ARC307.
Microsoft ASP.NET AJAX - AJAX as it has to be Presented by : Rana Vijayasimha Nalla CSCE Grad Student.
Hands-On Microsoft Windows Server 2003 Administration Chapter 5 Administering File Resources.
Patterns & practices Enterprise Library Brian Button Consultant/Developer patterns & practices.
Hands-On Microsoft Windows Server 2003 Administration Chapter 3 Administering Active Directory.
ASP.NET Programming with C# and SQL Server First Edition
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 10: Server Administration.
7.1 © 2004 Pearson Education, Inc. Exam Managing and Maintaining a Microsoft® Windows® Server 2003 Environment Lesson 7: Introducing Group Accounts.
Best Practices with Enterprise Library. 10/28/2008 Introductions Toi B Wright President, Dallas ASP.Net User Group Microsoft.
1 of 5 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2006 Microsoft Corporation.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Maintaining and Updating Windows Server 2008
VMware vCenter Server Module 4.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse 2.
Creating Business Workflow Using SharePoint Designer 2007 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft SQL Server.
6/1/2001 Supplementing Aleph Reports Using The Crystal Reports Web Component Server Presented by Bob Gerrity Head.
“Behind the Scenes” of the Enterprise Development Reference Architecture (EDRA) Jonathan Wanagel Microsoft patterns & practices
Introduction to the Enterprise Library. Sounds familiar? Writing a component to encapsulate data access Building a component that allows you to log errors.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
A Scalable Application Architecture for composing News Portals on the Internet Serpil TOK, Zeki BAYRAM. Eastern MediterraneanUniversity Famagusta Famagusta.

TUTORIAL # 2 INFORMATION SECURITY 493. LAB # 4 (ROUTING TABLE & FIREWALLS) Routing tables is an electronic table (file) or database type object It is.
Classroom User Training June 29, 2005 Presented by:
Introducing the Validation Application Block. Agenda  Enterprise Library 3.0 Introduction  Validation Application Block Overview  Applying, using and.
Doing Something Useful with Enterprise Library 3.0 Benjamin Day Level: Intermediate.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Microsoft Visual Basic 2005: Reloaded Second Edition
Enterprise Library for.NET Framework 2.0: Overview.
Global Customer Partnership Council Forum | 2008 | November 18 1IBM - GCPC MeetingIBM - GCPC Meeting IBM Lotus® Sametime® Meeting Server Deployment and.
Developing Workflows with SharePoint Designer David Coe Application Development Consultant Microsoft Corporation.
Enterprise Library 3.0: What’s New?. The Story So Far…  Application Blocks are reusable, extensible source-code components that provide guidance for.
ASP.NET 2.0 Chapter 5 Advanced Web Controls. ASP.NET 2.0, Third Edition2 Objectives.
An Introduction to Software Architecture
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
11 MANAGING AND DISTRIBUTING SOFTWARE BY USING GROUP POLICY Chapter 5.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Introduction to Microsoft Management Console (MMC) MMC is a common console framework for management applications. MMC provides a common environment for.
What’s new in Kentico CMS 5.0 Michal Neuwirth Product Manager Kentico Software.
Module 3 Configuring File Access and Printers on Windows 7 Clients.
Module 4 Planning for Group Policy. Module Overview Planning Group Policy Application Planning Group Policy Processing Planning the Management of Group.
Information Security 493. Lab # 4 (Routing table & firewalls) Routing tables is an electronic table (file) or database type object that is stored in a.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Getting Started with.NET Getting Started with.NET/Lesson 1/Slide 1 of 31 Objectives In this lesson, you will learn to: *Identify the components of the.NET.
Enterprise Library Caching Application Block Peter Provost Software Design Engineer Ron Jacobs Product Manager Scott Densmore Software Design Engineer.
Executive Summary - Human Factors Heuristic Evaluation 04/18/2014.
4.1 © 2004 Pearson Education, Inc. Exam Managing and Maintaining a Microsoft® Windows® Server 2003 Environment Lesson 12: Implementing Security.
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
Module 5: Managing Content. Overview Publishing Content Executing Reports Creating Cached Instances Creating Snapshots and Report History Creating Subscriptions.
Enterprise Library Overview Tom Hollander Product Manager Microsoft Edward Jezierski ArchitectMicrosoft Kyle Huntley Architect Avanade Ron Jacobs Product.
1 BCS 4 th Semester. Step 1: Download SQL Server 2005 Express Edition Version Feature SQL Server 2005 Express Edition SP1 SQL Server 2005 Express Edition.
Maintaining and Updating Windows Server 2008 Lesson 8.
Enterprise Library 3.0 Memi Lavi Solution Architect Microsoft Consulting Services Guy Burstein Senior Consultant Advantech – Microsoft Division.
SQL Database Management
Building Enterprise Applications Using Visual Studio®
LOCO Extract – Transform - Load
Enterprise Library Overview
Magento Technical Guidelines Eugene Shakhsuvarov, Software Magento
Partnership.
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
Mark Quirk Head of Technology Developer & Platform Group
Advanced Tips and Tricks
Presentation transcript:

Getting Started with Enterprise Library 4.x in ASP.NET Pawas Goyal

Agenda What is Enterprise Library? Enterprise Library Components /Architecture Common Scenarios Pre Requisite Enterprise Library Component Details ◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues References

What is Enterprise Library? Enterprise Library is: ◦ A library of application blocks that solve common challenges ◦ A set of helper classes that work in any architectural style ◦ Architectural guidance embodied in code, which ships with full source allowing you to modify and extend it ◦ Available as a free download

What is Enterprise Library? What is Enterprise Library? Enterprise Library is NOT: ◦ Part of the.NET Framework ◦ An application framework that imposes an architectural style ◦ A Microsoft product with support, compatibility and localization ◦ Available to purchase

Enterprise Library and ASP.NET Can be used in any ASP.NET application Configure just the blocks you require The most useful blocks in ASP.NET are: ◦ Data Access ◦ Caching ◦ Logging ◦ Cryptography ◦ Policy Injection ◦ Validation

Agenda What is Enterprise Library? Enterprise Library Components /Architecture Common Scenarios Pre Requisite Enterprise Library Component Details ◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues References

Enterprise Library Architecture

Security Crypto Configuration Data Access LoggingCaching Exception Handling Config Tools Core/Design Enterprise Library Components Policy Injection Validation Dependency Plug-in

Enterprise Library Application Blocks CachingCaching SecuritySecurity DataAccessDataAccessLoggingLogging ExceptionHandlingExceptionHandling ConfigHelpers & Design ConfigHelpers Instrumen- tation Object Builder CryptographyCryptography Core Policy Injection ValidationValidation

The Application Blocks (1) Caching Application Block ◦ incorporate a cache in applications. Pluggable cache providers are supported. Cryptography Application Block ◦ incorporate hashing and symmetric encryption in their applications. Data Access Application Block ◦ incorporate standard database functionality in their applications. Exception Handling Application Block ◦ consistent strategy for processing exceptions that occur throughout the architectural layers of enterprise applications. Validation Application Block ◦ create validation rules for business objects that can be used across different layers of their applications.

The Application Blocks (2) Logging Application Block ◦ include standard logging functionality in their applications. Policy Injection Application Block ◦ The Enterprise Library Policy Injection Application Block provides a mechanism for automatically applying policies to object instances;. Security Application Block ◦ Developers can use this application block to incorporate authorization and security caching functionality in their applications Unity Application Block ◦ Lightweight and extensible dependency injection container with support for constructor, property, and method call injection, as well as instance and type interception (via an extension).

Agenda What is Enterprise Library? Enterprise Library Components /Architecture Common Scenarios Pre Requisite Enterprise Library Component Details ◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues References

Common Scenarios (1) Enterprise Library can be useful in a variety of situations: Enterprise Library provides enough functionality to support many common scenarios that enterprise-level applications must address. Enterprise Library can serve as the basis for a custom library. You can take advantage of the extensibility points incorporated in each application block and extend the application block by supplying new providers. You can also modify the source code for the existing application blocks to incorporate new functionality. You can also add new application blocks to Enterprise Library. You can either develop extensions for existing application blocks and new application blocks yourself or you can use extensions and application blocks developed by others. Enterprise Library is designed so that its application blocks can function independently of each other. You have to add only the application blocks that your application will use; you do not have to add the entire library.

Common Scenarios (2) Enterprise Library includes the source code and the unit tests for all application blocks. This means you can modify the application blocks to merge into your existing library or you can use parts of the Enterprise Library source code in other application blocks or applications that you build. Enterprise Library includes documentation, quick start samples, and source code. Hands-on-labs and webcasts are posted as separate downloads on the Enterprise Library Home page. This means that you can use the library as a tool for learning architectural, design, and coding best practicesEnterprise Library

Agenda What is Enterprise Library? Enterprise Library Components /Architecture Common Scenarios Pre Requisite Enterprise Library Component Details ◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues References

Prerequisite For all application blocks except for the Unity Application Block, the Enterprise Library core features, and the configuration tools, the minimum requirements are: ◦ Microsoft Windows XP Professional, Windows Server 2003, Windows Server 2008, or Windows Vista operating system ◦ Microsoft.NET Framework 3.5 or later ◦ Microsoft Visual Studio 2008 development system (any of the following editions): ◦ Standard Edition ◦ Professional Edition ◦ Team Edition for Software Developers ◦ Team Edition for Software Testers ◦ Team Edition for Software Architects ◦ Team Suite

Agenda What is Enterprise Library? Enterprise Library Components /Architecture Common Scenarios Pre Requisite Enterprise Library Component Details ◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues References

Security Crypto Data Access Logging Caching Exception Handling Enterprise Library Components Details Policy Injection Validation Unity

◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues Caching Application Block

◦ Brief The Caching application block has been designed to simplify development tasks that implement caching functionality. It provides a thread and exception safe model that give support for local caches that can help improve performance, scalability and availability. The caching block is not designed to replace the ASP.NET cache but to work with it. The caching block provides a number of features that are not available to the ASP.NET cache such as:  The ability to use a persistent backing store  Multiple methods of setting expiration times  Can be used for project types other than web applications  The core settings are described in configuration and can be changed without recompilation of the project. In addition to the caching block can be extended to create your own expiration policies and storage mechanisms

◦ Prerequisite No Specific Requirements ◦ Sample Code ◦ First prepare application  Add a reference to the Caching Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click the Browse tab and find the location of the  Microsoft.Practices.EnterpriseLibrary.Caching.dll  Microsoft.Practices.EnterpriseLibrary.Common.dll  Microsoft.Practices.ObjectBuilder2.dll Select the assemblies and then click OK to add the reference. To use elements from the Caching Application Block without fully qualifying the element reference, add the following using Microsoft.Practices.EnterpriseLibrary.Caching; using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations; Caching Application Block

Example Code The following code shows how to Add item in Cache ICacheManager productsCache = CacheFactory.GetCacheManager(); string id = "ProductOneId"; string name = "ProductXYName"; int price = 50; Product product = new Product(id, name, price); productsCache.Add(product.ProductID, product, CacheItemPriority.Normal, null, new SlidingTime(TimeSpan.FromMinutes(5))); Caching Application Block

◦ Scenarios ◦ A consistent form of caching is required across different application environments. ◦ If there is a requirement for a persistent backing store. ◦ Caching configuration may need to change after deployment. ◦ When one of the following expiration policies of cached data need to be used. absolute time, extended time, sliding time, file dependency or never expired.

◦ Issues/Disadvantages ◦ You cannot synchronize caching across a Web farm. ◦ The Caching Application Block does not support encryption of data that is cached in memory. If a malicious user finds a way of compromising the system and accessing the memory of your application's process, he or she would be able to access information stored in the cache. If this is a significant threat to your application, do not store sensitive information, such as credit card numbers or passwords, in the cache. Caching Application Block

◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues Cryptography Application Block

◦ Brief The Cryptography application block has been designed to simplify development tasks that implement cryptographic functionality. It encapsulates the available windows security API's simplifying and standardising the way cryptographic functionality is performed within an application. The key design goals of this application block that improve coding and productivity for developers are. ◦ Provide a simple and intuitive interface to the commonly required functionality. ◦ Present a standard consistent model for common cryptography tasks. ◦ Make sure minimal or negligible performance impact compared to manually written cryptography code that accomplishes the same functionality. ◦ Provide a key protection model that can be customized to satisfy your organization's security requirements.

◦ Prerequisite No Specific Requirements ◦ Sample Code ◦ First prepare application Add a reference to the Caching Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click Browse to locate the Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.ObjectBuilder2.dll. Select the assemblies and then click OK to add the reference. To use elements from the Caching Application Block without fully qualifying the element reference, add the following using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography ; Cryptography Application Block

Example Code The following code shows how to encrypt and decrypt data. This code shows how to use the overloads that accept a string. string encryptedContentsBase64 =Cryptographer.EncryptSymmetric("symmProvider", "SensitiveData"); // Decrypt the base64 encoded string string readableString; readableString = Cryptographer.DecryptSymmetric("symmProvider", encryptedContentsBase64); Cryptography Application Block

◦ Scenarios ◦ There is a requirement for secure encryption of data. ◦ There is a requirement for Hash values to be create. E.g. Password Hashes ◦ The encrypted data does not need to be sent across a network and decrypted at the other end. This is better done using Asymmetric encryption ◦ If there is a requirement to standardize how encryption is handled both within an application and across the enterprise.

◦ Issues/Disadvantages ◦ There is a requirement to use Asymmetric encryption. This is not supported by the application block ◦ An encryption algorithm provides no security if the encryption algorithm is cracked or is vulnerable to brute force cracking. Cryptography Application Block

◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues Data Access Application Block

◦ Brief ◦ The Data Access application block has been designed to simplify development tasks that implement data access functionality, regardless of the source of that data.  The Data Access Application Block provides the following benefits:  It uses the functionality provided by ADO.NET 2.0 and with it, you can use ADO.NET functionality along with the application block's functionality.  It reduces the need to write boilerplate code to perform standard tasks.  It helps maintain consistent data access practices, both within an application and across the enterprise.  It reduces difficulties in changing the database type.  It relieves developers from learning different programming models for different types of databases.  It reduces the amount of code that developers must write when they port applications to different types of databases.

◦ Prerequisite No Specific Requirements ◦ Sample Code ◦ First prepare application Add a reference to the Data Access Application Block assembly. In Visual Studio, right- click your project node in Solution Explorer, and then click Add References. Click Browse to locate the Microsoft.Practices.EnterpriseLibrary.Data.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.ObjectBuilder2.dll. Select the assemblies and then click OK to add the reference. To use elements from the Data Access Application Block without fully qualifying the element reference, add the following using Microsoft.Practices.EnterpriseLibrary.Data; Data Access Application Block

To configure a connection string ◦ Click the Connection String node. ◦ (Optional) Set the Name property by typing a new name. This is the name of the Connection String node. The default name is Connection String. ◦ (Optional) In the ProviderName property section, change the provider name. Enter the name of the provider or select it from the drop-down list. The default provider name is System.Data.SqlClient. The ProviderName property must be a provider name specified in a DbProviderFactory class. ◦ Update the ConnectionString property as required. For example, this connection string specifies the local SQL Server Express named database instance using itegrated Windows security: ◦ Database=Database;Server=(local)\SQLEXPRESS;Integrated Security=SSPI

Example Application Code The following code shows how to call a stored procedure that returns a DataSet. Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetStoredProcCommand("GetProductsByCategory"); db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, 7); DataSet productDataSet = db.ExecuteDataSet(dbCommand); Data Access Application Block

◦ Scenarios The Data Access Block should be used if the application will be using standard data access techniques and there is a need to use a simple standardized method of data access that conforms to Microsoft's Patterns and Practices recommendations. If however the application needs to get data in a specialized way or customizations are required then using ADO. NET directly may be a better option

◦ Issues/Disadvantages ◦ DAAB places quite a bit of logic into configuration files. ◦ Does not support Connected Architecture. ◦ Connection string is not stored in encrypted format in the configuration file. ◦ you are using another layer over ADO.NET, which can make debugging a little harder, but the speed loss and complexity are miniscule. Data Access Application Block

◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues Exception Handling Application Block

◦ Brief The Enterprise Library Exception Handling Application Block helps developers and policy makers to create a consistent strategy for processing exceptions that occur in all architectural layers of an enterprise application. It does this in the following ways: ◦ It supports exception handling in all architectural layers of an application and is not limited to service interface boundaries. ◦ It allows exception handling policies to be defined and maintained at the administrative level so that policy makers, who might be system administrators as well as developers, can define how to handle exceptions. They can maintain and modify the rules that govern exception handling without changing the application block code. ◦ It invokes exception handlers in a consistent manner. This means that the handlers can be used in multiple places within and across applications.

Exception Handling Application Block Brief(continue) ◦ It provides commonly used exception handling functions, such as the ability to log exception information, the ability to hide sensitive information by replacing the original exception with another exception and the ability to maintain contextual information for an exception by wrapping the original exception inside another exception. These functions are encapsulated in.NET classes named exception handlers. ◦ It can combine exception handlers to produce the desired response to an exception, such as logging exception information followed by replacing the original exception with another. ◦ It lets developers create their own exception handlers.

◦ Prerequisite No Specific Requirements ◦ Sample Code ◦ First prepare application Add a reference to the Exception Handling Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click Browse to locate the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.ObjectBuilder2.dll. Select the assemblies and then click OK to add the reference. To use elements from the Exception Handling Application Block without fully qualifying the element reference, add the following using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling; Exception Handling Application Block

Example Code The following code shows how to execute the policy named "Data Access Policy" when an exception occurs. try { // Run code. } catch(Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, " Data Access Policy"); if (rethrow) throw; } Exception Handling Application Block

◦ Scenarios A method should catch exceptions only when it has to perform one or more of the following actions: ◦ Gather information for logging. ◦ Add any relevant information to the exception. ◦ Try to recover ◦ When you need to change policies because of changing security or other operational issues. ◦ When you need to log exception information or display exception information to the user.

◦ Issues/Disadvantages It depends on that you have configured all policies that you use in code. This could be a problem if you develop generic components or smaller frameworks because you are suddenly in the situation where you have to trust the user (=the developer) of your components to define all policies that you use in your code or else your code will break. This requires that you document it very well and probably also make some recommended configuration for the components that you deliver as part of the component. Generally the documentation of the entire EntLib has a lot more to wish and I hope that they start publishing better examples and documentation (hopefully before their next release, that will target.NET Framework 2.0). Exception Handling Application Block

◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues Logging Application Block

◦ Brief The logging application block simplifies the implementation of common logging functions. It allows the developer to write information to a variety of locations based on the configuration used. These include ◦ The event log ◦ An message ◦ A database ◦ A message queue ◦ A text file ◦ A WMI event Custom locations using application block extension points

◦ Prerequisite No Specific Requirements ◦ Sample Code ◦ First prepare application  Add a reference to the Logging Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click the Browse tab and find the location of the Microsoft.Practices.EnterpriseLibrary.Logging.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.ObjectBuilder2.dll Select the assemblies and then click OK to add the reference. To use elements from the Logging Application Block without fully qualifying the element reference, add the following using Microsoft.Practices.EnterpriseLibrary.Logging; using Microsoft.Practices.EnterpriseLibrary.Logging.ExtraInformation; using Microsoft.Practices.EnterpriseLibrary.Logging.Filters; Logging Application Block

Example Application Code The following code shows how to populate and raise an event in your application. The LogEntry object has a priority of 2 and belongs to both the Trace and UI Events categories. LogEntry logEntry = new LogEntry(); logEntry.EventId = 100; logEntry.Priority = 2; logEntry.Message = "Informational message"; logEntry.Categories.Add("Trace"); logEntry.Categories.Add("UI Events"); Logger.Write(logEntry); Logging Application Block

◦ Scenarios The Logging Application Block should be used when: ◦ There is a requirement to log information to the event log, e- mail, a database, a message queue, windows management instrumentation (WMI), or a file. ◦ There is a need to filter logging messages based on category or priority. ◦ The messages need to be formatted. ◦ There is a requirement to change the destination of the message without changing the application code. ◦ A simple, consistent interface for logging within the application and across the enterprise is required

◦ Issues/Disadvantages ◦ The Logging Application Block formatters do not encrypt logging information ◦ LAB places quite a bit of logic into configuration files. Logging Application Block

◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues Policy Injection Application Block Policy Injection Application Block

Policy Injection Application Block ◦ Brief ◦ The Enterprise Library Policy Injection Application Block provides a mechanism for automatically applying policies to object instances. This helps developers to better manage crosscutting concerns, maximize separation of concerns, and encapsulate behavior. Developers define the set of policies for the target classes and their members through configuration of the Policy Injection Application Block or by applying attributes to individual members of the target class. ◦ The Policy Injection Application Block ships with pre-built handlers for these application blocks that speed up development when using Enterprise Library to help manage crosscutting concerns. Developers can also create custom handlers and policies that carry out almost any required interception processing for methods and properties of their objects.

◦ Prerequisite No Specific Requirements ◦ Sample Code ◦ First prepare application  Add a reference to the Policy Injection Application Block  assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click the Browse tab and find the location of the Microsoft.Practices.EnterpriseLibrary.PolicyInjection.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.ObjectBuilder2.dll Select the assemblies and then click OK to add the reference. To use elements from the Policy Injection Application Block without fully qualifying the element reference, add the following  using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;  using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers; Policy Injection Application Block

Example code Let's say we have a policy for our store that whenever an order is returned it must be logged along with the reason it was returned. For simplification, here are my classes: public class Order : IOrder { public void Return(string reason) { // Do something... } } public interface IOrder { void Return(string reason); } Policy Injection Application Block

One option is to use the Enterprise Library Logging Application Block directly and somewhere during the Return Process just make a call that logs the information:Logging Application Block LogEntry logEntry = new LogEntry(); logEntry.Message = "...“ logEntry.Categories.Add("..."); //... Logger.Write(logEntry); With the Policy Injection Application Block, however, we can avoid this extra code by defining a policy that whenever a call is made to the Return Method on IOrder we should log a message.

Policy Injection Application Block There are numerous ways to match policies to methods, but in this case I am going to use the TagMatchingRule which means I just have to add a tag attribute to the Return Method on the Interface. Hence rather than writing all the LogEntry code above and explicitly calling the logging application block, I will just add the following to the IOrder Interface: public interface IOrder { [Tag("Log")] void Return(string reason); }

Policy Injection Application Block ◦ Scenarios ◦ The Policy Injection Application Block provides a ready-built solution that is easy to implement in new and existing applications, particularly in applications that already take advantage of the features of the Enterprise Library. ◦ The Policy Injection Application Block provides a solution that allows developers, operators, and administrators to create, modify, remove, and fine-tune interception policies though configuration, generally without requiring any changes to the code or recompilation of the application. This limits the chances of introducing errors into the code, simplifies versioning, and reduces downtime.

◦ Issues/Disadvantages Some functional limitations arise when using the Policy Injection Application Block to call routines that implement crosscutting concerns (such as validation, logging, and authorization) from handlers instead of directly from custom application code: Threaded applications where multiple calls passing through the same handler could corrupt the internal state. The application block caches policies as it initializes; the matching rules are not re-evaluated on each call. Therefore, matching rules cannot contain dynamic logic that changes over time. Policy Injection Application Block

◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues Security Application Block

Brief Developers frequently write applications that must authorize users using one or more security providers such as Microsoft Active Directory directory service, Authorization Manager, Active Directory Application Mode (ADAM), and custom authorization providers. These applications may also need to cache authentication or authorization data for the duration of a logon session. The Security Application Block simplifies these tasks by handling them in a consistent manner, abstracting the application code from the specific security providers. You can even change underlying providers through configuration without changing the underlying application code. The Security Application Block provides code that will help you with the following scenarios: ◦ Authorization ◦ Caching security-related credentials

Security Application Block ◦ The Security Application Block has the following features: ◦ It reduces the requirement to write boilerplate code to perform standard tasks. ◦ It helps maintain consistent security practices, both within an application and across the enterprise. ◦ It eases the learning curve for developers by using a consistent architectural model across the various areas of functionality provided. ◦ It provides implementations that you can use to solve common application security problems. ◦ It is extensible; it supports custom implementations of security providers.

Security Application Block The security application block has been designed to address the following areas. ◦ Authorisation ◦ Role management ◦ Profile management ◦ Caching principals ( Caching profile information and security-related credentials ) The security application block focuses on a role-based security model. The Security Application Block simplifies these tasks by handling them in a consistent manner and abstracting the application code from the specific security providers. Authentication, Authorisation, Roles and Profile Providers can work completely independently of one another but they are closely related

◦ Prerequisite No Specific Requirements ◦ Sample Code ◦ First prepare application  Add a reference to the Security Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click the Browse tab and find the location of the Microsoft.Practices.EnterpriseLibrary.Security.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.ObjectBuilder2.dll Select the assemblies and then click OK to add the reference. To use elements from the Security Application Block without fully qualifying the element reference, add the following using Microsoft.Practices.EnterpriseLibrary.Security; Security Application Block

Example Application Code The following code shows how to determine if a user is authorized to perform a task. IPrincipal principal = new GenericPrincipal(new GenericIdentity("Username"), new string[]{"Manager"}); IAuthorizationProvider ruleProvider = AuthorizationFactory.GetAuthorizationProvider("RuleProvider"); // Determine whether user is authorized for the rule defined as "Print Document". bool authorized = ruleProvider.Authorize(principal, "Print Document"); Security Application Block

◦ Scenarios The Security Application Block includes implementations of the following functions: ◦ Authorization ◦ Security-related caching and session management If your applications require the provided implementations, you can use the application block to provide this functionality. However, the application block is also designed to be extensible and includes generic providers for each function. You can adapt the providers to meet your own security requirements.

◦ Issues/Disadvantages ◦ SAB places quite a bit of logic into configuration files. Security Application Block

◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues Unity Application Block

◦ Brief The Unity Application Block (Unity) is a lightweight, extensible dependency Injection container with support for constructor, property and method call injection. It provides developers with the following advantages:  It provides simplified object creation, especially for hierarchical object structures and dependencies, which simplifies application code.  It supports abstraction of requirements, this allows developers to specify dependencies at run time or in configuration and simplify management of crosscutting concerns.  It increases flexibility by deferring component configuration to the container.  It has a service location capability, this allows clients to store or cache the container. This is especially useful in ASP.NET Web applications where the developers can persist the container in the ASP.NET session or application.

Security Crypto Configuration Data Access LoggingCaching Exception Handling Config Tools Core/Design Enterprise Library Components Policy Injection Validation Dependency Plug-in

Enterprise Library Components

◦ Prerequisite For all application blocks except for the Unity Application Block, the Enterprise Library core features, and the configuration tools, the minimum requirements are: ◦ Microsoft Windows XP Professional, Windows Server 2003, Windows Server 2008, or Windows Vista operating system ◦ Microsoft.NET Framework 2.0, 3.0, or 3.5 Microsoft Visual Studio 2005 or Visual Studio 2008 development system (any of the following editions):  Standard Edition  Professional Edition  Team Edition for Software Developers  Team Edition for Software Testers  Team Edition for Software Architects  Team Suite Unity Application Block

◦ Sample Code ◦ First prepare application Add a reference to the Unity Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click the Browse tab and find the location of the  Microsoft.Practices.Unity.dll  Microsoft.Practices.ObjectBuilder2.dll Select the assemblies and then click OK to add the reference. To use elements from the Unity Application Block without fully qualifying the element reference, add the following using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.Configuration; using Microsoft.Practices.Unity.StaticFactory;

Example Code Unity Application Block

◦ Scenarios Dependency injection provides opportunities to simplify code, abstract dependencies between objects, and generate dependent object instances automatically. However, the process may have a minor impact on performance, and it can increase complexity where only simple dependencies exist. In general, you should use the Unity Application Block in the following situations: ◦ Your objects and classes may have dependencies on other objects or classes. ◦ Your dependencies are complex or require abstraction. ◦ You want to take advantage of constructor, method, or property call injection features. ◦ You want to manage the lifetime of object instances. ◦ You want to be able to configure and change dependencies at run time. ◦ You want to be able to cache or persist the dependencies across postbacks in a Web application.

◦ Issues/Disadvantages ◦ Complex to understand ◦ Places a little bit coding logic in configuration files. ◦ Before use this you should be have great knowledge about your object there dependencies and relations. In general scenario it’s not possible. Unity Application Block

◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Scenarios ◦ Issues Validation Application Block Validation Application Block

Validation Application Block ◦ Brief The Enterprise Library Validation Application Block provides useful features that allow developers to implement structured and easy-to- maintain validation scenarios in their applications. Any application that accepts input either from users or from other systems must ensure that the information is valid in terms of some set of rules that you specify. For example phone number You can also group validators together in a rule set. A rule set allows you to validate a complex object or graph by composing different validators of different types and applying them to elements in the object graph. Examples of these elements include fields, properties, and nested objects.

Validation Application Block Brief (Continue) By using the Validation Application Block, you can perform validation and create rule sets in the following three ways:  Using configuration  Using attributes  Using code In addition, the Validation Application Block includes adapters that allow you to use the application block with the following technologies:  ASP.NET  Windows Forms  Windows Communications Framework (WCF)

◦ Prerequisite No Specific Requirements ◦ Sample Code ◦ First prepare application Add a reference to the Validation Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click the Browse tab and find the location of the  Microsoft.Practices.EnterpriseLibrary.Validation.dll  Microsoft.Practices.EnterpriseLibrary.Common.dll  Microsoft.Practices.ObjectBuilder2.dll Select the assemblies and then click OK to add the reference. To use elements from the Unity Application Block without fully qualifying the element reference, add the following using Microsoft.Practices.EnterpriseLibrary.Validation; using Microsoft.Practices.EnterpriseLibrary.Validation.Validators; Validation Application Block

Example Application Code This example shows how to associate a validator with an object and then validate that object. public class Customer { [StringLengthValidator(0, 20)] public string CustomerName; public Customer(string customerName) {this.CustomerName = customerName; } } public class MyExample { public static void Main() { Customer myCustomer = new Customer("A name that is toolong"); ValidationResults r = Validation.Validate (myCustomer); If (!r.IsValid) {throw new InvalidOperationException("Validation error found."); }}} Validation Application Block

◦ Scenarios o The Validation Application Block allows you to encapsulate validation best practices into easily maintainable code that you can reuse. Encapsulation also allows you to separate the application code from the validation logic. o In some situations, you may be able to update the validation logic without redeploying the application. o where the application block works well is when your validation code must work across multiple layers of the application's architecture. o In very simple cases, when you only need to validate a few objects, you may not want to incur the overhead of adding the application block.

◦ Issues/Disadvantages ◦ when you need only to validate a few objects then you have to include all VAB references. Validation Application Block

Agenda What is Enterprise Library? Enterprise Library Components /Architecture Common Scenarios Pre Requisite Enterprise Library Component Details ◦ Brief ◦ Prerequisite ◦ Sample Code ◦ Issues ◦ Key Scenarios References

Book covering Enterprise Library: ◦ "Effective Use of Microsoft Enterprise Library: Building Blocks for Creating Enterprise Applications and Services" (Addison-Wesley ISBN ). All about Enterprise Library: ◦ us).aspx us).aspx Set up for Enterprise Library: ◦ \Software\Utility\Enterprise Library Contact: Pawas Goyal