-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"
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!