The conception, birth, and first steps of an application named Charlie

Subscribe: Atom or RSS

The WebContext Builder

by Alister Jones (SomeNewKid)

The documentation for the WebContext object is that it is to provide “details of all information and objects needed for Charlie and its plugins to respond to a user’s HTTP request.” That’s a significant responsibility, and requires the WebContext object to expose quite a number of properties. The WebContext object also includes the WebRequest and WebResponse objects, making the WebContext object even more complex. The problem is, where to put all the code that initializes the WebContext object and its child WebRequest and WebResponse objects? For most objects, the initialization code is inside the object itself. However, the WebContext object was already complicated enough, without having extensive initialization code placed inside it.

I decided that the code to initialize the WebContext object would be separated from the WebContext object itself. That would leave the WebContext to concentrate on its responsibility, which is to provide many useful properties. The initialization code was moved into the WebContextBuilder class, which is a simple application of the Builder pattern. The WebContextBuilder class takes the current HttpContext class, and pulls it apart in order to figure out all the details necessary to initialize the WebContext class.

This application of the Builder pattern was very simple, but it did keep the WebContext, WebRequest, and WebResponse objects very pure in their responsibility (and keeps their code neat, too).

by Alister Jones | Next up: The WebApplication Object

0 comments

----