Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 8883 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET > Plug & play architecture using policy application blocks

Plug & play architecture using policy application blocks

Article posted by Questpond on 10/20/2008 | Views: 1918 | Category: ASP.NET | Level: Advance red flag

Advertisements

Advertisements
In this section we will discuss how we can make plug & play architecture using policy application blocks. What we will do is we will take a practical scenario where we want to enable logging for an application depending on situations

Title:        Plug and play architecture using policy application blocks
Author:      Shivprasad Koirala 
Email:       shiv_koirala@yahoo.com
Language:    Architecture Interview Questions
Level:       Beginner
Description: Plug and play architecture using policy application blocks

Plug & play architecture using policy application blocks


Introduction

Problem

Solution

Implementation
 

Introduction
 

In this section we will discuss how we can make plug & play architecture using policy application blocks. What we will do is we will take a practical scenario where we want to enable logging for an application depending on situations.

For past some days I have been writing and recording videos for architecture and project managers. You watch the videos at http://www.questpond.com
 

Problem


To understand the real use of policy application blocks we will take up a real time scenario. No application is perfect and it is very much possible that you can have defects in production. In production as a rule we have fully compiled DLL’s and it will be very difficult to track down the errors. We can definitely use TRACE to get to the bottom of the problem. One of the issues with TRACE is that we do not get verbose information. From trace we will just get which method has the issues.
Below is a solution which I have thought I am sure there are better ways of doing it. The whole point of this article is to make understand how we can use the plug and play mechanism given by policy application blocks.

We will try to implement a plug and play mechanism. The application interface of our project calls business classes. When we want to enable the debug mode we will just plug in the logging application block. The logging application block will start logging in method calls in event log which we can use to analyze what issue we have in the application. In the normal production mode we will remove the logging feature. The below figure visualizes the same as a switch
Which can plug in the logging or plug it out.

 

Solution
 

To implement the above solution we will use policy application blocks. Policy application blocks helps us to plug in policies which can be added and remove on fly. Using the enterprise application UI you can add new policies or remove policies.
 

Implementation
 

In order that the class methods can be monitored by the policy block we need inherit the class from an interface. For the current example we want to monitor any methods of class clsFireMethods. You can see we have inherited the same from a interface ‘IMethods’
 

Now open the web.config file of the project and add the policy injection block. When you add the policies you will see two important nodes one of the policy and the other is the handler. Currently we only want log the method calls in event viewer so we will add logging handler. In order that logging handler should function properly we also need to add the logging application block. Now we need to add when these handlers should be fired. For the current scenario we would like to see firemethod1 call logged when the method is called. So we have added the member name matching rule and added the member name in the matches collection.

No we are all set. In the code we just need to call the ‘PolicyInjection’ static class to create the object. This class ties up the handlers and the rules accordingly. Please note to add the policy injection namespace in the code.



Once you are all done test the project with logging handler enabled and without. Whenever firemethod1 is called you will see an entry on the event logger.
You can add more handlers. Depending on how you add the handlers the sequence will fire. So it will fire from top to bottom.

 

 

Advertisements

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:0 year(s)
Home page:http://www.questpond.com
Member since:Wednesday, September 03, 2008
Level:Starter
Status: [PanelMember] [Member] [Microsoft_MVP] [MVP] [Administrator]
Biography:

I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos ,
writing books and corporate trainings. Do visit my site for 
.NET, C# , design pattern , WCF , Silverlight
, LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server  training 
and Interview questions and answers

>> Write Response - Respond to this post and get points
Related Posts

In this article we shall learn how to validate a TextBox as a mandatory field, how to validate a DropDownList / ListBox and What is Cause Validation property and how to avoid validation on clicking of a button.

I have tried to give the steps for using the MENU control.

If you want to modify some functionality of existing Grid View control of ASP .Net then you always have the option of extending the control. In this article I have extend the Grid View with custom field. To extend the Grid View control you can inherit the new class from existing class or any of the following class 1). DataControlField – The base class for bind field 2). ButtonFieldBase – The base class for all button field and command field. In this article I am extending the Grid View control of ASP .Net with LongTextField and ConfirmDeleteButton (it will be in my next blog)

Generally GridView is used to show data in tabular format. It also provide ways to modify and delete records but currently there is no way to insert record using GridView. In this article, I shall describe an easy work around to insert record using GridView.

SQL Membership provider is mainly using for storing and retrieving user credentials for an application. This will avoid lengthy codes for user authentication from applications. There are mainly two types of Membership providers are there, SQLMembershipProvider and ActiveDirectoryMembershipProvider. For adding users, Microsoft providing a setup wizard named ASP.NET SQL Server Setup Wizard. Here I am discussing about SQLMembershipProvider.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/18/2013 9:22:16 PM