diff --git a/Libraries/SPTarkov.DI/DependencyInjectionHandler.cs b/Libraries/SPTarkov.DI/DependencyInjectionHandler.cs index e3e74b5f..cfa24762 100644 --- a/Libraries/SPTarkov.DI/DependencyInjectionHandler.cs +++ b/Libraries/SPTarkov.DI/DependencyInjectionHandler.cs @@ -3,23 +3,19 @@ using SPTarkov.DI.Annotations; namespace SPTarkov.DI; -public class DependencyInjectionHandler +public class DependencyInjectionHandler(IServiceCollection serviceCollection) { private static List? _allLoadedTypes; private static List? _allConstructors; private readonly Dictionary _injectedTypeNames = new(); - private readonly IServiceCollection _serviceCollection; private readonly Dictionary _injectedValues = new(); private readonly Lock _injectedValuesLock = new(); - private bool _oneTimeUseFlag; + private readonly HashSet _typeNamesToSkip = []; - public DependencyInjectionHandler(IServiceCollection serviceCollection) - { - _serviceCollection = serviceCollection; - } + private bool _oneTimeUseFlag; public void AddInjectableTypesFromAssembly(Assembly assembly) { @@ -49,6 +45,11 @@ public class DependencyInjectionHandler { foreach (var type in typesToInject) { + if (_typeNamesToSkip.Contains(type.Name)) + { + continue; + } + _injectedTypeNames.Add($"{type.Namespace}.{type.Name}", type); } } @@ -139,6 +140,11 @@ public class DependencyInjectionHandler } } + public void AddTypeNamesToIgnore(HashSet typeNames) + { + _typeNamesToSkip.UnionWith(typeNames); + } + private void RegisterGenericComponents(TypeRefContainer typeRef) { try @@ -216,10 +222,10 @@ public class DependencyInjectionHandler HandleSingletonRegistration(registrableInterface, implementationType); break; case InjectionType.Transient: - _serviceCollection.AddTransient(registrableInterface, implementationType); + serviceCollection.AddTransient(registrableInterface, implementationType); break; case InjectionType.Scoped: - _serviceCollection.AddScoped(registrableInterface, implementationType); + serviceCollection.AddScoped(registrableInterface, implementationType); break; default: throw new ArgumentOutOfRangeException( @@ -234,7 +240,7 @@ public class DependencyInjectionHandler var serviceKey = $"{implementationType.Namespace}.{implementationType.Name}"; if (registrableInterface != implementationType) { - _serviceCollection.AddSingleton( + serviceCollection.AddSingleton( registrableInterface, (serviceProvider) => { @@ -254,7 +260,7 @@ public class DependencyInjectionHandler } else { - _serviceCollection.AddSingleton(registrableInterface, implementationType); + serviceCollection.AddSingleton(registrableInterface, implementationType); } }