Skip to content

Cannot Instantiate Object Because Parameterless Constructor is Missing #4

Description

@lawrence-laz

User reported an issue of being unable to create a decorated object instance without parameterless constructor.

Reproduced here:

using Decor;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Xunit;

namespace Reproduce
{
    public class DecorRepro
    {
        public class Dependency { }
        public class Decorator : IDecorator
        {
            public async Task OnInvoke(Call call) => await call.Next();
        }
        public abstract class Base
        {
            protected Base(Dependency featureToggle)
            {
            }
            public abstract Task OnMessage();
        }
        public class Actual : Base
        {
            public Actual(Dependency featureToggle) :base(featureToggle)
            {
            }

            [Decorate(typeof(Decorator))]
            public override async Task OnMessage() => await Task.Delay(1);
        }
        [Theory, AutoMoqData]
        public void aaa(ServiceCollection serviceCollection)
        {
            var provider = serviceCollection
                .AddDecor()
                .AddTransient<Dependency>()
                .AddTransient<Decorator>()
                .AddScoped<Actual>().Decorated()
                .BuildServiceProvider();
            var sut = provider.GetService<Actual>();
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions