Enterprise Library in-depth analysis and flexible application blog Series

Source: Internet
Author: User

Enterprise Library is one of the many Open source frameworks developed by Microsoft P & P. The latest version has reached 4.1. Since it has been a long time since I came into contact with the Enterprise Library, it is frequently used in actual projects. We have accumulated some experience in this regard and hope to share and communicate with the majority of users through this new series. This series assumes that the reader has a certain understanding of the Enterprise Library and will not introduce the basic principles and programming models of each Application Block, the focus is on deep implementation principles, application of design patterns, effective scaling, and best practices of Enterprise libraries.

[Article 1st]:Integration with Policy Injection Application Block through Unity Extension

PIAB implements AOP through Method Interception Based on the Remoting principle (and another common Method is based on IL Injection ). To make the application play a role in the CallHandler of the target object, you need to create the object through PolicyInjecctor (Remoting PolicyInjection by default. The integration of Unity and PIAB allows Unity Container to create objects.

Unity is built on ObjectBuilder, and ObjectBuilder is the cornerstone of the entire Enterprise Library and other open-source frameworks (such as Smart Client Software Factory) of P & P. ObjectBuilder, as its name implies, is a component for object creation. ObjectBuilder creates objects by using Strategy-based object creation. It applies different policies to different stages of object creation (or release and recycling, it provides a powerful and highly scalable object creation framework. To achieve our goal, we must first create a custom BuilderStrategy...

[Article 2nd]:Synchronize Cache and Database through SqlDependency

For a real enterprise-level application, Caching is definitely a factor that must be taken into consideration. It makes rational and effective use of Caching to enhance the Performance of the application (reducing IO operations based on Persistent storage) scalability (caching data reduces the pressure on Database and other resources) and Availability (caching data, network Problems, inaccessible Web Services, Database crashes, and so on ). The Caching Application Block of Enterprise Library provides an easy-to-use and scalable framework for implementing Caching. With the help of Caching Application Block, administrators and developers can easily implement Caching-based management and programming. Because the essence of Caching is to keep relatively stable data in the memory to avoid IO operations on Persistent storage, there are two tricky problems: Load Balance; persistent storage and data synchronization in memory. This article provides a solution for SQL Server data and Cache Synchronization Through SqlDependency.

[Article 3rd]:If Unity, PIAB, and Exception Handling are introduced into the MVP mode

Recently, I am working on a Smart Client Software Factory project. Those familiar with SCSF or CAB should be familiar with the MVP design model. MVP is a variant of MVC. View and Mode focus on the UI presentation and business model respectively. View and Mode are completely separated. View accesses the business model through Presenter, presenter "indirectly" calls View to perform operations on the UI. For Exception Handling in MVP, the Exception Handling Application Block of Enterprise Library is implemented directly. Specifically, add a try/catch block to each control event in the View, and use the ExceptionPolicy in the catch to handle exceptions. This leads to the problem that the same code is repeatedly distributed across every corner of the application. So I have another idea: using Policy Injection to handle exceptions in AOP mode, with this idea, I think more about it. Why don't we integrate Unity together?

[Article 4th]:Create a custom Exception Handler to change the ELAB Exception Handling Mechanism

Microsoft Enterprise Library ELAB (Exception Handling Application Block) provides a Policy-based Exception Handling Method in different environments, such as at different layers in a multi-tier architecture, we can define different exception handling policies. For ELAB, Exception Handling Policy = Exception Type + Exception Handler (s), that is, the Exception Handling Policy specifies that Exception Handler must be used to process certain types of data. In this sense, the ELAB Exception handling mechanism is based on the Exception Type, and the Exception Type is the minimum granularity of Exception processing. For a fixed Exception Handling Policy, the same Exception Handler will be used to handle the same type of exceptions thrown on different occasions. For example, for a Data Access operation based on SQL Server, SqlException is thrown for database connection failures and violation of Data Consistency constraints. Both cases are equivalent to ELAB because it can only handle exceptions based on the exception type.

In many cases, Exception Handling Based on the exception type does not solve our actual exception handling problem. We often need a more fine-grained Exception Handling Mechanism: for exceptions of the same type thrown, corresponding exception handling is performed based on the specific attribute values of the exception object.

[Article 5th]:Create a simple version of the batch processing executor, understand the typical configuration methods and object creation methods of Enterprise Library

This tool executes a group of Batch processing tasks and can also be seen as a Sequential Workflow Executor. I regard it as a Batch Job Executor. In the process of using Batch Job Executor, you can customize each step of Batch processing or every Activity in Workflow through configuration. In terms of functionality, this little tool is just a little thing, and it will not go to the elegant hall. However, considering that the involved and implementation of Batch Job Executor are typical implementation methods based on Enterprise Library, such as EL-based configuration and object creation methods, for those who want to know more about EL, perhaps we can look at EL's design principles through this small example. Readers who are familiar with EL design from time to time may be difficult to understand the following content. It is best to download the source code, combined with the following introduction, hoping to help you better understand EL. (Source Code download: http://files.cnblogs.com/artech/Artech.BatchJobExecutor.zip)

[Article 6th]: Create a mini-version AOP framework by yourself

The Enterprise Library PIAB-based AOP framework has been widely used in the company's project development. However, recently, my colleagues maintained an old project and used Enterprise Library 2, therefore, PIAB is released in Enterprise Library 3.0, so it is used directly. To solve this problem, I wrote a Method Interception principle and wrote a simple version of the AOP framework.

[Article 7th]: integration between PIAB and Unity

In EnteLib, PIAB (Policy Injection Application Block) and Unity are positioned as lightweight AOP frameworks and IoC containers (Container ). Through PIAB, we can define some business-independent crosscutting concern in the corresponding CallHandler and apply it to the target method that carries the business logic through Attribute declaration or configuration. By using the IoC container (or DI container) provided by Unity, namely, UnityContainer, dependency dynamic injection is well implemented, so as to achieve loose coupling between components, modules, or services.

Unity is fully built on ObjectBuilder2. As the name suggests, it is a basic component used to create objects. ObjectBuilder2 provides a highly scalable, Strategy-Based object creation framework. It is not only a basic component of Unity, but also the cornerstone of EnterLib and Software Factory. PIAB implements Policy Injection through the Method Call Interception mechanism ). PIAB provides different method hijacking mechanisms. The most typical ones are based on TransparentProxy (refer to my PIAB articles) and Code Generation (such as dynamically generating a subclass that inherits the target type, use Override to drop the corresponding Virtual method to implement policy injection, or dynamically generate a type that implements the target interface to implement the corresponding method to implement policy injection ). PIAB needs to use a special mechanism to create an Interceptable object, while UnityContainer is essentially a container for creating objects. If you can enable UnityContainer to create Interceptable according to PIAB's requirements) object. (Download the Source Code from here)

[Article 8th]: Integration of WCF and Exception Handling AppBlock [Part 1] [Part 2]

In the last chapter of "WCF Technology Analysis (Volume 1)", I gave a specific distributed application instance of the application WCF. I named this instance PetShop. In this example, I use the extended WCF to implement some design and architecture modes, such as AOP and IoC. Readers who have read this book may still remember that I have integrated the Exception Handling Application Block: EHAB in the Microsoft Enterprise Library through the WCF extension. At that time, due to lack of background knowledge, it was impossible to introduce the specific implementation. Now we can detail how this is implemented. (Download the Source Code from here)

 

Author: Artech
Source: http://artech.cnblogs.com
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.