Zenject is great, but I haven't found a solution that feels right, for instantiating a game object
I have a script, that provides various event hooks for monobehaviour events. Start, PostStart, Update, FixedUpdate, and others, so non-Unity controllers can execute in at certain events. It is based on an interface I named "IEventsController"
My setup before, would have been something like this:
private static IEventsController _Events;
public static IEventsController GetEvents()
{
if (_Events == null)
{
var go = new GameObject("EventsController");
_Events = go.AddComponent<EventsController>();
}
return _Events;
}
I'm trying to figure out if Zenject has a built in solution for this. I could use a factory or a method, but the factory has a whole extra class to manage this when Zenject might already handle it. Using a method to generate this still requires the static reference to check if its been created or not, and it feels wrong for that to sit in the installer script. Also, there is the FromComponent Series of bindings that might have something for this, but nothing I've seen so far.
A sample binding method call I might expect:
Container.BindComponent<IEventsController>()
.To<EventsController>()
.ViaNewGameObject("Events Controller");
- Thanks.