Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivatorUtilities.CreateFactory created breaking change from version 4.2.2 to 5.0.1 #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mesies
Copy link

@mesies mesies commented Nov 20, 2024

This PR was created to solve #235, on the premise that upgrade from 4.2.2 to 5.0.1 should have no breaking changes,

The reason for the issue is that for example Decorator3 does not request IDecoratedService but requests a concrete class that implements IDecoratedService.
This behavior is supported by ActivatorUtilities.CreateInstance since it uses the IServiceProvider to inject constructor arguments,
but ActivatorUtilities.CreateFactory expects the contructor to have IDecoratedService, which is not the case in this example.

public class Decorated : IDecoratedService
{
        public Decorated(IService injectedService = null)
        {
            InjectedService = injectedService;
        }

        public IService InjectedService { get; }
}

public class Decorator3 : IDecoratedService
{
        public Decorator3(Decorated inner)
        {
            Inner = inner ?? throw new ArgumentNullException(nameof(inner));
        }

        public Decorated Inner { get; }
}

Thanks for all the hard work!
Let me know what you think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant