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

Added open generic support for decorator func #81

Open
wants to merge 2 commits into
base: master
from

Conversation

@Kamil-Zakiev
Copy link

@Kamil-Zakiev Kamil-Zakiev commented Feb 12, 2019

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

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.

@@ -261,6 +276,27 @@ bool TryDecorate(Type[] typeArguments)
return arguments.Aggregate(true, (result, args) => result && TryDecorate(args));
}

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

This comment has been minimized.

@khellang

khellang Jun 6, 2019
Owner

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?

This comment has been minimized.

@Kamil-Zakiev

Kamil-Zakiev Jun 6, 2019
Author

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

This comment has been minimized.

@Kamil-Zakiev

Kamil-Zakiev Jun 7, 2019
Author

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"

@Kamil-Zakiev Kamil-Zakiev force-pushed the Kamil-Zakiev:master branch from cc0acdd to 4a04fd9 Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.