diff --git a/src/LightInject.Tests/ContainerMock.cs b/src/LightInject.Tests/ContainerMock.cs index b9dd01d2..18a4f085 100644 --- a/src/LightInject.Tests/ContainerMock.cs +++ b/src/LightInject.Tests/ContainerMock.cs @@ -434,5 +434,10 @@ public object GetInstance(Type serviceType, Scope scope, string serviceName) { throw new NotImplementedException(); } + + public IEnumerable GetRegisteredServices(Type serviceType) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/src/LightInject/LightInject.cs b/src/LightInject/LightInject.cs index 422e9dfa..f608c1b8 100644 --- a/src/LightInject/LightInject.cs +++ b/src/LightInject/LightInject.cs @@ -671,6 +671,13 @@ public interface IServiceFactory /// The type of class for which to create an instance. /// An instance of the . object Create(Type serviceType); + + /// + /// Get a list of ServiceRegistrations available for the requested serviceType. + /// + /// The Type for which registrations should be returned. + /// An IEnumerable (possibly empty) of s. + IEnumerable GetRegisteredServices(Type serviceType); } /// @@ -3243,6 +3250,14 @@ public ServiceContainer Clone() ScopeManagerProvider); } + /// + public IEnumerable GetRegisteredServices(Type serviceType) + { + return availableServices.ContainsKey(serviceType) + ? availableServices[serviceType].Values + : Enumerable.Empty(); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal object GetInstance(Type serviceType, Scope scope) { @@ -6286,6 +6301,9 @@ public IEnumerable GetAllInstances(Type serviceType) /// public object Create(Type serviceType) => serviceFactory.Create(serviceType, this); + /// + public IEnumerable GetRegisteredServices(Type serviceType) => serviceFactory.GetRegisteredServices(serviceType); + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal object GetScopedInstance(GetInstanceDelegate getInstanceDelegate, object[] arguments, int instanceDelegateIndex) {