-
-
Notifications
You must be signed in to change notification settings - Fork 835
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
Add support for OnlyIf and IfNotRegistered on module registration #1272
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1272 +/- ##
===========================================
+ Coverage 76.42% 76.53% +0.11%
===========================================
Files 187 188 +1
Lines 5085 5123 +38
Branches 1034 1041 +7
===========================================
+ Hits 3886 3921 +35
- Misses 706 707 +1
- Partials 493 495 +2
Continue to review full report at Codecov.
|
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.
I think this is pretty slick, though I made a note where the actual logic was somewhat confusing for a moment.
I think the "breaking" IModuleRegistrar
change is fine. Honestly, if you've implemented IModuleRegistrar
on your own, God have mercy on your soul.
/// The <see cref="ContainerBuilder"/> into which registrations will be made. | ||
/// </summary> | ||
private readonly ContainerBuilder _builder; | ||
private Action<IComponentRegistryBuilder>? _nextModuleCallback; |
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 took me a bit to figure out that this is effectively the call to module.Configure
for all modules registered via this registrar. The RegistrationData
allows wrapping of that chain with predicates, but RegisterModule
needs the ability to add modules inside that wrapper.
I wonder if a more descriptive name like _moduleConfigureChain
or something might help? I'm not glued to that as the name, but it did take me a few reads through here to go, "OOOHHH, it's predicates wrapped around this callback, and this callback gets sort of lazy-initialized via closure." Like two levels of callbacks, not just one "pipeline." I think _nextModule
threw me off because I was expecting one pipeline, like ASP.NET Core _next
and my poor zombie brain didn't connect that it's sorta two levels going on here.
I also had a big block of //
comments written but was like... maybe it's just me and a more descriptive name would be enough.
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.
The word 'next' does imply pipeline, you're right (in Autofac as well, never mind ASP.NET Core). Will re-word and add some comments.
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.
🖲️
This PR is a partial fix for #1235, by adding OnlyIf support for Module Registrations.
This change is technically breaking, through the addition of a new
RegistrarData
property onIModuleRegistrar
, however if someone has implemented a customIModuleRegistrar
, I will be quite surprised.This change allows you to do this:
or this:
You can stack
OnlyIf
calls in the same way you can do it on normal registrations:The way I've laid out the evaluation of the conditions and the module registrations is as follows (after some thought):
This means that any
OnlyIf
statements used against a singleIModuleRegistrar
instance will be applied to the state of the registry before any modules got registered.This behaviour seemed like the most predicatable/logical, rather than (for example), evaluating the predicate per-module.