AllServices
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 AllServices : AbstractContainerDebuggerExtension
{
private const string name = "All services";
private IAllServicesDiagnostic diagnostic;
public override IEnumerable<DebuggerViewItem> Attach()
{
DebuggerViewItem[] array = (from p in diagnostic.Inspect()
select BuildServiceView(p, p.Key.ToCSharpString())).ToArray();
Array.Sort(array, (DebuggerViewItem i1, DebuggerViewItem i2) => i1.Name.CompareTo(i2.Name));
return new DebuggerViewItem[1] {
new DebuggerViewItem("All services", "Count = " + array.Length.ToString(), array)
};
}
public override void Init(IKernel kernel, IDiagnosticsHost diagnosticsHost)
{
diagnostic = new AllServicesDiagnostic(kernel);
diagnosticsHost.AddDiagnostic(diagnostic);
}
private DebuggerViewItem BuildServiceView(IEnumerable<IHandler> handlers, string name)
{
ComponentDebuggerView[] array = handlers.Select(base.DefaultComponentView).ToArray();
return new DebuggerViewItem(name, "Count = " + array.Length.ToString(), array);
}
}
}