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

Resolve #11: Use Func<X, Y> to handle methods with parameters. #12

Merged
merged 3 commits into from
Jan 15, 2022

Conversation

tillig
Copy link
Member

@tillig tillig commented Jan 14, 2022

Added the test for #11 and, for the case of methods with generic parameters, switched the ResolvingInterceptor to dynamically create a Func<X, Y> delegate type based on the parameter types and return type for the method, then use that resolved factory for the method backing.

The biggest challenge around generic parameters is that, while you might have OpenGenericImpl<string> as a parameter, someone could also do public class MyClosed : OpenGenericImpl<string> and pass one of those as the parameter, so you get into type casting and compatibility challenges... which we've already solved in core Autofac. Hence the desire to reuse that logic and not mirror it here.

I didn't add caching for the Func<X, Y> type signature; we'd need to add method caching and matching logic something similar to the constructor caching and matching in core Autofac which seemed a little overkill here. It does mean for every method invocation (for methods with generic parameters) it's two resolution calls - one to get the factory, one to get the resolved object. Not sure if that's acceptable, but it seemed the simplest way to add support to for open generic methods/parameters.

I did leave the original logic for methods that don't have generic parameters so it's still reasonably optimal.

Generic return types don't appear to have any impact here, so there was no special requirement or change to handle that.

@tillig
Copy link
Member Author

tillig commented Jan 14, 2022

Looks like I'll need to add a test for that exception condition.

@codecov
Copy link

codecov bot commented Jan 14, 2022

Codecov Report

Merging #12 (cf792a5) into develop (870c783) will increase coverage by 0.38%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #12      +/-   ##
===========================================
+ Coverage    97.87%   98.26%   +0.38%     
===========================================
  Files            4        4              
  Lines           94      115      +21     
  Branches        17       18       +1     
===========================================
+ Hits            92      113      +21     
  Misses           1        1              
  Partials         1        1              
Impacted Files Coverage Δ
...ac.Extras.AggregateService/ResolvingInterceptor.cs 97.36% <100.00%> (+1.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 870c783...cf792a5. Read the comment docs.

Copy link
Member

@alistairjevans alistairjevans left a comment

Choose a reason for hiding this comment

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

Looks good, and I agree it's the right choice to delegate the generic parameter logic to Autofac via the Func<> call. The open generic path you've added is not going to be very performant, but this generic argument stuff rarely is.

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