diff --git a/src/Snowberry.DependencyInjection/Implementation/ServiceDescriptor.cs b/src/Snowberry.DependencyInjection/Implementation/ServiceDescriptor.cs index d867763..7aa1c74 100644 --- a/src/Snowberry.DependencyInjection/Implementation/ServiceDescriptor.cs +++ b/src/Snowberry.DependencyInjection/Implementation/ServiceDescriptor.cs @@ -46,11 +46,6 @@ public static ServiceDescriptor Scoped(Type serviceType, Type implementationType /// public Type ImplementationType { get; } - /// - /// The optional service key. - /// - public object? ServiceKey { get; } - /// public ServiceLifetime Lifetime { get; } } diff --git a/src/Snowberry.DependencyInjection/Interfaces/IServiceDescriptorCollection.cs b/src/Snowberry.DependencyInjection/Interfaces/IServiceDescriptorCollection.cs index 1defeef..2d07376 100644 --- a/src/Snowberry.DependencyInjection/Interfaces/IServiceDescriptorCollection.cs +++ b/src/Snowberry.DependencyInjection/Interfaces/IServiceDescriptorCollection.cs @@ -35,5 +35,16 @@ public interface IServiceDescriptorReceiver : IDisposableContainer /// The type of the service. /// The optional service key. /// The optional service descriptor for the specified type. - IServiceDescriptor? GetOptionalServiceDescriptor(object? serviceKey); + IServiceDescriptor? GetOptionalServiceDescriptor(object? serviceKey); + + /// + /// Returns the collection of registered service descriptors. + /// + /// The collection. + IServiceDescriptor[] GetServiceDescriptors(); + + /// + /// Gets the amount of registered service descriptor. + /// + int Count { get; } } diff --git a/src/Snowberry.DependencyInjection/Interfaces/IServiceRegistry.cs b/src/Snowberry.DependencyInjection/Interfaces/IServiceRegistry.cs index a7145a6..a19c79c 100644 --- a/src/Snowberry.DependencyInjection/Interfaces/IServiceRegistry.cs +++ b/src/Snowberry.DependencyInjection/Interfaces/IServiceRegistry.cs @@ -134,9 +134,4 @@ public interface IServiceRegistry /// The type of the service. /// Whether the given is registered or not. bool IsServiceRegistered(object? serviceKey); - - /// - /// Gets the amount of registered services. - /// - int Count { get; } } diff --git a/src/Snowberry.DependencyInjection/Lookup/DefaultServiceFactory.cs b/src/Snowberry.DependencyInjection/Lookup/DefaultServiceFactory.cs index 3c23d06..859044a 100644 --- a/src/Snowberry.DependencyInjection/Lookup/DefaultServiceFactory.cs +++ b/src/Snowberry.DependencyInjection/Lookup/DefaultServiceFactory.cs @@ -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, diff --git a/src/Snowberry.DependencyInjection/ServiceContainer.cs b/src/Snowberry.DependencyInjection/ServiceContainer.cs index b68c62d..cbf63e4 100644 --- a/src/Snowberry.DependencyInjection/ServiceContainer.cs +++ b/src/Snowberry.DependencyInjection/ServiceContainer.cs @@ -273,7 +273,16 @@ public T GetKeyedService(object? serviceKey) /// The service factory that will be used. /// public IScopedServiceFactory ServiceFactory { get; } - + + /// + public IServiceDescriptor[] GetServiceDescriptors() + { + lock (_lock) + { + return [.. _serviceDescriptorMapping.Values]; + } + } + /// public int Count { diff --git a/src/Snowberry.DependencyInjection/Snowberry.DependencyInjection.csproj b/src/Snowberry.DependencyInjection/Snowberry.DependencyInjection.csproj index 7449a20..f9306d0 100644 --- a/src/Snowberry.DependencyInjection/Snowberry.DependencyInjection.csproj +++ b/src/Snowberry.DependencyInjection/Snowberry.DependencyInjection.csproj @@ -10,7 +10,7 @@ Snowberry Software A lightweight easy to use IoC container for .NET. - 3.2.0.0 + 3.3.0.0 $(AssemblyVersion) true diff --git a/src/Tests/Snowberry.DependencyInjection.Tests/KeyedTests.cs b/src/Tests/Snowberry.DependencyInjection.Tests/KeyedTests.cs index 1c960a1..9e9a656 100644 --- a/src/Tests/Snowberry.DependencyInjection.Tests/KeyedTests.cs +++ b/src/Tests/Snowberry.DependencyInjection.Tests/KeyedTests.cs @@ -20,6 +20,8 @@ public void Keyed_Simple_Singleton() }, "_KEY_"); Assert.Equal("2", serviceContainer.GetKeyedService("_KEY_").Name); + Assert.Equal(2, serviceContainer.Count); + Assert.Equal(2, serviceContainer.GetServiceDescriptors().Length); } [Fact]