views:

420

answers:

2

I'm maintaining a web application that utilizes the provider pattern as described below, for configuration purposes.

http://msdn.microsoft.com/en-us/library/ms972319.aspx
http://msdn.microsoft.com/en-us/library/ms972370.aspx

Everything has been working fine, but as we add functionality to our application, we are finding that our provider has become a mash up of several different functions that do not belong together. We are contemplating splitting up the configuration provider so that like functions are organized with other like functions. We're doing this because our original provider now has a handful of functions that do not need to be implemented by some modules. Instead of just throwing NotImplementedException on the extraneous functions when implementing the provider, we would like to just not include them at all.

We realize that we could create multiple providers using the above MSDN method, but multiple providers would just create more entries in the web.config. It would be nice to minimize entries in the web.config, since that is starting to get big.

Has anyone found another way to implement the provider model?

+1  A: 

You could look at using an inversion of control (IoC) container (Google "Castle Windsor", or StructureMap, or AutoFac, or NInject, or Microsoft Unity). Using an IoC you can either configure the "providers" in a configuration file or at the beginning of your application.

Typically you would create interfaces for each type of provider that you have. Using interfaces you could easily break up your providers however it made sense to you.

Once you have the interfaces in place you could simply ask the container for an implementation of that interface when you need it and the container will take care of instantiating a provider for you.

Jeremy Wiebe