Skip to content

Instantly share code, notes, and snippets.

@mikehadlow
Created May 27, 2011 14:09
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 mikehadlow/995317 to your computer and use it in GitHub Desktop.
Save mikehadlow/995317 to your computer and use it in GitHub Desktop.
A Windsor registration checking extension method
using System.Linq;
using Castle.Windsor;
namespace Suteki.Common.Windsor
{
public static class WindsorExtensions
{
public static void CheckRegistration<TService, TImplementation>(this IWindsorContainer container)
{
var handlers = container.Kernel.GetHandlers(typeof(TService));
if (handlers.Length == 0)
{
throw new SutekiCommonException("No handler for {0} found", typeof (TService).FullName);
}
if(!handlers.Any(handler => handler.ComponentModel.Implementation == typeof(TImplementation)))
{
throw new SutekiCommonException("No implementation {0} found for service {1}",
typeof (TImplementation), typeof (TService));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment