Zenject
Zenject copied to clipboard
Add method AllInterfacesAndSelf to ConventionSelectTypesBinder
Is your feature request related to a problem? Please describe. Convention Based Binding allows to bind all the interfaces
Container.Bind(x => x.AllInterfaces())
.To(x => x.AllNonAbstractClasses().InNamespace("MyGame.Things"));
This is equivalent to Container.BindInterfacesTo<T>(), but there is not an option to "BindInterfacesAndSelf" in Convention Based Bind So you can bind interfaces, and you can bind classes, but you can not bind both
Describe the solution you'd like A clear and concise description of what you want to happen.
Container.Bind(x => x.AllInterfacesAndSelf())
.To(x => x.AllNonAbstractClasses().InNamespace("MyGame.Things"));
public class ConventionSelectTypesBinder
{
...
public ConventionFilterTypesBinder AllInterfacesAndSelf()
{
_bindInfo.AddTypeFilter(t => t.IsInterface || (t.IsClass && !t.IsAbstract));
return CreateNextBinder();
}
}
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. Right now I am using the following workarround, creating a ConventionBindInfo and resolving its types
ConventionBindInfo bindInfo = new ConventionBindInfo();
bindInfo.AddTypeFilter(t => t.IsInterface || (t.IsClass && !t.IsAbstract));
Container
//.Bind(x => x.AllInterfacesAndSelf())
.Bind(bindInfo.ResolveTypes())
.To(generator)
.AsSingle();
Additional context Add any other context or screenshots about the feature request here.