ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D
MIT License
2.52k stars 363 forks source link

Unable to Resolve type A while building object with type B (during Integration Test) #549

Closed Gamerios closed 6 years ago

Gamerios commented 6 years ago

Hello,

currently I am evaluating zenject for a new project of my company during reserach phase. But right now I am struggling setting up the bindings / injects.

I try to develop within a Unity Test environment. I attached a SceneContext Script to an Object in the Scene and added an Installer.

Version Unity 2017.1 Tried Zenject from Unity Asset Store and from github nothing changes :(


using System;
using UnityEngine;
using Zenject;

public class GameInstaller : MonoInstaller<GameInstaller>
{
    public override void InstallBindings()
    {
        base.Container.Bind<ICoroutineExecuter>().FromInstance(this.coroutineExecuter);
        base.Container.BindInterfacesAndSelfTo<ElementsGateway>().AsSingle();
    }

    [SerializeField]
        private CoroutineExecuter coroutineExecuter;
}

using System;
using System.Collections;
using UnityEngine;

namespace Executer
{
    public interface ICoroutineExecuter
    {
        Coroutine StartAsync(IEnumerator coroutine);
        void StopAsync(Coroutine coroutine);
    }
}

using System;
using System.Collections;
using Executer;
using UnityEngine;

namespace CExecuter
{
    public class CoroutineExecuter : MonoBehaviour, ICoroutineExecuter
    {

        public Coroutine StartAsync(IEnumerator coroutine)
        {
            return base.StartCoroutine(coroutine);
        }

        public void StopAsync(Coroutine coroutine)
        {
            base.StopCoroutine(coroutine);
        }

    }
}

When let Zenject Verify the Scene: I get the log that the installer executes the binding stuffs Get this:


ZenjectException: Unable to resolve type 'Executer.ICoroutineExecuter' while building object with type 'Executer.Apply.ApplyForces'.

Object graph:
SceneKernel
TickableManager
ApplyForces

Zenject.DiContainer.Resolve (Zenject.InjectContext context) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1010)
Zenject.DiContainer.InjectExplicitInternal (System.Object injectable, System.Type injectableType, Zenject.InjectArgs args) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1443)
Zenject.DiContainer.InjectExplicit (System.Object injectable, System.Type injectableType, Zenject.InjectArgs args) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1381)
UnityEngine.Debug:LogException(Exception)
ModestTree.Log:ErrorException(Exception) (at Assets/Plugins/Zenject/Source/Internal/Log.cs:60)
Zenject.DiContainer:InjectExplicit(Object, Type, InjectArgs) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1385)
Zenject.<GetAllInstancesWithInjectSplit>c__AnonStorey0:<>m__0() (at Assets/Plugins/Zenject/Source/Providers/TransientProvider.cs:72)
Zenject.IProviderExtensions:GetAllInstances(IProvider, InjectContext, List`1) (at Assets/Plugins/Zenject/Source/Providers/IProviderExtensions.cs:34)
Zenject.IProviderExtensions:GetAllInstances(IProvider, InjectContext) (at Assets/Plugins/Zenject/Source/Providers/IProviderExtensions.cs:19)
Zenject.DiContainer:GetDecoratedInstances(IProvider, InjectContext) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1154)
Zenject.DiContainer:SafeGetInstances(ProviderInfo, InjectContext) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1092)
Zenject.DiContainer:ResolveAllInternal(InjectContext, List`1) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:761)
Zenject.DiContainer:ResolveAll(InjectContext) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:726)
Zenject.DiContainer:Resolve(InjectContext) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1002)
Zenject.DiContainer:InjectExplicitInternal(Object, Type, InjectArgs) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1443)
Zenject.DiContainer:InjectExplicit(Object, Type, InjectArgs) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1381)
Zenject.<GetAllInstancesWithInjectSplit>c__AnonStorey0:<>m__0() (at Assets/Plugins/Zenject/Source/Providers/TransientProvider.cs:72)
Zenject.IProviderExtensions:GetAllInstances(IProvider, InjectContext, List`1) (at Assets/Plugins/Zenject/Source/Providers/IProviderExtensions.cs:34)
Zenject.IProviderExtensions:GetAllInstances(IProvider, InjectContext) (at Assets/Plugins/Zenject/Source/Providers/IProviderExtensions.cs:19)
Zenject.DiContainer:GetDecoratedInstances(IProvider, InjectContext) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1154)
Zenject.DiContainer:SafeGetInstances(ProviderInfo, InjectContext) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1092)
Zenject.DiContainer:Resolve(InjectContext) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1017)
Zenject.DiContainer:InjectExplicitInternal(Object, Type, InjectArgs) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1443)
Zenject.DiContainer:InjectExplicit(Object, Type, InjectArgs) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1381)
Zenject.<GetAllInstancesWithInjectSplit>c__AnonStorey0:<>m__0() (at Assets/Plugins/Zenject/Source/Providers/ComponentProviders/AddToGameObjectComponentProviders/AddToGameObjectComponentProviderBase.cs:115)
Zenject.IProviderExtensions:GetAllInstances(IProvider, InjectContext, List`1) (at Assets/Plugins/Zenject/Source/Providers/IProviderExtensions.cs:34)
Zenject.IProviderExtensions:GetAllInstances(IProvider, InjectContext) (at Assets/Plugins/Zenject/Source/Providers/IProviderExtensions.cs:19)
Zenject.DiContainer:GetDecoratedInstances(IProvider, InjectContext) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1154)
Zenject.DiContainer:SafeGetInstances(ProviderInfo, InjectContext) (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:1092)
Zenject.DiContainer:ResolveDependencyRoots() (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:383)
Zenject.DiContainer:ResolveRoots() (at Assets/Plugins/Zenject/Source/Main/DiContainer.cs:325)
Zenject.SceneContext:Resolve() (at Assets/Plugins/Zenject/Source/Install/Contexts/SceneContext.cs:283)
Zenject.SceneContext:Validate() (at Assets/Plugins/Zenject/Source/Install/Contexts/SceneContext.cs:115)
Zenject.Internal.ZenUnityEditorUtil:ValidateCurrentSceneSetup() (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:69)
Zenject.Internal.ZenMenuItems:<ValidateCurrentSceneInternal>m__1() (at Assets/Plugins/Zenject/Source/Editor/ZenMenuItems.cs:274)
Zenject.Internal.ZenUnityEditorUtil:SaveThenRunPreserveSceneSetup(Action) (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:26)
Zenject.Internal.ZenMenuItems:ValidateCurrentSceneInternal() (at Assets/Plugins/Zenject/Source/Editor/ZenMenuItems.cs:271)
Zenject.Internal.ZenMenuItems:ValidateCurrentScene() (at Assets/Plugins/Zenject/Source/Editor/ZenMenuItems.cs:21)

Hope you can help my out it try at this problem many days now and my boss hang me :(

svermeulen commented 6 years ago

Can you reduce it down to a simple example? It's hard to guess what the problem could be without more information. On a basic glance, it seems like it should work since you're binding ICoroutineExecuter in game installer