Fix up tooling to handle new types in DI (#434)

* Fix up tooling to handle new types in DI

* Remove usings
This commit is contained in:
Jesse
2025-06-29 15:40:49 +02:00
committed by GitHub
parent 1c5e82187e
commit 7ab24629e2
3 changed files with 11 additions and 15 deletions
@@ -13,8 +13,6 @@ public class DependencyInjectionHandler(IServiceCollection serviceCollection)
private readonly Dictionary<string, object> _injectedValues = new();
private readonly Lock _injectedValuesLock = new();
private readonly HashSet<string> _typeNamesToSkip = [];
private bool _oneTimeUseFlag;
public void AddInjectableTypesFromAssembly(Assembly assembly)
@@ -45,11 +43,6 @@ public class DependencyInjectionHandler(IServiceCollection serviceCollection)
{
foreach (var type in typesToInject)
{
if (_typeNamesToSkip.Contains(type.Name))
{
continue;
}
_injectedTypeNames.Add($"{type.Namespace}.{type.Name}", type);
}
}
@@ -140,11 +133,6 @@ public class DependencyInjectionHandler(IServiceCollection serviceCollection)
}
}
public void AddTypeNamesToIgnore(HashSet<string> typeNames)
{
_typeNamesToSkip.UnionWith(typeNames);
}
private void RegisterGenericComponents(TypeRefContainer typeRef)
{
try
@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SPTarkov.DI;
using SPTarkov.Server.Core.Models.Spt.Mod;
using SPTarkov.Server.Core.Utils;
namespace HideoutCraftQuestIdGenerator;
@@ -10,7 +12,11 @@ public class HideoutCraftQuestIdGeneratorLauncher
{
try
{
ProgramStatics.Initialize();
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(WebApplication.CreateBuilder());
serviceCollection.AddSingleton<IReadOnlyList<SptMod>>([]);
var diHandler = new DependencyInjectionHandler(serviceCollection);
diHandler.AddInjectableTypesFromTypeAssembly(
typeof(HideoutCraftQuestIdGeneratorLauncher)
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SPTarkov.DI;
using SPTarkov.Server.Core.Models.Spt.Mod;
using SPTarkov.Server.Core.Utils;
@@ -11,12 +12,13 @@ public class ItemTplGeneratorLauncher
{
try
{
ProgramStatics.Initialize();
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(WebApplication.CreateBuilder());
serviceCollection.AddSingleton<IReadOnlyList<SptMod>>([]);
var diHandler = new DependencyInjectionHandler(serviceCollection);
diHandler.AddTypeNamesToIgnore(["HttpServer", "HttpCallbacks"]);
diHandler.AddInjectableTypesFromTypeAssembly(typeof(ItemTplGeneratorLauncher));
diHandler.AddInjectableTypesFromTypeAssembly(typeof(App));