Consider the following
builder.Register(c => new A());
builder.Register(c => new B());
builder.Register(c => new C());
B
I was looking for a similar solution for registrations done as follows:
builder.RegisterType().As();
// and/or
builder.RegisterType().Keyed(key);
where IExoticTree and IMountainTree inherit from a common ITree interface.
With those, the service type (e.g. registered interface) is different from the LimitType and hence, the proposed solution is not applicable.
I got inspired by the accepted solution to manage these as well with the following code:
IEnumerable instances = scope.ComponentRegistry.Registrations
.Where(r => typeof(ITree).IsAssignableFrom(r.Activator.LimitType))
.Select(r => r.Services.First())
.Select(s => scope.ResolveService(s) as ITree)
.Distinct();
Hope it helps someone ^^