26,04 €
Microsoft Enterprise Library is a collection of reusable software components (also known as Application Blocks) that are designed to assist developers with common enterprise development challenges. Before using an Application block, you should have a good understanding of your application requirements and of the scenarios that the Application Block is designed to address.
This book covers the fundamental elements of each Application Block so that you get a good understanding of its concepts. This is followed by referencing the required and optional assemblies and the initial configuration of that block using the configuration editor. Finally, leverage Application Block features to achieve goals of the enterprise application development.
You will first get an overview of the different Application Blocks in Enterprise Library and their inter-dependencies. Then you will learn to install the Enterprise library and optionally the source code. Then you will learn about the individual functional Application Blocks: the Data Access Application Block, Logging Application Block, Exception Handling Application Block, Caching Application Block, Validation Application Block, Security Application Block, and Cryptography Application Block.
In the Caching Application Block chapter you will learn to reference the required assemblies, configure the initial settings, cache, retrieve, remove, and flush cached data. You will also learn to configure and leverage encryption providers to encrypt cached data.
In the Validation Application Block chapter you will be introduced to concepts such as Validators, ValidatorFactory, ValidationResults, and so on. You will learn to reference the required assemblies, set up the initial configuration, validate objects using attributes, validate values programmatically, validate using configuration, and also learn to integrate the Application block with Windows Forms and ASP.NET. Finally you will learn to implement a custom validator.
In the Security Application Block chapter you will be introduced to Authorization Providers and the Security Cache Provider. You will then learn about referencing required assemblies, configure security settings, and learn to set up and validate based on the authorization rules. You will also learn to leverage the Security cache provider to cache user Identity, Principal, and Profile. Finally you will learn to implement a custom Authorization Provider.
In the Cryptography Application Block chapter you will be introduced to Hashing and Cryptography providers; you will learn to reference required assemblies, set up the initial configuration, generate/compare hash values, and implement a custom hash provider. You will also learn to encrypt/decrypt data and also implement a custom symmetric cryptography provider.
A step by step tutorial that guides you through the process of building Enterprise applications using the Application Blocks in Microsoft Enterprise Library 5.0.
This is a step-by-step tutorial in which a chapter is dedicated to each Application Block of the Microsoft Enterprise Library 5.0. We will develop small applications to implement the functions in each Application Block all through the book.
If you are a Programmer, Consultant, or an Associate Architect, who is interested in developing Enterprise applications, this book is for you. We assume that you already have a good knowledge of Microsoft .NET framework and the C# programming language.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 240
Veröffentlichungsjahr: 2010
Copyright © 2010 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2010
Production Reference: 1041110
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-849680-90-5
www.packtpub.com
Cover Image by Dorota Feifer ( <[email protected]> )
Author
Sachin Joshi
Reviewers
Nikos Anastopoulos
Anand Narayanswamy
Acquisition Editor
Rashmi Phadnis
Development Editor
Reshma Sundaresan
Technical Editor
Neha Damle
Indexers
Monica Ajmera Mehta
Rekha Nair
Editorial Team Leader
Gagandeep Singh
Project Team Leader
Lata Basantani
Project Coordinator
Leena Purkait
Proofreader
Chris Smith
Graphics
Geetanjali Sawant
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
Sachin Joshi holds a Master's Degree in Computer Applications and a Bachelor's Degree in Business Administration. He is a Microsoft Certified Professional Developer in ASP.NET and Microsoft Certified Technology Specialist in WCF and .NET 3.5 Windows. He has over five years of industry experience developing enterprise applications with Microsoft .NET and related technologies. Sachin was performing a juggling act between his college degree and running his own optical business for around five years before joining the IT industry.
Sachin is currently working as a Consultant in a well reputed software company in Hyderabad, India. He has several years of experience in designing and architecting solutions for various domains and he has been involved with several complex engagements. His technical strengths include C, C++, C#, VB.NET, Microsoft .NET, AJAX, Design Patterns, SQL Server, JavaScript, and so on. His current passion is Vala (http://live.gnome.org/Vala) a new programming language with C#-like syntax with the power of C.
Sachin blogs at http://fuzzydev.com and spends most of his time reading books and playing with different technologies. When not at work, Sachin spends time with his family, watching movies and playing video games. He and his wife have not only pledged but are working towards spreading awareness of the noble cause of organ donation. Sachin has a dream of opening a library for students who are economically disadvantaged, to enable them to grow. In the technology arena, Sachin is currently working on an open source project code named Apocalypse - lifting of the veil, a CMS based on ASP.NET 4.0.
Life is not about winning or losing, it's not about battles or competitions, it's not about mistakes or missed opportunities, it's about realizing the true meaning of life, it's about freeing your mind & soul of dust, life is about your own definition of success. YOUR LIFE IS BEAUTIFUL, YOU ARE ALWAYS SUCCESSFUL PERIOD
--Sachin JoshiNo book is the product of just the author, he just happens to be the one with his name on the cover.
A number of people contributed to the success of this book, and it would take more space than I have to thank each one individually.
I am greatly indebted to Rashmi Phadnis, Acquisition Editor at Packt Publishing, for accepting my proposal and also for her support and guidance from the beginning. I am thankful to Reshma Sundaresan, Development Editor at Packt Publishing, for the valuable advice at every stage through e-mails that encouraged me a lot. I am also thankful to Leena Purkait, Project Coordinator at Packt Publishing, for all the support and help in keeping me on schedule and also managing the schedule so professionally. I'm grateful to Nikos Anastopoulos and Anand Narayanswamy thank you for reviewing the book and providing valuable and insightful feedback. Also, thanks to Dorota Feifer for the lovely cover image.
Special mention goes to David Barnes, Acquisition Editor at Packt Publishing, with whom I had the initial interaction. Thank you David for inspiring me during our interaction and with your blog posts (http://davidbarneswork.posterous.com). Also, a big thank you to the entire Packt Publishing team, for working so diligently to help bring out a high quality product.
I must also thank the talented team of developers who have contributed to the Enterprise Library project. This product truly helps in taking the complexity out of enterprise application development and allows developers to focus on the crux of the requirements.
Nikos Anastopoulos has a BSc and MSc in Software Engineering, from Coventry University, UK, and an MBA from Athens University of Economics and Business.
He has worked at Microsoft Hellas for 10 years, as a Platform Solutions Specialist for 3.5 years and as a Senior Consultant for 6.5 years at Microsoft Consulting Services. He has worked in many development projects in Greece, mostly in the Banking sector and Telcos, using Microsoft's development products, servers, and technologies like: .NET, C# (ASP.NET), SQL Server 200x, BizTalk Server 200x, and SharePoint Portal Server 200x. In all his engagements, he has extensively used Microsoft's Enterprise Library, since its very early releases.
Before joining Microsoft he worked as a developer in ISVs for two years working on client/server and Internet applications.
I would like to thank my family; my wife, Eirini, and my two lovely daughters, Kallia and Stavrianna, for their support over these years.
Anand Narayanaswamy is a Microsoft Most Valuable Professional (MVP) based in Trivandrum, India. He works as a freelance technical writer besides devoting time for blogging and tweeting. He also works as a technical editor for ASPAlliance.com. He had worked as a technical editor/reviewer for various publishers such as Sams, Addison-Wesley, McGraw Hill, and Packt. He is the author of Community Server Quickly (www.packtpub.com/community-server/book) published by Packt Publishing and runs www.learnxpress.com and www.dotnetalbum.com.
First, I would like to thank the Almighty for giving me the strength and energy to work every day. I specially thank my father, mother, and brother for providing valuable help, support, and encouragement. I also thank Leena Purkait, Project Coordinator, Packt Publishing, and Sachin Joshi for their assistance, cooperation, and understanding throughout the review process of this book.
This book is dedicated to:
My parents, Pravin and Geeta Joshi. They have dedicated their entire life towards making me what I am today. I Love You, You Rock!!!
Thanks to my beautiful wife, Nisha, for her love, support, and patience. I Love You, you make me complete.
This book covers the fundamental elements of each application block so that you get a good understanding of its concepts. This is followed by referencing the required and optional assemblies and then initial configuration of that block using the configuration editor. Finally, it leverages the application block features to achieve goals of enterprise application development.
Chapter 1, Getting Started with Enterprise Library, introduces us to the Enterprise Library and explores various application blocks such as Unity, Policy Injection, Data Access block, Logging block, Exception Handling block, Caching block, Validation block, Security block, and Cryptography block.
Chapter 2, Data Access Application Block, explores the fundamental elements of the Data Access Application Block such as Database, SqlDatabase, OracleDatabase, SqlCeDatabase, GenericDatabase, Parameter Mapper, and Output Mappers.
Chapter 3, Logging Application Block, explores the fundamental elements of the Logging Application Block such as Log Category, Special Category, Logging Trace Listeners, Log Formatters, Logging Filters, Logger, LogWriter, LogEntry, and so on. We also learn about the various required and optional assemblies and learn to set up the initial configuration.
Chapter 4, Exception Handling Application Block, introduces us to the fundamental elements of the Exception Handling Application Block such as Exception Policy, Exception Types, and Exception Handler. We also learn about the required and optional assemblies, the initial infrastructure configuration, and the individual feature-level configuration.
Chapter 5, Caching Application Block, teaches us the fundamental elements of the Caching Application Block. We further learn to configure an encryption provider to encrypt cached data while using a persistent backing store.
Chapter 6, Validation Application Block, teaches us to validate objects using various approaches such as using an attribute, self-validation, programmatically, and through configuration. We also learn how the Validation Application Block can be integrated with Windows Forms-based applications and ASP.NET web applications.
Chapter 7, Security Application Block, introduces us to the key features of the Security Application Block and explores the elements of Authorization and Security Cache Providers. We also learn about the various required and optional assemblies.
Chapter 8, Cryptography Application Block, introduces us to the fundamental elements of the Cryptography Application Block such as IHashProvider, ISymmetricCryptoProvider, CryptographyManager, and so on. We also learn to generate hash, compare hash, and implement a custom hash provider. We also explore encryption and decryption of data and understand the basics of implementing a custom symmetric cryptography provider.
To use this book you will need Microsoft Enterprise Library 5.0.
If you are a programmer, consultant, or an associate architect, who is interested in developing Enterprise applications, this book is for you. We assume that you already have a good knowledge of Microsoft .NET framework and the C# programming language.
Feedback from our readers is always welcome. Let us know what you think about this book – what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code for this book
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books – maybe a mistake in the text or the code – we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
While developing enterprise-scale applications, developers often find themselves focusing on mundane and repeated tasks generally referred to as cross-cutting concerns: tasks such as writing repeated data access code, logging exceptions, handling and managing exceptions, caching data, validating user input, and so on. Although these tasks are important, developers often spend a lot of time implementing and debugging these cross-cutting concerns rather than channeling their efforts towards the core business requirements of customers. Developing this functionality in-house, as flexible and customizable reusable components, is one option but it involves time and money, not to mention the testing and bug-fixing effort.
This book will give you insight into Microsoft Enterprise Library, show you how to leverage the individual functional application blocks, and equip you with the knowledge to be productive in your work. Before embarking on the learning journey, read this chapter to get introduced to Enterprise Library; all other chapters are self contained so it doesn't matter whether you read the book sequentially or flip to a specific functional application block chapter with the intent to quickly get up to speed and leverage that specific functional application block.
In this chapter, you will:
Enterprise Library (EntLib) is a collection of reusable software components or application blocks designed to assist software developers with common enterprise development challenges. Each application block addresses a specific cross-cutting concern and provides highly configurable features, which results in higher developer productivity. EntLib is implemented and provided by Microsoft patterns & practices group, a dedicated team of professionals who work on solving these cross-cutting concerns with active participation from the developer community. This is an open source project and thus freely available under the Microsoft Public License (Ms-PL) at the CodePlex open source community site (http://entlib.codeplex.com), basically granting us a royalty-free copyright license to reproduce its contribution, build derivative works, and distribute them.
More information can be found at the Enterprise Library community site http://www.codeplex.com/entlib.
Enterprise Library consists of nine application blocks; two are concerned with wiring up stuff together and the remaining seven are functional application blocks. This book focuses on the seven functional blocks and we have separate chapters in this book devoted to each functional application block.
The following is the complete list of application blocks; these are briefly discussed in the next sections.
Wiring blocks provides mechanisms to build highly flexible, loosely coupled, and maintainable systems. These blocks are mainly about wiring or plugging together different functionalities. The following two blocks fall under this category:
The Unity Application Block is a lightweight, flexible, and extensible dependency injection container that supports interception and various injection mechanisms such as constructor, property, and method call injection. The Unity Block is a standalone open source project, which can be leveraged in our application. This block allows us to develop loosely coupled, maintainable, and testable applications. Enterprise Library leverages this block for wiring the configured objects. More information on the Unity block is available at http://unity.codeplex.com; the Unity block is not covered in this book.
The Policy Injection Application Block is included in this release of Enterprise Library for backwards compatibility and policy injection is implemented using the Unity interception mechanism. This block provides a mechanism to change object behavior by inserting code between the client and the target object without modifying the code of the target object. The Policy Injection block is not covered in this book.
Enterprise Library consists of the following functional application blocks, which can be used individually or can be grouped together to address a specific cross-cutting concern. This book contains dedicated chapters for each of these functional application blocks; in each chapter we will explore the application block in detail.
Developing an application that stores/retrieves data in/from some kind of a relational database is quite common; this involves performing CRUD (Create, Read, Update, Delete) operations on the database by executing T-SQL or stored procedure commands. But we often end up writing the plumbing code over and over again to perform these operations: plumbing code such as creating a connection object, opening and closing a connection, parameter caching, and so on.
The following are the key benefits of the Data Access block:
We will further dive deep into the Data Access block in Chapter 2, Data Access Application Block.
Logging is an essential activity, which is required to understand what's happening behind the scene while the application is running. This is especially helpful in identifying issues and tracing the source of the problem without debugging. The Logging Application Block provides a very simple, flexible, standard, and consistent way to log messages. Administrators have the power to change the log destination (file, database, e-mail, and so on), modify message format, decide on which category is turned on/off, and so on. The Logging block is further discussed in Chapter 3, Logging Application Block
Handling exceptions appropriately and allowing the user to either continue or exit gracefully is essential for any application to avoid user frustration. The Exception Handling Application Block adapts the policy-driven approach to allow developers/administrators to define how to handle exceptions.
The following are the key benefits of the Exception Handling Block:
We will dive deep into Exception Handling Block in Chapter 4, Exception Handling Application Block.
Caching in general is a good practice for data that has a long life span; caching is recommended if the possibility of data being changed at the source is low and the change doesn't have significant impact on the application. The Caching Application Block allows us to cache data locally in our application; it also gives us the flexibility to cache the data in-memory, in a database or in an isolated storage. The Caching block is discussed in detail in Chapter 5, Caching Application Block.
The Validation Application Block (VAB) provides various mechanisms to validate user inputs. As a rule of thumb always assume user input is not valid unless proven to be valid. The Validation block allows us to perform validation in three different ways; we can use configuration, attributes, or code to provide validation rules. Additionally it also includes adapters specifically targeting ASP.NET, Windows Forms, and Windows Communication Foundation (WCF). We will explore the Validation block in detail in Chapter 6, Validation Application Block.
The Security Application Block simplifies authorization based on rules and provides caching of the user's authorization and authentication data. Authorization can be done against Microsoft Active Directory Service, Authorization Manager (AzMan), Active Directory Application Mode (ADAM), and Custom Authorization Provider. Decoupling of the authorization code from the authorization provider allows administrators to change the provider in the configuration without changing the code. The Security block is explored in detail in Chapter 7, Security Application Block.
The Cryptography Application Block provides a common API to perform basic cryptography operations without inclining towards any specific cryptography provider and the provider is configurable. Using this application block we can perform encryption/decryption, hashing, & validate whether the hash matches some text. We will discuss the Cryptography block in detail in Chapter 8, Cryptography Application Block.
Several functional application blocks provide features that depends on other blocks; these dependencies are listed below.
Application Block
Dependencies
Condition
Logging Application Block
Data Access Application Block
If the messages have to be logged in database.
Exceptional Handling Application Block
Logging Application Block
If exception information has to be logged.
Data Access Application Block
If exception information has to be logged to database.
Caching Application Block
Data Access Application Block
If data has to be cached in database.
Cryptography Application Block
If cached data has to be encrypted.
Security Application Block
Caching Application Block
If credentials have to be cached.
Cryptography Application Block
If cached credentials have to be encrypted.
Data Access Application Block
If credentials have to be cached in database.
Following is the graphical representation of the dependencies between the functional application blocks:
