-
-
Notifications
You must be signed in to change notification settings - Fork 835
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Open generic scanning extensions #1246
Open generic scanning extensions #1246
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1246 +/- ##
===========================================
+ Coverage 76.14% 76.34% +0.19%
===========================================
Files 185 185
Lines 4821 4870 +49
Branches 994 1004 +10
===========================================
+ Hits 3671 3718 +47
- Misses 676 679 +3
+ Partials 474 473 -1
Continue to review full report at Codecov.
|
What is the motivation behind the name AsOpenTypesOf? Are you able to elaborate on it's purpose? What is an open type of an already open generic? Regarding 'AssignableTo', are you simply saying that it's not possible because one generic type is not assignable to another? I think in terms of the strict implementation of the runtime's |
Unrelated; @alsami, did we stabilise the code coverage metrics already? There's a big drop in this PR for what isn't really a huge quantity of code. |
No, still have to look into it. Will do so soon. Really don't know why it does it again, maybe we will need to downgrade to the pre-release again. Will figure it out. |
Hi @alistairjevans
|
@RaymondHuy, I think it's just the name that of the method that may need a rethink. // RedoOpenGenericCommand<T> is an open type of ICommand<T>
public class RedoOpenGenericCommand<T> : ICommand<T> {}
var cb = new ContainerBuilder();
cb.RegisterAssemblyOpenGenericTypes(typeof(ICommand<>).GetTypeInfo().Assembly)
.AsOpenTypesOf(typeof(ICommand<int>));
var c = cb.Build(); I just feel like the user expectation of the name Haven't you kind of implicitly created an open generic |
@alistairjevans yah, maybe somehow I have self implemented the |
Yeah, if you call |
@alistairjevans Yes, currently we can't use the method |
Good stuff; did you want to rename your |
Thanks @alistairjevans I've updated my PR. |
Thanks @RaymondHuy; can I suggest we add some tests for passing invalid types into |
Hi @alistairjevans I've add testcases to my PR for passing closed types and also resolving services which are not assignable to the target open generic type. Can you check if it is satisfied ? feel free to suggest more testcases 😃 |
{ | ||
var cb = new ContainerBuilder(); | ||
cb.RegisterAssemblyOpenGenericTypes(typeof(ICommand<>).GetTypeInfo().Assembly) | ||
.AssignableTo(closedType); |
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.
It feels like passing a closed type into AssignableTo
for Open Generics is enough of an input mistake that we should throw an ArgumentException
if someone tries it?
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.
@alistairjevans when using AssignableTo
in registering assembly closed type, it doesn't throw exception when the argument is open generic type. Therefore should we keep this behavior in this case or we will modify it too ?
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.
Ah, good point. We should retain the same behaviour for consistency, and I don't think it's worth a breaking change in the existing AssignableTo
.
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.
Good to go! Thanks @RaymondHuy for all the work!
Thanks @alistairjevans, btw I wonder there are any plans for adding SourceGenerator to Autofac ? I can spend times on the implementation if we can finalize the design or something like that. |
I've given it a little thought before when implementing pipelines, but didn't get too far with it (#1096 (comment)). The problem we have is the extremely dynamic nature of Autofac's registration system, that allows components to late-resolve objects using I'm still open to using it though if we can find a good way; if you want to raise an issue to discuss design that would be just fine. |
Add remaining methods as discussed in #1232.
Some notes:
AsClosedTypesOf
is renamed toAsOpenTypesOf
AssignableTo
because https://stackoverflow.com/questions/5461295/using-isassignablefrom-with-open-generic-types#:~:text=The%20difference%20is%20that%20open,%22assignable%22%20to%20the%20other.