diff --git a/Syrette/ServiceContainer.cs b/Syrette/ServiceContainer.cs
index 06a58e9..181930a 100644
--- a/Syrette/ServiceContainer.cs
+++ b/Syrette/ServiceContainer.cs
@@ -24,7 +24,7 @@ public class ServiceContainer {
///
public List GetServices() where TService : class =>
descriptors.Where(d => d.ServiceType == typeof(TService))
- .Select(d => (TService)GetService(d.ImplementationType)).ToList();
+ .Select(d => (TService)GetService(d.ImplementationType, d.Arguments?.ToArray())).ToList();
///
/// Registers a singleton service with its implementation.
@@ -158,19 +158,21 @@ public class ServiceContainer {
// so we use reflection to call the generic GetService method with the provided type
// Basically we build the method GetService() at runtime and then call it.
// "Classic black magic sorcery" in reflection.
- private object GetService(Type serviceType) {
+ private object GetService(Type serviceType, object[]? args = null) {
+ List arguments = [serviceType];
+
+ if (args != null) arguments.AddRange(args.ToList().Select(a => a.GetType()));
+
var method = typeof(ServiceContainer)
.GetMethod(nameof(GetService))!
- .MakeGenericMethod(serviceType);
- return method.Invoke(this, null)!;
+ .MakeGenericMethod(arguments.ToArray());
+
+ return method.Invoke(this, args)!;
}
- private object? TryGetService(Type serviceType) {
- var method = typeof(ServiceContainer)
- .GetMethod(nameof(GetService))!
- .MakeGenericMethod(serviceType);
+ private object? TryGetService(Type serviceType, object[]? args = null) {
try {
- return method.Invoke(this, null)!;
+ return GetService(serviceType, args);
} catch {
return null!;
}
@@ -230,7 +232,7 @@ public class ServiceContainer {
throw new Exception($"Multiple constructors found for type {descriptor.ImplementationType}. Please provide a specific constructor.");
List par;
- List