Skip to content

Instantly share code, notes, and snippets.

@a-h
Created March 17, 2015 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-h/1991902e849ddfa26e29 to your computer and use it in GitHub Desktop.
Save a-h/1991902e849ddfa26e29 to your computer and use it in GitHub Desktop.
How to get better performance when creating WCF clients using ChannelFactory<T>
private static void RegisterServices(IKernel kernel)
{
// The ProxyGenerator is part of Castle and will emit code at runtime. This code needs to be cached
// or there will be zero improvement in performance. It's cached by default, per instance of the
// ProxyGenerator.
kernel.Bind<ProxyGenerator>()
.ToConstant(new ProxyGenerator());
// The ChannelFactoryCache will cache the creation of the ChannelFactory, which is slow because it
// requires the use of reflection.
ChannelFactoryCache.Add<IWebServiceInterface>(endpoint, GetBinding(endpoint), null);
// Setup Ninject to provide instances of a dynamically generated class which will create instances of
// a WCF channel on the fly. See the ToWcfClient extension method.
kernel.Bind<IWebServiceInterface>()
.ToWcfClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment