From 357c6adb7a5af4aeb99fddcda4434065dd42bc89 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 20 Jul 2024 16:22:31 -0700 Subject: [PATCH] Resolve circular dependency --- mod/TTT.Round/RoundBehavior.cs | 9 +++++++-- src/TTT/TTTServiceCollection.cs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mod/TTT.Round/RoundBehavior.cs b/mod/TTT.Round/RoundBehavior.cs index bbc413c..360c369 100644 --- a/mod/TTT.Round/RoundBehavior.cs +++ b/mod/TTT.Round/RoundBehavior.cs @@ -5,6 +5,7 @@ using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; using CounterStrikeSharp.API.Modules.Timers; +using Microsoft.Extensions.DependencyInjection; using TTT.Public.Behaviors; using TTT.Public.Extensions; using TTT.Public.Formatting; @@ -13,13 +14,17 @@ namespace TTT.Round; -public class RoundBehavior(IRoleService _roleService) - : IRoundService, IPluginBehavior { +public class RoundBehavior : IRoundService, IPluginBehavior { private Round? _round; private int _roundId = 1; private RoundStatus _roundStatus = RoundStatus.Paused; + private readonly IServiceProvider _provider; + private IRoleService _roleService = null!; + + public RoundBehavior(IServiceProvider provider) { _provider = provider; } public void Start(BasePlugin plugin) { + _roleService = _provider.GetRequiredService(); plugin.RegisterListener(TickWaiting); plugin.AddCommandListener("jointeam", OnTeamJoin); VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(BlockDamage, diff --git a/src/TTT/TTTServiceCollection.cs b/src/TTT/TTTServiceCollection.cs index e082150..89f25c5 100644 --- a/src/TTT/TTTServiceCollection.cs +++ b/src/TTT/TTTServiceCollection.cs @@ -11,9 +11,9 @@ namespace TTT; public class TTTServiceCollection : IPluginServiceCollection { public void ConfigureServices(IServiceCollection serviceCollection) { + serviceCollection.AddTTTRoles(); serviceCollection.AddRoundService(); serviceCollection.AddPlayerService(); - serviceCollection.AddTTTRoles(); serviceCollection.AddDetectiveBehavior(); serviceCollection.AddLogsService(); serviceCollection.AddManagerService();