ssannandeji/Zenject-2019

Convention based binding should not include anonymouse classes

Opened this issue · 0 comments

A binding like this:

            Container.Bind(x => x.AllInterfaces()
                    .Where(i =>
                        ... some exceptional exclusions
                    )
                )
                .To(x => x.AllNonAbstractClasses().InNamespaces("Assets.Scripts", "Assets.Libraries.PiecEngine"))
                .AsSingle();

In a code base with a method like this:

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static IEnumerable<Position> Neighbours4(Position vector)
        {
            yield return vector + Position.Up;
            yield return vector + Position.Down;
            yield return vector + Position.Left;
            yield return vector + Position.Right;
        }

Can sometimes cause zenject to attempt to instantiate the anonymous class and produce errors like:

ZenjectException: Unable to resolve type 'System.Int32' while building object with type 'Assets.Libraries.PiecEngine.UnityUtilities.PositionUtilities+<Neighbours4>d__9'. 
Object graph:
SceneKernel
DisposableManager
PositionUtilities.<Neighbours4>d__9

Because the generated class implements IDisposable

Zenject should probably automatically skip anonymous classes to avoid this