This release includes the following changes:
- Added support for circular dependencies in the PostInject method or as fields (just not constructor parameters)
- Fixed issue with identifiers that was occurring when having both [Inject] and [InjectOptional] attributes on a field/constructor parameter. Now requires that only one be set
- Removed BindValue in favour of just using Bind for both reference and value types for simplicity
- Removed GameObjectInstantiator class since it was pretty awkward and confusing. Moved methods directly into IInstantiator/DiContainer. See IInstantiator class.
- Extracted IResolver and IBinder interfaces from DiContainer
These include some breaking changes but
First post on r/Zenject, woot! Let me start off by saying thanks for creating such a great tool, it's really helped me finally start to grasp DI and appreciate what it can bring to a project. I'm having an issue with a Factory. When I use it without any extra parameters, it works fine, but I'm trying to pass a set of attributes to a newly created object and it's throwing the error in the subject line. Here's my code snippets below:
Installer.cs:
---------------
using Zenject;
using UnityEngine;
public class Installer: MonoInstaller
{
public Settings SceneSettings;
public override void InstallBindings()
{
Container.Bi
Hey, I have a specific situation where I have a state machine which I want to be global and scene independent. I want to be able to create new instances of states, states can be scene-dependent (such as a 'combat encounter state') and these scene-dependent states will have dependencies which exist only in that scene (such as 'enemies in the combat encounter'.)
Because I want to create new state objects, I have factories set up for each state class, and contained in a global state factory class which the state machine object has a dependency on. However because this factory class is bound in the start scene, and therefore in a different context than the combat encounter scene, none of the sc
Since a lot of unity systems require you to make static calls to methods like the Input system I wonder what would be a good way to decouple your code from those systems. The obvious and tedious way would be to wrap them inside classes that you can then inject with zenject. I wonder if there is an easier way to do so?
Hello Zenjecters.
My team is trying to perfom some test with Zenject but we find a wall. We use a simple MVC system so to make it symple we have a class *View for every scene.
The problem comes when we want to test the state of the scene when the View class do something into it.
To make it works I just have a scene with a GameObject. This GameObject has a Zenjenct Binding with his Transform also as ID: SomeGameObject.
To keep it simple this is the View.
public class SampleView: IInitializable
{
[Inject] private AEvent _event;
[Inject(Id="SomeGameObject")] private _gameObject;
public void Initialize()
{
_event += SetGameObjectActive;
Hi,
I'v been trying to get my head around Zenject and DI, i have been reading the documentation and its starting to make sense (sort of :) )
I'm working on a simple thing that downloads a model and displays it (assetbundle) Would this be an typical usage for the Factory design pattern?
AsteroidManager has a reference to Asteroid.Factory Asteroid has an factory class
Downloader would download the asteroid assetbundle.
How would i hook those op together (loading objects from bundle, then instantiate object) ... ?
Hello,
I'd like to have a MonoBehaviour dispatch an event and have another MonoBehaviour listen to it. You can't however, Bind MBs in the Composition Root, only with the ZenjectBinding class, or by having them be publicly referenced in the installer. This is problematic as I cannot UnBind that class when a condition is met.
I'm guessing this is meant to enforce use of a facade pattern, but I really don't understand why this cannot be a feature with MBs. But I digress -- what's the simplest approach for accomplishing this, even if binding MonoBehaviours is not an option?
I posted this in the Google Groups as well, not meant to spam, but perhaps to invigorate the sub as I'm starting to swit
Hi,
I just started using Zenject with Unity.
I'm using an Entity Component System design pattern and thus I do have an Enemy Prefab, holding components like Health or Inventory, but I don't really need a class called Enemy as it is just another entity holding components.
(A) In order to spawn it, I think I need to do something like this:
Container.BindFactory<Enemy, Enemy.Factory>().FromPrefab(enemyPrefab);
Is there any way to avoid having a "base class" for every prefab to be able to spawn it?
(B) I don't always want to spawn things from some game logic, but have initial entities put into the world from the editor.
My Entity class has some code like this:
Hello, I'm new to DI Container, so there's still something I couldn't understand.
Here's a little fighting game.
public class Game : ITickable, IInitializable
{
public Game( [InjectOptional( "Player_1P" )]Character player_1P,
[InjectOptional( "Player_2P" )]Character player_2P)
{ }
}
======================================== public class Character { public Character( CharacterView view ) { } }
public class CharacterView : Monobehaviear
{
}
======================================== public class PlayerController : ITickable { publi
So I have a scene that contains just my player, and a scene per terrain (so I can load and unload different scene setups without having to unload the player). In the terrain scenes, I just find the player through code, because I know the player scene will always be loaded. so my question is how do I let the player's script referance an object in another scene?
I mean, some times is more easy for artist to create an GameObject in the scene (instead of a prefab), and then I use Instantiate with this object to create cloned instances.
Or, is there a best practice than use factories to create a new instance from a GameObject in the scene?
NUnit namespace could not be found by Unity (but could be found by Visual Studio) in the SceneTestFixture.cs and few others scripts in the same directory.
And these items could not be found too:
- SetUpAttribute
- SetUp
- TearDownAttribute
- NUnit
Does it Zenject error or mine?
How can I fix it?
I have factory which spawns Sub-Container using MonoBehaviour based Player but this leads to errors with initialization order, and null refs from other (non MonoBehaviour) classes using that Player when their Initialize() happen. I don't know how to spawn such thing without class inherited from MonoBehaviour because Zenject expects that such MonoBehaviour is placed inside ZenjectBinding component so can be Injected later. I still want to bind new things inside that newly created Sub-Container so GameObjectContext is probably way to go.
Making it short https://github.com/modesttree/Zenject/blob/master/Documentation/SubContainers.md#hello-world-for-facades -> Creating Sub-Containers on Ga