From f526e61e9c7c651e2421d422d38e5c96c6477908 Mon Sep 17 00:00:00 2001 From: Dzmitry Bazyleu Date: Sat, 4 Apr 2026 17:19:00 +0200 Subject: [PATCH] Fix compatibility issue with Reflex 14.3.0 --- .../Infrastructure/Reflex/DiceInstaller.cs | 28 ++- .../Reflex/ReflexBuildExtensions.cs | 224 +++++++++--------- .../Common/TestFixture/ReflexTestsBase.cs | 5 +- .../BehaviorAttributeReflexTests.cs | 11 +- .../ExecutionTests/ExecutionReflexTests.cs | 13 +- .../PlayMode/GoBackTests/GoBackReflexTests.cs | 11 +- .../GoBackToTests/GoBackToReflexTests.cs | 15 +- .../GoToStateTests/GoToReflexTests.cs | 28 +-- .../HistoryTests/HistorySizeReflexTests.cs | 15 +- .../RecoveryReflexTests.cs | 17 +- .../SubStateTests/SubStateReflexTests.cs | 14 +- Packages/manifest.json | 4 +- Packages/packages-lock.json | 4 +- README.md | 20 +- 14 files changed, 206 insertions(+), 203 deletions(-) diff --git a/Assets/Examples/Infrastructure/Reflex/DiceInstaller.cs b/Assets/Examples/Infrastructure/Reflex/DiceInstaller.cs index 8b69bac..4a7da47 100644 --- a/Assets/Examples/Infrastructure/Reflex/DiceInstaller.cs +++ b/Assets/Examples/Infrastructure/Reflex/DiceInstaller.cs @@ -1,6 +1,7 @@ using Examples.States; using Reflex.Attributes; using Reflex.Core; +using Reflex.Enums; using UniState; using UnityEngine; @@ -13,20 +14,23 @@ public class DiceInstaller : MonoBehaviour, IInstaller public void InstallBindings(ContainerBuilder builder) { - builder.AddStateMachine(typeof(StateMachine), typeof(IStateMachine)); + builder.RegisterStateMachine(typeof(StateMachine), typeof(IStateMachine)); - builder.AddState(typeof(LostState)); - builder.AddState(typeof(RollDiceState)); - builder.AddState(typeof(StartGameState)); - builder.AddState(typeof(WinState)); + builder.RegisterState(typeof(LostState)); + builder.RegisterState(typeof(RollDiceState)); + builder.RegisterState(typeof(StartGameState)); + builder.RegisterState(typeof(WinState)); - builder.AddSingleton(container => - { - DiceEntryPoint entryPoint = new(container.Resolve()); - entryPoint.Start(); + builder.RegisterFactory( + container => + { + DiceEntryPoint entryPoint = new(container.Resolve()); + entryPoint.Start(); - return entryPoint; - }); + return entryPoint; + }, + Lifetime.Singleton, + global::Reflex.Enums.Resolution.Lazy); } } -} \ No newline at end of file +} diff --git a/Assets/UniState/Runtime/Integrations/Reflex/ReflexBuildExtensions.cs b/Assets/UniState/Runtime/Integrations/Reflex/ReflexBuildExtensions.cs index 4cc05b0..a284445 100644 --- a/Assets/UniState/Runtime/Integrations/Reflex/ReflexBuildExtensions.cs +++ b/Assets/UniState/Runtime/Integrations/Reflex/ReflexBuildExtensions.cs @@ -1,77 +1,112 @@ #if UNISTATE_REFLEX_SUPPORT using System; -using System.Collections.Generic; using Reflex.Core; using Reflex.Enums; -using Reflex.Resolvers; -namespace UniState -{ +namespace UniState +{ public static class ReflexBuildExtensions { - public static void AddStateMachine( + public static void RegisterStateMachine( this ContainerBuilder builder, Type stateMachineImplementation, Type stateMachineContract) { - AddStateMachineInternal(builder, stateMachineImplementation, stateMachineContract, Lifetime.Transient); + RegisterStateMachine(builder, stateMachineImplementation, stateMachineContract, Lifetime.Transient); } - - public static void AddSingletonStateMachine( + + public static void RegisterStateMachine( this ContainerBuilder builder, Type stateMachineImplementation, - Type stateMachineContract) + Type stateMachineContract, + Lifetime lifetime) { - AddStateMachineInternal(builder, stateMachineImplementation, stateMachineContract, Lifetime.Singleton); + RegisterStateMachineInternal(builder, stateMachineImplementation, stateMachineContract, lifetime); } - - public static void AddState(this ContainerBuilder builder, Type state) + + public static void RegisterState(this ContainerBuilder builder, Type state) + { + RegisterState(builder, state, Lifetime.Transient); + } + + public static void RegisterState(this ContainerBuilder builder, Type state, Lifetime lifetime) { ValidateStateBindingInput(state); - builder.AddTransient(state, GetStateContracts(state)); + builder.RegisterType(state, GetStateContracts(state), lifetime, Resolution.Lazy); } - - public static void AddState(this ContainerBuilder builder, Type stateImplementation, Type stateContract) - { - ValidateStateBindingInput(stateImplementation, stateContract); - - builder.AddTransient(stateImplementation, stateContract); - } - - public static void AddSingletonState(this ContainerBuilder builder, Type state) + + public static void RegisterState(this ContainerBuilder builder, Type stateImplementation, Type stateContract) { - ValidateStateBindingInput(state); + RegisterState(builder, stateImplementation, stateContract, Lifetime.Transient); + } + + public static void RegisterState( + this ContainerBuilder builder, + Type stateImplementation, + Type stateContract, + Lifetime lifetime) + { + ValidateStateBindingInput(stateImplementation, stateContract); - builder.AddSingleton(state, GetStateContracts(state)); + builder.RegisterType( + stateImplementation, + new[] { stateContract }, + lifetime, + Resolution.Lazy); } - - public static void AddSingletonState(this ContainerBuilder builder, Type stateImplementation, - Type stateContract) - { - ValidateStateBindingInput(stateImplementation, stateContract); - - builder.AddSingleton(stateImplementation, stateContract); - } + + [Obsolete("Use RegisterStateMachine(builder, implementation, contract) or the overload with Lifetime.")] + public static void AddStateMachine( + this ContainerBuilder builder, + Type stateMachineImplementation, + Type stateMachineContract) => + RegisterStateMachine(builder, stateMachineImplementation, stateMachineContract); + + [Obsolete("Use RegisterStateMachine(builder, implementation, contract, Lifetime.Singleton) instead.")] + public static void AddSingletonStateMachine( + this ContainerBuilder builder, + Type stateMachineImplementation, + Type stateMachineContract) => + RegisterStateMachine(builder, stateMachineImplementation, stateMachineContract, Lifetime.Singleton); + + [Obsolete("Use RegisterState(builder, state) or the overload with Lifetime.")] + public static void AddState(this ContainerBuilder builder, Type state) => + RegisterState(builder, state); + + [Obsolete("Use RegisterState(builder, implementation, contract) or the overload with Lifetime.")] + public static void AddState(this ContainerBuilder builder, Type stateImplementation, Type stateContract) => + RegisterState(builder, stateImplementation, stateContract); + + [Obsolete("Use RegisterState(builder, state, Lifetime.Singleton) instead.")] + public static void AddSingletonState(this ContainerBuilder builder, Type state) => + RegisterState(builder, state, Lifetime.Singleton); + + [Obsolete("Use RegisterState(builder, implementation, contract, Lifetime.Singleton) instead.")] + public static void AddSingletonState( + this ContainerBuilder builder, + Type stateImplementation, + Type stateContract) => + RegisterState(builder, stateImplementation, stateContract, Lifetime.Singleton); private static void ValidateStateBindingInput(Type stateImplementation, Type stateContract) { ValidateStateBindingInput(stateImplementation); - if (!stateContract.IsAssignableFrom(stateImplementation)) - { - throw new ArgumentException( - $"AddState({stateImplementation.Name}): Type parameter state must implement {stateContract.Name}."); - } - } + if (!stateContract.IsAssignableFrom(stateImplementation)) + { + throw new ArgumentException( + $"RegisterState({stateImplementation.Name}): Type parameter state must implement {stateContract.Name}."); + } + } private static void ValidateStateBindingInput(Type state) { if (!typeof(IExecutableState).IsAssignableFrom(state)) { throw new ArgumentException( - $"AddState({state.Name}): Type parameter state must implement IState"); + $"RegisterState({state.Name}): Type parameter state must implement IState"); } } @@ -91,93 +126,48 @@ private static Type[] GetStateContracts(Type state) private static void ValidateStateMachineBindingInput(Type stateMachineImplementation, Type stateMachineContract) { - if (stateMachineImplementation == stateMachineContract) - { - throw new ArgumentException( - $"AddStateMachine<{stateMachineImplementation.Name}>: Type parameters must differ : " + - "use AddStateMachine() where stateMachineImplementation implements stateMachineContract.\");"); - } - - if (!stateMachineContract.IsAssignableFrom(stateMachineImplementation)) - { - throw new ArgumentException( - $"AddStateMachine: Type {stateMachineImplementation.Name} " + - $"must implement {stateMachineContract.Name}."); - } - - if (!typeof(IStateMachine).IsAssignableFrom(stateMachineContract)) - { - throw new ArgumentException( - $"AddStateMachine: Type {stateMachineContract.Name} " + - $"must implement IStateMachine."); - } - } - - private static void AddStateMachineInternal( - ContainerBuilder builder, - Type stateMachineImplementation, - Type stateMachineContract, - Lifetime lifetime) - { - ValidateStateMachineBindingInput(stateMachineImplementation, stateMachineContract); - - builder.Bindings.Add(Binding.Validated( - new ReflexStateMachineResolver(stateMachineImplementation, lifetime), - stateMachineImplementation, - stateMachineImplementation, - stateMachineContract)); - } - - private sealed class ReflexStateMachineResolver : IResolver - { - private readonly Type _stateMachineImplementation; - private readonly Lifetime _lifetime; - private readonly List _disposables = new(); - - private object _instance; - - public Lifetime Lifetime => _lifetime; - - public ReflexStateMachineResolver(Type stateMachineImplementation, Lifetime lifetime) + if (stateMachineImplementation == stateMachineContract) { - _stateMachineImplementation = stateMachineImplementation; - _lifetime = lifetime; + throw new ArgumentException( + $"RegisterStateMachine<{stateMachineImplementation.Name}>: Type parameters must differ : " + + "use RegisterStateMachine() where stateMachineImplementation implements stateMachineContract.\");"); } - public object Resolve(Container container) + if (!stateMachineContract.IsAssignableFrom(stateMachineImplementation)) { - if (_lifetime == Lifetime.Singleton && _instance != null) - { - return _instance; - } - - var stateMachine = (IStateMachine)container.Construct(_stateMachineImplementation); - stateMachine.SetResolver(container.ToTypeResolver()); - - if (_lifetime == Lifetime.Singleton) - { - _instance = stateMachine; - } - - if (stateMachine is IDisposable disposable) - { - _disposables.Add(disposable); - } - - return stateMachine; + throw new ArgumentException( + $"RegisterStateMachine: Type {stateMachineImplementation.Name} " + + $"must implement {stateMachineContract.Name}."); } - public void Dispose() + if (!typeof(IStateMachine).IsAssignableFrom(stateMachineContract)) { - for (var i = _disposables.Count - 1; i >= 0; i--) - { - _disposables[i].Dispose(); - } - - _disposables.Clear(); - _instance = null; + throw new ArgumentException( + $"RegisterStateMachine: Type {stateMachineContract.Name} " + + $"must implement IStateMachine."); } } + + private static void RegisterStateMachineInternal( + ContainerBuilder builder, + Type stateMachineImplementation, + Type stateMachineContract, + Lifetime lifetime) + { + ValidateStateMachineBindingInput(stateMachineImplementation, stateMachineContract); + + builder.RegisterFactory( + container => + { + var stateMachine = (IStateMachine)container.Construct(stateMachineImplementation); + stateMachine.SetResolver(container.ToTypeResolver()); + return stateMachine; + }, + stateMachineImplementation, + new[] { stateMachineImplementation, stateMachineContract }, + lifetime, + Resolution.Lazy); + } } } diff --git a/Assets/UniStateTests/Common/TestFixture/ReflexTestsBase.cs b/Assets/UniStateTests/Common/TestFixture/ReflexTestsBase.cs index d63a80d..e71371c 100644 --- a/Assets/UniStateTests/Common/TestFixture/ReflexTestsBase.cs +++ b/Assets/UniStateTests/Common/TestFixture/ReflexTestsBase.cs @@ -1,5 +1,6 @@ using Cysharp.Threading.Tasks; using Reflex.Core; +using Reflex.Enums; using UniState; namespace UniStateTests.Common @@ -37,7 +38,7 @@ await StateMachineTestHelper.RunAndVerify(Container.ToTyp protected virtual void SetupBindings(ContainerBuilder builder) { - builder.AddSingleton(typeof(ExecutionLogger)); + builder.RegisterType(typeof(ExecutionLogger), Lifetime.Singleton, Resolution.Lazy); } } -} \ No newline at end of file +} diff --git a/Assets/UniStateTests/PlayMode/BehaviorAttributeTests/BehaviorAttributeReflexTests.cs b/Assets/UniStateTests/PlayMode/BehaviorAttributeTests/BehaviorAttributeReflexTests.cs index cf1b764..252134c 100644 --- a/Assets/UniStateTests/PlayMode/BehaviorAttributeTests/BehaviorAttributeReflexTests.cs +++ b/Assets/UniStateTests/PlayMode/BehaviorAttributeTests/BehaviorAttributeReflexTests.cs @@ -2,6 +2,7 @@ using Cysharp.Threading.Tasks; using NUnit.Framework; using Reflex.Core; +using Reflex.Enums; using UniState; using UniStateTests.Common; using UniStateTests.PlayMode.StateBehaviorAttributeTests.Infrastructure; @@ -22,11 +23,11 @@ protected override void SetupBindings(ContainerBuilder builder) { base.SetupBindings(builder); - builder.AddStateMachine(typeof(StateMachineBehaviourAttribute), typeof(IVerifiableStateMachine)); - builder.AddState(typeof(FirstState)); - builder.AddState(typeof(NoReturnState)); - builder.AddState(typeof(FastInitializeState)); - builder.AddSingleton(typeof(BehaviourAttributeTestHelper)); + builder.RegisterStateMachine(typeof(StateMachineBehaviourAttribute), typeof(IVerifiableStateMachine)); + builder.RegisterState(typeof(FirstState)); + builder.RegisterState(typeof(NoReturnState)); + builder.RegisterState(typeof(FastInitializeState)); + builder.RegisterType(typeof(BehaviourAttributeTestHelper), Lifetime.Singleton, Resolution.Lazy); } } } diff --git a/Assets/UniStateTests/PlayMode/ExecutionTests/ExecutionReflexTests.cs b/Assets/UniStateTests/PlayMode/ExecutionTests/ExecutionReflexTests.cs index ce0bbac..940317f 100644 --- a/Assets/UniStateTests/PlayMode/ExecutionTests/ExecutionReflexTests.cs +++ b/Assets/UniStateTests/PlayMode/ExecutionTests/ExecutionReflexTests.cs @@ -2,6 +2,7 @@ using Cysharp.Threading.Tasks; using NUnit.Framework; using Reflex.Core; +using Reflex.Enums; using UniState; using UniStateTests.Common; using UniStateTests.PlayMode.Execution.Infrastructure; @@ -38,12 +39,12 @@ protected override void SetupBindings(ContainerBuilder builder) { base.SetupBindings(builder); - builder.AddSingleton(typeof(ExecutionTestHelper)); - builder.AddStateMachine(typeof(ExecutionStateMachine), typeof(IVerifiableStateMachine)); - builder.AddState(typeof(FirstState)); - builder.AddState(typeof(SecondState)); - builder.AddState(typeof(SecondStateWithException)); - builder.AddState(typeof(SecondStateWithWrongDependency)); + builder.RegisterType(typeof(ExecutionTestHelper), Lifetime.Singleton, Resolution.Lazy); + builder.RegisterStateMachine(typeof(ExecutionStateMachine), typeof(IVerifiableStateMachine)); + builder.RegisterState(typeof(FirstState)); + builder.RegisterState(typeof(SecondState)); + builder.RegisterState(typeof(SecondStateWithException)); + builder.RegisterState(typeof(SecondStateWithWrongDependency)); } } } diff --git a/Assets/UniStateTests/PlayMode/GoBackTests/GoBackReflexTests.cs b/Assets/UniStateTests/PlayMode/GoBackTests/GoBackReflexTests.cs index 4e542ae..7aa5046 100644 --- a/Assets/UniStateTests/PlayMode/GoBackTests/GoBackReflexTests.cs +++ b/Assets/UniStateTests/PlayMode/GoBackTests/GoBackReflexTests.cs @@ -2,6 +2,7 @@ using Cysharp.Threading.Tasks; using NUnit.Framework; using Reflex.Core; +using Reflex.Enums; using UniState; using UniStateTests.Common; using UniStateTests.PlayMode.GoBackTests.Infrastructure; @@ -23,11 +24,11 @@ protected override void SetupBindings(ContainerBuilder builder) { base.SetupBindings(builder); - builder.AddSingleton(typeof(GoBackTestHelper)); - builder.AddStateMachine(typeof(StateMachineGoBack), typeof(IVerifiableStateMachine)); - builder.AddState(typeof(StateGoBackFirst)); - builder.AddState(typeof(StateGoBackSecond)); - builder.AddState(typeof(StateGoBackThird)); + builder.RegisterType(typeof(GoBackTestHelper), Lifetime.Singleton, Resolution.Lazy); + builder.RegisterStateMachine(typeof(StateMachineGoBack), typeof(IVerifiableStateMachine)); + builder.RegisterState(typeof(StateGoBackFirst)); + builder.RegisterState(typeof(StateGoBackSecond)); + builder.RegisterState(typeof(StateGoBackThird)); } } } diff --git a/Assets/UniStateTests/PlayMode/GoBackToTests/GoBackToReflexTests.cs b/Assets/UniStateTests/PlayMode/GoBackToTests/GoBackToReflexTests.cs index 44e8eb0..2d4b5b7 100644 --- a/Assets/UniStateTests/PlayMode/GoBackToTests/GoBackToReflexTests.cs +++ b/Assets/UniStateTests/PlayMode/GoBackToTests/GoBackToReflexTests.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using Reflex.Core; +using Reflex.Enums; using UniState; using UniStateTests.Common; using UniStateTests.PlayMode.GoBackToTests.Infrastructure; @@ -17,12 +18,12 @@ protected override void SetupBindings(ContainerBuilder builder) { base.SetupBindings(builder); - builder.AddStateMachine(typeof(GoBackToStateMachine), typeof(IVerifiableStateMachine)); - builder.AddState(typeof(GoBackToState1)); - builder.AddState(typeof(GoBackToState2)); - builder.AddState(typeof(GoBackToState3)); - builder.AddState(typeof(GoBackToState4)); - builder.AddSingleton(typeof(GoBackToTestsHelper)); + builder.RegisterStateMachine(typeof(GoBackToStateMachine), typeof(IVerifiableStateMachine)); + builder.RegisterState(typeof(GoBackToState1)); + builder.RegisterState(typeof(GoBackToState2)); + builder.RegisterState(typeof(GoBackToState3)); + builder.RegisterState(typeof(GoBackToState4)); + builder.RegisterType(typeof(GoBackToTestsHelper), Lifetime.Singleton, Resolution.Lazy); } } -} \ No newline at end of file +} diff --git a/Assets/UniStateTests/PlayMode/GoToStateTests/GoToReflexTests.cs b/Assets/UniStateTests/PlayMode/GoToStateTests/GoToReflexTests.cs index d13d153..7a07e2f 100644 --- a/Assets/UniStateTests/PlayMode/GoToStateTests/GoToReflexTests.cs +++ b/Assets/UniStateTests/PlayMode/GoToStateTests/GoToReflexTests.cs @@ -22,20 +22,20 @@ protected override void SetupBindings(ContainerBuilder builder) { base.SetupBindings(builder); - builder.AddStateMachine(typeof(StateMachineGoToState), typeof(IVerifiableStateMachine)); - builder.AddState(typeof(StateGoTo1)); - builder.AddState(typeof(StateGoTo2)); - builder.AddState(typeof(StateGoTo3)); - builder.AddState(typeof(StateGoTo3), typeof(StateGoToAbstract3)); - builder.AddState(typeof(StateGoTo4)); - builder.AddState(typeof(StateGoTo5)); - builder.AddState(typeof(CompositeStateGoTo6)); - builder.AddState(typeof(SubStateGoTo6First)); - builder.AddState(typeof(SubStateGoTo6Second)); - builder.AddState(typeof(CompositeStateGoTo7)); - builder.AddState(typeof(SubStateGoTo7First)); - builder.AddState(typeof(SubStateGoTo7Second)); - builder.AddState(typeof(StateGoTo8)); + builder.RegisterStateMachine(typeof(StateMachineGoToState), typeof(IVerifiableStateMachine)); + builder.RegisterState(typeof(StateGoTo1)); + builder.RegisterState(typeof(StateGoTo2)); + builder.RegisterState(typeof(StateGoTo3)); + builder.RegisterState(typeof(StateGoTo3), typeof(StateGoToAbstract3)); + builder.RegisterState(typeof(StateGoTo4)); + builder.RegisterState(typeof(StateGoTo5)); + builder.RegisterState(typeof(CompositeStateGoTo6)); + builder.RegisterState(typeof(SubStateGoTo6First)); + builder.RegisterState(typeof(SubStateGoTo6Second)); + builder.RegisterState(typeof(CompositeStateGoTo7)); + builder.RegisterState(typeof(SubStateGoTo7First)); + builder.RegisterState(typeof(SubStateGoTo7Second)); + builder.RegisterState(typeof(StateGoTo8)); } } } diff --git a/Assets/UniStateTests/PlayMode/HistoryTests/HistorySizeReflexTests.cs b/Assets/UniStateTests/PlayMode/HistoryTests/HistorySizeReflexTests.cs index f35df28..2d3c13b 100644 --- a/Assets/UniStateTests/PlayMode/HistoryTests/HistorySizeReflexTests.cs +++ b/Assets/UniStateTests/PlayMode/HistoryTests/HistorySizeReflexTests.cs @@ -2,6 +2,7 @@ using Cysharp.Threading.Tasks; using NUnit.Framework; using Reflex.Core; +using Reflex.Enums; using UniState; using UniStateTests.Common; using UniStateTests.PlayMode.HistoryTests.Infrastructure; @@ -24,13 +25,13 @@ protected override void SetupBindings(ContainerBuilder builder) { base.SetupBindings(builder); - builder.AddSingleton(typeof(HistorySizeTestHelper)); - builder.AddStateMachine(typeof(StateMachineLongHistory), typeof(IStateMachineLongHistory)); - builder.AddStateMachine(typeof(StateMachineZeroHistory), typeof(IStateMachineZeroHistory)); - builder.AddState(typeof(StateInitLongHistory)); - builder.AddState(typeof(StateInitZeroHistory)); - builder.AddState(typeof(StateFooHistory)); - builder.AddState(typeof(StateBarHistory)); + builder.RegisterType(typeof(HistorySizeTestHelper), Lifetime.Singleton, Resolution.Lazy); + builder.RegisterStateMachine(typeof(StateMachineLongHistory), typeof(IStateMachineLongHistory)); + builder.RegisterStateMachine(typeof(StateMachineZeroHistory), typeof(IStateMachineZeroHistory)); + builder.RegisterState(typeof(StateInitLongHistory)); + builder.RegisterState(typeof(StateInitZeroHistory)); + builder.RegisterState(typeof(StateFooHistory)); + builder.RegisterState(typeof(StateBarHistory)); } } } diff --git a/Assets/UniStateTests/PlayMode/RecoveryTransitionTests/RecoveryReflexTests.cs b/Assets/UniStateTests/PlayMode/RecoveryTransitionTests/RecoveryReflexTests.cs index acd22eb..f389a7c 100644 --- a/Assets/UniStateTests/PlayMode/RecoveryTransitionTests/RecoveryReflexTests.cs +++ b/Assets/UniStateTests/PlayMode/RecoveryTransitionTests/RecoveryReflexTests.cs @@ -2,6 +2,7 @@ using Cysharp.Threading.Tasks; using NUnit.Framework; using Reflex.Core; +using Reflex.Enums; using UniState; using UniStateTests.Common; using UniStateTests.PlayMode.RecoveryTransitionTests.Infrastructure; @@ -28,14 +29,14 @@ protected override void SetupBindings(ContainerBuilder builder) { base.SetupBindings(builder); - builder.AddSingleton(typeof(RecoveryTestHelper)); - builder.AddStateMachine(typeof(StateMachineDefaultRecovery), typeof(IStateMachineDefaultRecovery)); - builder.AddStateMachine(typeof(StateMachineGoToStateRecovery), typeof(IStateMachineGoToStateRecovery)); - builder.AddStateMachine(typeof(StateMachineExitRecovery), typeof(IStateMachineExitRecovery)); - builder.AddState(typeof(StateInitial)); - builder.AddState(typeof(StateThrowTwoException)); - builder.AddState(typeof(StateWithFailExecution)); - builder.AddState(typeof(StateStartedAfterException)); + builder.RegisterType(typeof(RecoveryTestHelper), Lifetime.Singleton, Resolution.Lazy); + builder.RegisterStateMachine(typeof(StateMachineDefaultRecovery), typeof(IStateMachineDefaultRecovery)); + builder.RegisterStateMachine(typeof(StateMachineGoToStateRecovery), typeof(IStateMachineGoToStateRecovery)); + builder.RegisterStateMachine(typeof(StateMachineExitRecovery), typeof(IStateMachineExitRecovery)); + builder.RegisterState(typeof(StateInitial)); + builder.RegisterState(typeof(StateThrowTwoException)); + builder.RegisterState(typeof(StateWithFailExecution)); + builder.RegisterState(typeof(StateStartedAfterException)); } } } diff --git a/Assets/UniStateTests/PlayMode/SubStateTests/SubStateReflexTests.cs b/Assets/UniStateTests/PlayMode/SubStateTests/SubStateReflexTests.cs index cafce24..b9eccfe 100644 --- a/Assets/UniStateTests/PlayMode/SubStateTests/SubStateReflexTests.cs +++ b/Assets/UniStateTests/PlayMode/SubStateTests/SubStateReflexTests.cs @@ -20,13 +20,13 @@ protected override void SetupBindings(ContainerBuilder builder) { base.SetupBindings(builder); - builder.AddStateMachine(typeof(StateMachineSubStates), typeof(IVerifiableStateMachine)); - builder.AddState(typeof(StateInitial)); - builder.AddState(typeof(StateFinal)); - builder.AddState(typeof(SubStateInitialFirst)); - builder.AddState(typeof(SubStateInitialSecond)); - builder.AddState(typeof(SubStateFinalFirst)); - builder.AddState(typeof(SubStateFinalSecond)); + builder.RegisterStateMachine(typeof(StateMachineSubStates), typeof(IVerifiableStateMachine)); + builder.RegisterState(typeof(StateInitial)); + builder.RegisterState(typeof(StateFinal)); + builder.RegisterState(typeof(SubStateInitialFirst)); + builder.RegisterState(typeof(SubStateInitialSecond)); + builder.RegisterState(typeof(SubStateFinalFirst)); + builder.RegisterState(typeof(SubStateFinalSecond)); } } } diff --git a/Packages/manifest.json b/Packages/manifest.json index f52360d..1916b27 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,7 +1,7 @@ { "dependencies": { "com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask", - "com.gustavopsantos.reflex": "https://github.com/gustavopsantos/reflex.git?path=/Assets/Reflex/#11.0.0", + "com.gustavopsantos.reflex": "https://github.com/gustavopsantos/reflex.git?path=/Assets/Reflex/#14.3.0", "com.svermeulen.extenject": "https://github.com/Mathijs-Bakker/Extenject.git?path=UnityProject/Assets/Plugins/Zenject/Source", "com.unity.ide.rider": "3.0.36", "com.unity.render-pipelines.universal": "12.1.7", @@ -40,4 +40,4 @@ "com.unity.modules.wind": "1.0.0", "com.unity.modules.xr": "1.0.0" } -} +} \ No newline at end of file diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index eea49ea..1ed66ad 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -8,11 +8,11 @@ "hash": "809d23edae0df58fd0f61b4b6f67855c59d1b2fb" }, "com.gustavopsantos.reflex": { - "version": "https://github.com/gustavopsantos/reflex.git?path=/Assets/Reflex/#11.0.0", + "version": "https://github.com/gustavopsantos/reflex.git?path=/Assets/Reflex/#14.3.0", "depth": 0, "source": "git", "dependencies": {}, - "hash": "224d2a1d1716b26f8eddf2e0d4a5c47d50d7a75c" + "hash": "86569ca217b989a8cec9db1e37f81c44130d23f1" }, "com.svermeulen.extenject": { "version": "https://github.com/Mathijs-Bakker/Extenject.git?path=UnityProject/Assets/Plugins/Zenject/Source", diff --git a/README.md b/README.md index a61328f..8485a97 100644 --- a/README.md +++ b/README.md @@ -1189,31 +1189,33 @@ namespace Examples.Infrastructure.Reflex All state machines, states, and their dependencies should be registered in the DI container using Reflex's `ContainerBuilder`. Special extension methods have been provided for convenient registration. -`AddState(typeof(MyState))` and `AddSingletonState(typeof(MyState))` register the state as itself and as all implemented -interfaces. Use the two-parameter overload when you need to expose an additional abstract/base contract explicitly. +`RegisterState(typeof(MyState))` registers the state as itself and as all implemented interfaces. +Use the overload with `Lifetime.Singleton` when you need a singleton lifetime. +Use the two-parameter overload when you need to expose an additional abstract/base contract explicitly. Here's example code demonstrating the available extension methods: ```csharp using Reflex.Core; +using Reflex.Enums; using UniState; private void RegisterStates(ContainerBuilder builder) { // Recommended usage for general cases - builder.AddStateMachine(typeof(StateMachine), typeof(IStateMachine)); - builder.AddState(typeof(BarState)); - builder.AddState(typeof(BarState), typeof(BarBaseState)); + builder.RegisterStateMachine(typeof(StateMachine), typeof(IStateMachine)); + builder.RegisterState(typeof(BarState)); + builder.RegisterState(typeof(BarState), typeof(BarBaseState)); // Singleton version (use cautiously, not recommended in most cases) - builder.AddSingletonStateMachine(typeof(StateMachine), typeof(IStateMachine)); - builder.AddSingletonState(typeof(BarState)); - builder.AddSingletonState(typeof(BarState), typeof(BarBaseState)); + builder.RegisterStateMachine(typeof(StateMachine), typeof(IStateMachine), Lifetime.Singleton); + builder.RegisterState(typeof(BarState), Lifetime.Singleton); + builder.RegisterState(typeof(BarState), typeof(BarBaseState), Lifetime.Singleton); } ``` ## License -This library is under the MIT License. Full text is [here](LICENSE). \ No newline at end of file +This library is under the MIT License. Full text is [here](LICENSE).