Aggregator Provider Pattern: An Extension of Provider Pattern

Definition

Aggregator Provider Pattern is an extension of Provider Pattern, which enables us to create and utilize multiple instance of the class having the same provider interface. In this pattern, there is an Aggregator class which implements the provider interface and contains a collection of instances of classes having the same provider interface.

The underlying caller class of this aggregator is simply unaware of how many provider instances do the caller Provider Aggregator contains, but all of the provider instances will be utilized with a single invocation from the caller class.

image

Comparison with Provider Pattern

Provider Aggregator Pattern is fully compatible with the existing Provider Pattern and the power of provider pattern can be easily extended to use multiple providers concurrently without any modification on the caller classes that were using a provider.

In short Provider Pattern is concerned with the utilization of one of the available providers; whereas Aggregator Provider Pattern is concerned with the utilization of all of the available providers at the same time.

Example Demonstration

Aggregator Provider Pattern is useful when we need a configurable framework to add/remove multiple services used by one caller/user. For instance we can have Logger Provider framework, where we need log info to be saved at text files, save to database and sent to email addresses and so on. Having an easy configurable framework along with Aggregator Provider Pattern will enable us to add or remove more services without requiring the code modification in the code that uses this provider.

image

Regarding the example case that just been described can utilize the Aggregator Provider Pattern, by creating the classes as illustrated above. The code snippet below shows a basic usage of this pattern, where the last line will perform the log operation based in list of log providers loaded in the aggregator class dynamically.

image

Download the latest white paper and samples from MSDN Code Gallery.

 

EISK

Boosting Up ASP.NET MVC Productivity!

Learn with the help of EISK, how you can make your ASP.NET skill up to 300% productive in real-world software project, along with tons of fun and excitements.

1 Comment

  • Previously when required to write log in many loggers, we just instancead multiple loggers again and again and call log methods as many times as we required. We thought that that was the best approach. But we are wrong.

    "Aggregator Provider Pattern" is the best solution to solve that logger problem.

    Many many thanks for inventing that pattern. I hope it will solve the issues of using multiple logger. I also hope it will be very popular pattern because of its simplicity.
    Thanks once again!

Comments have been disabled for this content.