ssannandeji / Zenject-2019

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

using BindInstance on fields of injected instances fails validation #568

Closed pajama closed 6 years ago

pajama commented 6 years ago
[Inject] Quest _quest;

public override void InstallBindings()
{
    //works
    Container.BindInstance(_quest);
    //works
    Container.BindInstance<QuestId>().FromMethod(() => _quest.Id);

    //does not work
    Container.BindInstance(_quest.Id);
}
svermeulen commented 6 years ago

This is expected, because by default validation does not instantiate any dependencies, including those dependencies that are injected into installers. Typically the way we recommend getting around this is to mark some classes with the [ZenjectAllowDuringValidation] attribute as described here

pajama commented 6 years ago

@svermeulen makes sense. Thanks for clarifying!