You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to use Fx to manage an application that has a behavior tree. Apologies in advance for the length, this is a bit tricky to describe without providing some context. I tried to make this as concise as possible.
The trick with this is that the behaviors are a series on nested components forming sub-trees. At first glance this seems perfect for Dependency Injection, but it doesn't work well, because the trees themselves are responsible for their internal structure. It would be possible to unroll the tree into the DI framework, but this would be like literally describing your business logic in the DI container.
The desire for DI, and thus the challenge is that at each level of the subtree, you are likely to need non behavior tree resources. Say a database, cache, messaging layer, or hardware interface. These would be ideal to inject.
In other frameworks and languages, the solution was usually just to pass the container into the nested factories, and call something like container.instantiate(MyDependency) or container.retrieve(MyDependency).
My understanding of Fx is that fx.Populate() is able to do that, but you can't do that at runtime (for good reason). While I don't want to call Populate at runtime, it would be very handy to have access to it inside factory methods within Provide(), so that it could be passed in.
For example, I currently have code like this that I would like to use DI for (please forgive the pseudo code):
There is no reason for the parent objects to know what the dependencies of the nested objects are, but the parent objects do need to be able to choose which objects to instantiate.
So ideally the above code would be something like:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I would like to use Fx to manage an application that has a behavior tree. Apologies in advance for the length, this is a bit tricky to describe without providing some context. I tried to make this as concise as possible.
The trick with this is that the behaviors are a series on nested components forming sub-trees. At first glance this seems perfect for Dependency Injection, but it doesn't work well, because the trees themselves are responsible for their internal structure. It would be possible to unroll the tree into the DI framework, but this would be like literally describing your business logic in the DI container.
A behavior tree might look like this:
The desire for DI, and thus the challenge is that at each level of the subtree, you are likely to need non behavior tree resources. Say a database, cache, messaging layer, or hardware interface. These would be ideal to inject.
In other frameworks and languages, the solution was usually just to pass the container into the nested factories, and call something like
container.instantiate(MyDependency)
orcontainer.retrieve(MyDependency)
.My understanding of Fx is that
fx.Populate()
is able to do that, but you can't do that at runtime (for good reason). While I don't want to call Populate at runtime, it would be very handy to have access to it inside factory methods within Provide(), so that it could be passed in.For example, I currently have code like this that I would like to use DI for (please forgive the pseudo code):
There is no reason for the parent objects to know what the dependencies of the nested objects are, but the parent objects do need to be able to choose which objects to instantiate.
So ideally the above code would be something like:
I hope my intention is clear - my goal is to only do this at startup, not runtime.
Is this possible with Fx (or Dig directly?)
Beta Was this translation helpful? Give feedback.
All reactions