Created
June 22, 2017 14:01
-
-
Save lkaczanowski/db303cf0060bac0b98558c93151adfe7 to your computer and use it in GitHub Desktop.
Extensions for Castle Windstor ie: verifying registration of dependencies
This file contains 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; | |
using System.Linq; | |
using System.Text; | |
using Castle.MicroKernel; | |
using Castle.MicroKernel.Handlers; | |
using Castle.Windsor; | |
using Castle.Windsor.Diagnostics; | |
namespace Extensions | |
{ | |
public static class WindsorContainerExtensions | |
{ | |
public static void VerifyInstallationIsValid(this IWindsorContainer container) | |
{ | |
var host = (IDiagnosticsHost)container.Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey); | |
var diagnostics = host.GetDiagnostic<IPotentiallyMisconfiguredComponentsDiagnostic>(); | |
var handlers = diagnostics.Inspect(); | |
if (handlers.Any() == false) | |
{ | |
return; | |
} | |
var message = new StringBuilder(); | |
message.AppendLine("Castle Windsor did not register all dependencies properly!"); | |
var inspector = new DependencyInspector(message); | |
foreach (var handler in handlers) | |
{ | |
((IExposeDependencyInfo)handler).ObtainDependencyDetails(inspector); | |
} | |
throw new InvalidOperationException(message.ToString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment