This will be my last post about the provider issue. I've worked out a couple of solutions and for a while I was keen on moving to a provider command object. The only problem with a command object is that properly implement you have to change the way the Microsoft system works. After a lot of consideration I decided that building on top of what Microsoft has decided to publish made the most sense.
So after deciding to make building on top of Microsoft a design goal I went back over the code and had a little epiphany. This happened when a question about the IsReusable property on the IHttpHandler interface came across my inbox. I thought, “IsReusable, what a great solution”.
Most of my problems with the provider design pattern are listed in previous posts. With the IHttpHandler interface there is a companion IHttpHandlerFactory that controls the creation of the handlers. With my provider framework solution, I am taking the same approach.
First I’ve included a set of helper classes to deal with the configuration aspects of providers. Second I’ve built an extension to the ProviderBase that will be used in the service host code, at this time it doesn’t do anything. Finally, I’ve built a provider factory that oversees the creation of ManagedProvider’s.
The ManagedProviderFactory is an intelligent factory that caches and holds instances of ManagedProviderBase and ManagedProviderPool classes. The rule to apply when creating a ManagedProvider is return true for IsReusable if the provider doesn’t hold state (i.e. access member variables) and false if it does. If a ManagedProvider is not reusable the ManagedProviderFactory creates and caches a pool of ManagedProviders to pull from.
The threading issues are removed from the actual provider implementation and contained in the factory. The threading solution that I currently implement is not a very good solution and should not be used in a high performance environment. The solution is a simple one, designed to show the concept. As I continue to develop the ServiceHost project the threading solution will work itself out.
You can download the code here. I HAVE NOT written any tests cases or made any effort to test the code. It's very possible that it doesn't work at all. I am posting it now so you can get a feel for the direction that I am taking to solve the problems inherit to the current provider design pattern.
You will need Visual Studio 2005 C# Express Edition Beta 1 to open the project.