Compartilhar via


Design Pattern for Building Channel Factories and Listeners

This is just a style convention that helps you avoid doing some thinking while writing custom channel classes. During the channel construction process, there's a flow of information from the binding (design time), through the channel factory and listener, and down to the channel (run time). The channel needs to know about the configuration changes that the user has made in setting up the binding. As we've seen before, there's some difficulty with storing this information outside the channel, so we can't rely on referencing the information indirectly through another object after creation. Here's the convention that we've sort of settled on in most of our channels.

When creating the channel factory or listener (jointly referred to as the channel manager), the constructor takes two arguments.

  1. The constructor gets the this instance of the binding element that is building the channel manager. Inside the constructor, the configuration settings of the binding element are copied to private fields of the channel manager. The channel manager doesn't hold on to the binding element after initialization is complete.
  2. The constructor gets the binding context instance that the binding element was passed. The binding context instance allows the channel manager to fish out the inner channel manager and access binding parameters.

When creating the channel, the constructor takes as many arguments as it needs to pass all of the private data that was being stored in the channel manager. It can be helpful to group some of these arguments using a specialized interface if you need to pass around the same information to a lot of different places. The channel manager does not give the this instance to the channel normally. An exception is if you're using the ChannelBase class for your channel, which requires an instance of ChannelManagerBase. In that case, the channel manager gives its this instance to the channel solely for that purpose. The channel constructor takes that instance as a ChannelManagerBase rather than using a specialized type.

Next time: Mixed Mode Addressing

Comments

  • Anonymous
    November 01, 2006
    Angus, the bulldog has so taken over the house. At least, it's made us more popular with the neighbors.

  • Anonymous
    November 01, 2006
    This article covers some of the advanced topics that I left out of the earlier piece on configuring HTTP

  • Anonymous
    October 20, 2007
    Angus, the bulldog has so taken over the house. At least, it's made us more popular with the neighbors