Skip to content
Merged
9 changes: 8 additions & 1 deletion src/Castle.Windsor/Core/ComponentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public sealed class ComponentModel : GraphNode

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly List<Type> services = new List<Type>(4);
private HashSet<Type> servicesFast = new HashSet<Type>();

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ComponentName componentName;
Expand Down Expand Up @@ -331,6 +332,12 @@ public IEnumerable<Type> Services
{
get { return services; }
}

[DebuggerDisplay("Count = {services.Count}")]
public HashSet<Type> FastServices
{
get { return servicesFast; }
}

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal ParameterModelCollection ParametersInternal
Expand Down Expand Up @@ -378,7 +385,7 @@ public void AddService(Type type)
type));
}

ComponentServicesUtil.AddService(services, type);
ComponentServicesUtil.AddService(services,servicesFast, type);
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions src/Castle.Windsor/Core/Internal/ComponentServicesUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ public class ComponentServicesUtil
{
private static readonly TypeByInheritanceDepthMostSpecificFirstComparer comparer = new TypeByInheritanceDepthMostSpecificFirstComparer();

public static void AddService(IList<Type> existingServices, Type newService)
public static void AddService(IList<Type> existingServices,HashSet<Type> lookup, Type newService)
{
if (existingServices.Contains(newService))
if (lookup.Contains(newService))
{
return;
}
if (newService.GetTypeInfo().IsInterface)
{
existingServices.Add(newService);
lookup.Add(newService);
return;
}
if (newService.GetTypeInfo().IsClass == false)
Expand All @@ -44,18 +45,21 @@ public static void AddService(IList<Type> existingServices, Type newService)
if (existingServices[i].GetTypeInfo().IsInterface)
{
existingServices.Insert(i, newService);
lookup.Add(newService);
}
var result = comparer.Compare(newService, existingServices[i]);
if (result < 0)
{
existingServices.Insert(i, newService);
lookup.Add(newService);
return;
}
if (result == 0)
{
return;
}
}
lookup.Add(newService);
existingServices.Add(newService);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Castle.Windsor/MicroKernel/Handlers/AbstractHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public object Resolve(CreationContext context)

public virtual bool Supports(Type service)
{
return ComponentModel.Services.Contains(service);
return ComponentModel.FastServices.Contains(service);
}

public virtual bool SupportsAssignable(Type service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ComponentRegistration<TService> : IRegistration
{
private readonly List<IComponentModelDescriptor> descriptors = new List<IComponentModelDescriptor>();
private readonly List<Type> potentialServices = new List<Type>();
private readonly HashSet<Type> potentialServicesFast = new HashSet<Type>();

private bool ifComponentRegisteredIgnore;
private Type implementation;
Expand Down Expand Up @@ -473,7 +474,7 @@ public ComponentRegistration<TService> Forward(IEnumerable<Type> types)
{
foreach (var type in types)
{
ComponentServicesUtil.AddService(potentialServices, type);
ComponentServicesUtil.AddService(potentialServices,potentialServicesFast , type);
}
return this;
}
Expand Down