Skip to content

Commit

Permalink
Added GetServiceDescriptors()
Browse files Browse the repository at this point in the history
  • Loading branch information
VNNCC committed Mar 28, 2024
1 parent 15bab92 commit 5fdd5ab
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public static ServiceDescriptor Scoped(Type serviceType, Type implementationType
/// <inheritdoc/>
public Type ImplementationType { get; }

/// <summary>
/// The optional service key.
/// </summary>
public object? ServiceKey { get; }

/// <inheritdoc/>
public ServiceLifetime Lifetime { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,16 @@ public interface IServiceDescriptorReceiver : IDisposableContainer
/// <typeparam name="T">The type of the service.</typeparam>
/// <param name="serviceKey">The optional service key.</param>
/// <returns>The optional service descriptor for the specified type.</returns>
IServiceDescriptor? GetOptionalServiceDescriptor<T>(object? serviceKey);
IServiceDescriptor? GetOptionalServiceDescriptor<T>(object? serviceKey);

/// <summary>
/// Returns the collection of registered service descriptors.
/// </summary>
/// <returns>The collection.</returns>
IServiceDescriptor[] GetServiceDescriptors();

/// <summary>
/// Gets the amount of registered service descriptor.
/// </summary>
int Count { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,4 @@ public interface IServiceRegistry
/// <typeparam name="T">The type of the service.</param>
/// <returns>Whether the given <typeparamref name="T"/> is registered or not.</returns>
bool IsServiceRegistered<T>(object? serviceKey);

/// <summary>
/// Gets the amount of registered services.
/// </summary>
int Count { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected object CreateBuiltInType(Type type)
return typeCode switch
{
TypeCode.Empty => throw new NotImplementedException(),
TypeCode.Object => throw new NotImplementedException(),
TypeCode.Object => new object(),
TypeCode.Boolean => false,
TypeCode.Byte => (byte)0,
TypeCode.Char => (char)0,
Expand Down
11 changes: 10 additions & 1 deletion src/Snowberry.DependencyInjection/ServiceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,16 @@ public T GetKeyedService<T>(object? serviceKey)
/// The service factory that will be used.
/// </summary>
public IScopedServiceFactory ServiceFactory { get; }


/// <inheritdoc/>
public IServiceDescriptor[] GetServiceDescriptors()
{
lock (_lock)
{
return [.. _serviceDescriptorMapping.Values];
}
}

/// <inheritdoc/>
public int Count
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Authors>Snowberry Software</Authors>
<Description>A lightweight easy to use IoC container for .NET.</Description>

<AssemblyVersion>3.2.0.0</AssemblyVersion>
<AssemblyVersion>3.3.0.0</AssemblyVersion>
<VersionPrefix>$(AssemblyVersion)</VersionPrefix>

<IsPackable>true</IsPackable>
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/Snowberry.DependencyInjection.Tests/KeyedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public void Keyed_Simple_Singleton()
}, "_KEY_");

Assert.Equal("2", serviceContainer.GetKeyedService<ITestService>("_KEY_").Name);
Assert.Equal(2, serviceContainer.Count);
Assert.Equal(2, serviceContainer.GetServiceDescriptors().Length);
}

[Fact]
Expand Down

0 comments on commit 5fdd5ab

Please sign in to comment.