DefaultDiagnosticsSubSystem
using Castle.Core.Internal;
using Castle.MicroKernel;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Castle.Windsor.Diagnostics
{
public class DefaultDiagnosticsSubSystem : AbstractSubSystem, IDiagnosticsHost
{
private readonly IDictionary<Type, IDiagnostic<object>> diagnostics = new Dictionary<Type, IDiagnostic<object>>();
public override void Terminate()
{
diagnostics.Values.OfType<IDisposable>().ForEach(delegate(IDisposable e) {
e.Dispose();
});
}
public void AddDiagnostic<TDiagnostic>(TDiagnostic diagnostic) where TDiagnostic : IDiagnostic<object>
{
diagnostics.Add(typeof(TDiagnostic), (IDiagnostic<object>)(object)diagnostic);
}
public TDiagnostic GetDiagnostic<TDiagnostic>() where TDiagnostic : IDiagnostic<object>
{
diagnostics.TryGetValue(typeof(TDiagnostic), out IDiagnostic<object> value);
return (TDiagnostic)value;
}
}
}