Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/LightInject.Tests/ContainerMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,5 +434,10 @@ public object GetInstance(Type serviceType, Scope scope, string serviceName)
{
throw new NotImplementedException();
}

public IEnumerable<ServiceRegistration> GetRegisteredServices(Type serviceType)
{
throw new NotImplementedException();
}
}
}
18 changes: 18 additions & 0 deletions src/LightInject/LightInject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,13 @@ public interface IServiceFactory
/// <param name="serviceType">The type of class for which to create an instance.</param>
/// <returns>An instance of the <paramref name="serviceType"/>.</returns>
object Create(Type serviceType);

/// <summary>
/// Get a list of ServiceRegistrations available for the requested serviceType.
/// </summary>
/// <param name="serviceType">The Type for which registrations should be returned.</param>
/// <returns>An IEnumerable (possibly empty) of <see cref="ServiceRegistration"/>s.</returns>
IEnumerable<ServiceRegistration> GetRegisteredServices(Type serviceType);
}

/// <summary>
Expand Down Expand Up @@ -3243,6 +3250,14 @@ public ServiceContainer Clone()
ScopeManagerProvider);
}

/// <inheritdoc/>
public IEnumerable<ServiceRegistration> GetRegisteredServices(Type serviceType)
{
return availableServices.ContainsKey(serviceType)
? availableServices[serviceType].Values
: Enumerable.Empty<ServiceRegistration>();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal object GetInstance(Type serviceType, Scope scope)
{
Expand Down Expand Up @@ -6286,6 +6301,9 @@ public IEnumerable<object> GetAllInstances(Type serviceType)
/// <inheritdoc/>
public object Create(Type serviceType) => serviceFactory.Create(serviceType, this);

/// <inheritdoc/>
public IEnumerable<ServiceRegistration> GetRegisteredServices(Type serviceType) => serviceFactory.GetRegisteredServices(serviceType);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal object GetScopedInstance(GetInstanceDelegate getInstanceDelegate, object[] arguments, int instanceDelegateIndex)
{
Expand Down