ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
336 stars 33 forks source link

Grace.Factory passes invalid argument values to constructor #215

Closed krasin-ga closed 5 years ago

krasin-ga commented 5 years ago

 public class Test
    {
        public Test(ExampleClass.IFactory factory)
        {
            factory.Create(
                startId: 1,
                endId: 2,
                reverse: true,
                loadIdsLimit: 3,
                maxBufferSize: 4,
                cancellationTokenSource: new CancellationTokenSource());
        }
    }

    public class ExampleClass : IAsyncEnumerator<SyncJob>
    {
        public SyncJob Current { get; private set; }

        public ExampleClass(
            long startId,
            long endId,
            bool reverse,
            int loadIdsLimit,
            long maxBufferSize,
            CancellationTokenSource cancellationTokenSource,
            Dependency1 dependency1,
            Dependency2 dependency2)
        {
            Debug.Assert(startId == 1);
            Debug.Assert(endId == 2);
            Debug.Assert(reverse == true);
            Debug.Assert(loadIdsLimit == 3);
            Debug.Assert(maxBufferSize == 4);
            Debug.Assert(cancellationTokenSource != null);
            Debug.Assert(cancellationTokenSource != null);
        }

        public Task<bool> MoveNext(CancellationToken cancellationToken)
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        public interface IFactory
        {
            ExampleClass Create(
                long startId,
                long endId,
                bool reverse,
                int loadIdsLimit,
                long maxBufferSize,
                CancellationTokenSource cancellationTokenSource);
        }
    }

    public class Dependency1
    {
    }

    public class Dependency2
    {
    }
ipjohnson commented 5 years ago

Hi @krasin-ga

I've added the test you specified and it passed in VS as well as the appveyor build. It sounds like maybe the use case is a bit more complex? Is it possible the name of the parameters don't match or the order isn't the same?

krasin-ga commented 5 years ago

My bad. It turned out that the bug is reproduced only when creating a proxy type and registering it as a decorator.

          var proxyType = new DefaultProxyBuilder().CreateClassProxyType(
                typeof(ExampleClass),
                new Type[0],
                ProxyGenerationOptions.Default);

            registrationBlock.ExportDecorator(proxyType)
                 .As(typeof(ExampleClass))
                 .WithCtorParam<IExportLocatorScope, IInterceptor[]>(
                     scope => Array.Empty<IInterceptor>());
ipjohnson commented 5 years ago

Hi @krasin-ga

I tried adding that to the test and it still passes. Can you create a small working sample as a repo or maybe a gist?

krasin-ga commented 5 years ago

My bad! 😃 The bug is reproduced only in the old version of Castle.Core (4.2.1), in version 4.4.0 everything is fine.

ipjohnson commented 5 years ago

That would explain that, I'm using castle version 4.3.1 in my tests so I wouldn't have seen it.