Zenject icon indicating copy to clipboard operation
Zenject copied to clipboard

Add method AllInterfacesAndSelf to ConventionSelectTypesBinder

Open Maesla opened this issue 3 years ago • 0 comments

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.

Maesla avatar Jun 30 '21 06:06 Maesla