Simpler configuration of proxies

What is the configurable components of EasyProxy?
Well for starters you can change their Call behaviors and Channel allocators (you can also change the ChannelFactories but its still WCF's ChannelFactories so you're stuck with that I'm afraid).

You can create a proxy with your own custom components at creation time:

IMyContract proxy = EasyProxyFactory.CreateProxy<IMyContract>(myCallBehavior);

But doing that could mean adding additional code per contract that you would like to substitute because a Call Behavior needs a Channel Allocator and that needs a Channel Factory.

You can also make use of the factory's configuration section that allows you to tweak only the part that you need to change. So let's say you would like to keep the Call Behavior but you would like to change the Channel Allocator from the Transient one to the Channel Pooled one, you could do something like this:

EasyProxyFactory.GetConfiguration<IMyContract>().ChannelAllocatorFactory = (cf, e) => new PooledChannelAllocator(cf, e);

Now every time you create a new proxy for IMyContract (which shouldn't happen much since you can reuse the same proxy over and over) it will make use of the Pooled Channel Allocator instead. So it saves you lots of unnecessary coding and configuration.

Now you can do this with the Call Behavior and Channel Factory as well.
Essentially if you make this call:
EasyProxyFactory.GetConfiguration<IMyContract>();

You get a EasyProxyFactoryConfiguration<IMyContract> back. This instance allows you to modify the following:
  • ChannelFactoryFactory - the creation process of the WCF Channel Factory - uses the ChannelFactoryDelegate
  • ChannelAllocatorFactory - as we've seen above - uses the ChannelAllocatorDelegate
  • CallBehaviorFactory - the creation process of the Call Behavior - uses the CallBehaviorDelegate

This will only tweak the proxy creation for a given contract.

Unfortunately I have not been able to come across a solution to make a global configuration (for all contracts) yet. The fact the Generics is tightly used in this solution makes it much more complex to solve. If you have any ideas on how to do this, please don't hesitate to contact me with ideas (or pull requests).

Last edited Jun 4, 2013 at 4:08 PM by dandrejvv, version 2

Comments

No comments yet.