Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reflex DI Integration #95

Open
Open
Assignees
CristianRos
Labels
enhancementNew feature or request
@CristianRos

Description

@CristianRos

Hi!

I recently discovered UniState and I wanted to give it a shot but it does not have an integration that works out of the box with Reflex DI.
Since you are already supporting VContainer and Zenject, I made my own Reflex integration and I thought it might align with the project needs. It would be nice if we can discuss about this.

In a TL:DR; way, what I've done it's to take VContainer's integration as a guide and port it to work with Reflex code since they both use ContainerBuilder patterns.

You can look at my integration code here:https://gist.github.com/CristianRos/3fbbbb7e87aec00bdf686620ec022084

There are some decisions in there that might not be obvious if you are not already familiar with Reflex like:

  • Reflex implies the Lifetime in the builder functionbuilder.AddTransient() andbuilder.AddSingleton() so I decided to split them intoRegisterStateMachine andRegisterStateMachineAsSingleton. Same withRegisterState implementations.
  • Reflex doesn't have an.AsSelf().AsImplementedInterfaces(); implementation so I made a helper functionGetContractsAndSelf();. If I understood right what that does it's to take all the state associated interfaces and bind them to the actual state and self.
    I actually tried to test it with the Dice game tutorial you posted in the Readme.
Image

This is what shows up in the Reflex debugger. That's all the bindings to each state. I'm not sure that's desired, but hey it works!

  • Reflex doesn't have aRegisterEntryPoint either so I ended up creating a bootstrapper and injecting the EntryPoint:

DiceInstaller

usingReflex.Core;usingUniState;usingUnityEngine;publicclassDiceInstaller:MonoBehaviour,IInstaller{publicvoidInstallBindings(ContainerBuilderbuilder){builder.RegisterStateMachine<IStateMachine,StateMachine>();builder.AddSingleton(container=>{IStateMachinestateMachine=container.Resolve<IStateMachine>();returnnewDiceEntryPoint(stateMachine);},typeof(DiceEntryPoint));builder.RegisterState<StartGameState>();builder.RegisterState<RollDiceState>();builder.RegisterState<LostState>();builder.RegisterState<WinState>();}}

DiceGameBootstrapper

usingReflex.Attributes;usingUnityEngine;publicclassDiceGameBootstrapper:MonoBehaviour{[Inject]readonlyDiceEntryPoint_diceEntryPoint;voidAwake(){_diceEntryPoint.Start();}}

Everything else it's literally a copy pasted version of your tutorial to test everything works alright and I believe it does, at least I do get the Dice game example working.

I also omitted the preprocessor directive#if UNISTATE_REFLEX_SUPPORT as it isn't convenient for my use-case right now and I'm also not familiarized with how to set it up.

Let me know what do you think, I'll be glad to contribute and help!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp