ssannandeji / Zenject-2019

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

Feature Request: Add binding id to InjectContext and add InjectIdAttribute #616

Open brzGatsu opened 5 years ago

brzGatsu commented 5 years ago

It would be great if I could do the following so I can avoid unneccessary closures when the id is dynamic:

string id = "Bar";
Container.Bind<Foo>().WithId(id).AsCached().OnInstantiated((context, obj) => ((Foo)obj).Id = context.BindingId))

In this case context.BindingId == "Bar"

An alternative useful thing for this would be an attribute that can be used for parameter injection, i.e. Foo([InjectId] string id). This would also be helpful in the create function of factories,