Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Haakon Langaas Lageng
    @HaakonL
    For the record, this is my Scene Context
    public class GameInstaller : MonoInstaller { public override void InstallBindings() { } }
    Haakon Langaas Lageng
    @HaakonL
    public class StartScreen : MonoBehaviour
    {
        private GameManager _manager;
    
        // THIS DOES NOT WORK
        public StartScreen(GameManager manager)
        {
            _manager = manager;
        }
    
        // THIS WORKS
        [Inject]
        public void Construct(GameManager manager)
        {
            _manager = manager;
        }
    }
    I'd expect constructor injection to work, but it doesn't. Adding an extra method with the Inject attribute is a workaround, but I'd like to readonly the implementations, just like I do when I work in dotnet core or other c# projects.
    Lavagrados
    @Lavagrados_gitlab
    You should not use constructor with MonoBehaviour, so I think Construct method is fine
    Haakon Langaas Lageng
    @HaakonL
    Ok, got it!
    Thanks.
    Jonathon T
    @zeiphon
    Hmm, so calling container.Inject(myMonoBehaviour); should inject into that object as well as any newly instantiated dependencies right?
    Jonathon T
    @zeiphon
    i'm having an issue injecting Zenject.SignalBus into a dependency
    I have:
    A (MonoBehaviour, in hierarchy) --contains property--> B (ScriptableObject) --calls inject() on--> C (MonoBehaviour) --contains injected field--> D (plain class) --contains injected field--> SignalBus
    A, B and C all also have SignalBus injected, successfully. but when it comes to D, zenject is unable to resolve the SignalBus type?
    Chad Wentz
    @CWentzJaneious
    whats the code look like in D?
    Jonathon T
    @zeiphon
    it's a plain class with [Inject]private SignalBus signalBus;or were you interested in the other class code?
    Chad Wentz
    @CWentzJaneious
    and when are you using the signal bus?
    if it is inside of the constructor then that might be the issue
    Jonathon T
    @zeiphon
    oh, no it's just in a method
    Jonathon T
    @zeiphon
    agh i'm an idiot. I'd forgotten that D was being installed in an editor-time installer from quite some time ago. that was the issue
    Sakari Bergen
    @sbergen

    Does anyone know why the FromFactoryBinderBase component binding methods use new List<TypeValuePair>() instead of BindInfo.Arguments e.g. here https://github.com/modesttree/Zenject/blob/master/UnityProject/Assets/Plugins/Zenject/Source/Binding/Binders/Factory/FactoryFromBinderBase.cs#L150?

    This breaks using WithArguments(...) for any factory producing a Component...

    robertverdes
    @robertverdes

    Hi all. I have a MonoInstaller that inherits from another MonoInstaller:

    class BaseItemInstaller : MonoInstaller<BaseItemInstaller> {  
      public Item.Args Args ; 
      [Inject] public void Construct(Item.Args args) { Args = args }
    }
    class ItemInstaller : BaseItemInstaller { }

    The ItemInstaller is used as a subcontainer factory for Item:

    Container.BindFactory<Item.Args, Item, Item.Factory>()
      .FromSubContainerResolve()
      .ByNewContextPrefab<ItemInstaller>(itemPrefab);

    My assumption is that calling itemFactory.Create(itemArgs) will inject the Item.Args instance into the subcontainer installer. And it works if using BaseItemInstaller, but if using ItemInstaller, it complains:
    ZenjectException: Assert hit! Could not find match for argument type 'Item.Args' when injecting into sub container installer 'ItemInstaller'

    The documentation states that inject methods are called in the order of Base class to Derived class. This can be useful to avoid the need to forward many dependencies from derived classes to the base class via constructor parameters, while also guaranteeing that the base class inject methods complete first, just like how constructors work.

    But this is not the expected behaviour in this case. Indeed, if I duplicate the Construct method in ItemInstaller, it works, and if I log the order of execution, BaseItemInstaller.Construct is called before ItemInstaller.Construct.

    What am I missing? Thanks

    Haakon Langaas Lageng
    @HaakonL
    Any suggestions how I should set up this correctly?
    Container.BindFactory<ILevelController, LevelController.Factory>().AsSingle();
    
    Container.BindFactory<ILevelController, LevelController.Factory>().AsSingle();
    
    public class LevelController : MonoBehaviour, ILevelController
    {
        public class Factory : PlaceholderFactory<ILevelController>
        {
            // Do stuff
        }
    }

    When I call _levelFactory.Create() I get an error:

    ZenjectException: Assert hit! Expected non-abstract type for given binding but instead found type 'ILevelController'

    Sakari Bergen
    @sbergen
    @robertverdes I think this is related: svermeulen/Extenject#7
    Sakari Bergen
    @sbergen

    @HaakonL See how CustomEnemyFactory is used here: https://github.com/modesttree/Zenject/blob/master/Documentation/Factories.md#custom-factories

    PlaceholderFactory is just a mechanism to provide a "typedef". C# lacks such a global alias mechanism, which could look e.g. like this:
    using global FooFactory = IFactory<int, IFoo>;
    so instead we have to do
    class FooFactory : PlaceholderFactory<int, IFoo> {}

    So where you are going wrong is with having // Do stuff in a PlaceholderFactory. You need to implement a separate factory class for that. Note, however, that you don't have to use PlaceholderFactory, but can opt to just use IFactory instead. All you loose in this case is compile-time validation of changes to arguments. But if you have validation in place, I don't see that as a big issue. This is all covered in the docs, btw :)

    Mathijs Bakker
    @Mathijs-Bakker
    Zenject has been deprecated from the asset store.
    Mathijs Bakker
    @Mathijs-Bakker
    For the latest updates and features to the open source DI framework. You are recommended to use the Extenject fork. And for support, use it’s active Gitter channel.
    Matthew-Underwood
    @Matthew-Underwood
    Hello, I am looking into creating my own dependency injection framework for educational purposes. One thing that stumps me is how is lazy loading performed? I imagine its loaded in during runtime when the lazy dependency is passed into a objects constructor. The practice of how this would work I can figure out. Does it use some event handling when an instances constructor is called?
    Mathijs Bakker
    @Mathijs-Bakker
    Lazy instantiation in DI frameworks is done by using .Net’s System.Lazy<T> class.
    "A System.Lazy<T> allows access to an underlying value through its Value property. That value will only be created when it’s requested for the first time. After that, the Lazy<T> caches the value for as long as the Lazy<T> instance exists."
    Mathijs Bakker
    @Mathijs-Bakker
    @Matthew-Underwood Hope this helps!
    Matthew-Underwood
    @Matthew-Underwood
    @Mathijs-Bakker thanks, I looked into Lazy<T> and i thought it was initially what I wanted. But would'nt solve the problem of accessing a object only when its needed (property getter, method call etc). Turns out what I actually needed was the Proxy object pattern https://en.wikipedia.org/wiki/Proxy_pattern. But I want to keep it simple for now.
    Alberto GR
    @reverso13_twitter
    hey guys! Is there a way to provide a single parameter every time a class is injected?
    So for example:
    public Player(IClient client, string uuid)
    where IClient will always be injected the same way, but uuid needs to be unique and hardcoded for every instance it is created
    first I bind IClient:
    Container.Bind<IClient>().To<Client>().AsSingle();
    Alberto GR
    @reverso13_twitter
    but is there a way to inject that unique uuid parameter?
    maybe using Identifiers somehow?
    Extrys
    @Extrys
    Hello, is there any way to bind concrete signal types to Interfaaces so i Fire the concrete Signal and i subscribe to the interface?
    Extrys
    @Extrys
    ok i had to implement that feature to the framework
    MnogoZnaet
    @MnogoZnaet
    Hi everyone, I have 300 different npc models and PlayerControl facade class wich use this model depend on NPC type
    the question is how to organise PlayerControl pool to get Spawn PlayerControl with necessary NPC model
    Alireza Tarahomi
    @ATHellboy
    Hey guys,
    I have a custom Editor class (public class Test : Editor). I want to inject some components in this script. How can I do injection in editor time ?
    If it is how I can inject it ?
    marekhanzlik
    @marekhanzlik
    image.png
    Hello all, i've started experimenting with zenject but i've already hit a weird problem, does this look normal to you?
    SceneContext.Awake takes 10s on app load (android device) - bindings are prebaked
    marekhanzlik
    @marekhanzlik
    I've added ZEN_INTERNAL_PROFILING debug symbol and my user code (installers) are taking around 2 sec( which is ok cause i have a fake network transaction there )
    but 4 seconds on GetInjectableMonoBehaviours? and 4 seconds on ProjectContext.InstantiateAndInitialize .. is it normal?
    Nikolay Kandalintsev
    @nikolayinnerspace
    Hello everyone could someone help me to understand how to Lookup container for specific instance after i binded the list like this Container.Bind<MyType>().FromComponentsInChildren().AsSingle();
    as I understand it bind the List<MyType> to the container. and what I need is also iterate over MyType entries and add them to the container with specific id.
    something like this
    Container.Bind<HandController>().FromComponentsInChildren().AsSingle();
    Container.Bind<HandController>().WithId(HandType.Left).FromMethod(() =>
                Container.ResolveAll<HandController>().Where(hand=> hand.HandType == HandType.Left).FirstOrDefault());
    Container.Bind<HandController>().WithId(HandType.Right).FromMethod(() =>
                Container.ResolveAll<HandController>().Where(hand=> hand.HandType == HandType.Right).FirstOrDefault());
    AndreyKh-GP
    @AndreyKh-GP
    Hi. My question is how do I bind a prefab factory with sub-container? Documentation says that binding syntax for prefab factory should be like this Container.BindFactory<UnityEngine.Object, Foo, Foo.Factory>().FromFactory<FooFactory>();
    or
    Container.BindFactory<UnityEngine.Object, Foo, Foo.Factory>().FromFactory<PrefabFactory<Foo>>();
    But how do I use FromSubContainerResolve in this case? I want to have a factory that would spawn objects based on prefab I pass to it at run time and be able to resolve dependencies of that spawned object in it's subcontainer.
    LuisMerinoP
    @LuisMerinoP
    Hi there! I have a factory to dynamically create my prefab from "myClass" attached. If the dependencies of "myClass" are not resolved, the Create() method of the factory crashes. I want to know if there is away to create an object with factories, but that if the dependencies are not resolved, to ommit that and instantiate the object and have "myClass" with mi dependencies null in my code. thanks!