<PackageReference Include="Castle.Windsor" Version="6.0.0" />

UsingContainerAsServiceLocator

using Castle.Core.Internal; using Castle.MicroKernel; using Castle.Windsor.Diagnostics.DebuggerViews; using System; using System.Collections.Generic; using System.Linq; namespace Castle.Windsor.Diagnostics.Extensions { public class UsingContainerAsServiceLocator : AbstractContainerDebuggerExtension { private const string name = "Potential Service Locator usages"; private IUsingContainerAsServiceLocatorDiagnostic diagnostic; public override IEnumerable<DebuggerViewItem> Attach() { IHandler[] array = diagnostic.Inspect(); if (array.Length == 0) return Enumerable.Empty<DebuggerViewItem>(); Array.Sort(array, (IHandler f, IHandler s) => f.ComponentModel.Name.CompareTo(s.ComponentModel.Name)); ComponentDebuggerView[] array2 = array.ConvertAll(base.DefaultComponentView); return new DebuggerViewItem[1] { new DebuggerViewItem("Potential Service Locator usages", "Count = " + array2.Length.ToString(), array2) }; } public override void Init(IKernel kernel, IDiagnosticsHost diagnosticsHost) { diagnostic = new UsingContainerAsServiceLocatorDiagnostic(kernel); diagnosticsHost.AddDiagnostic(diagnostic); } } }