Created
May 27, 2011 14:09
-
-
Save mikehadlow/995317 to your computer and use it in GitHub Desktop.
A Windsor registration checking extension method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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