Skip to content

Conversation

@Kamil-Zakiev
Copy link

Hi Kristian!
I have added support for decorating open generic type by decorator func.
This change allows me to initialize component after being resolved by ServiceProvider.
I added test CanDecorateOpenGenericTypeBasedOnInterfaceByDecoratorFunc that may clarify my intensions.

It would be great if this could be added to your library. Thank you!

Copy link
Owner

@khellang khellang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long to respond 😞 I think the change looks pretty good. My only concern is the recent change in logic (introduced in #76) and reusing code between the different paths. See comment below.

return arguments.Aggregate(true, (result, args) => result && TryDecorate(args));
}

private static bool TryDecorateOpenGeneric(this IServiceCollection services, Type serviceType, Func<object, IServiceProvider, object> decorator)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I'm not a big fan of the duplication here. I just merge #76, which made a change to the argument filter below:

- .Where(descriptor => descriptor.ServiceType.IsAssignableTo(serviceType))
+ .Where(descriptor => IsSameGenericType(descriptor.ServiceType, serviceType))

Ideally, this should be changed here as well. Are you able to find a way to share more of this code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed duplication by refining existed TryDecorateOpenGeneric method.
Take a look, please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored my implementation, simplified TryDecorateOpenGeneric.
Should look good now.

P.S. locally I have successful build, but AppVeyor fails with "unable to access 'https://github.com/khellang/Scrutor.git/': Could not resolve host: github.com"

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.

2 participants