Replies: 1 comment 3 replies
-
Why would you have a null configuration delegate? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
Not sure entirely how to approach this, thus I'm making this a discussion first before making a proper API proposal.
Consider the following scenario:
This shows a common situation, where one might want to accept a delegate for configuring options, but then they encounter an issue with
Configure(Action<TOptions>)
not accepting nullable. If the warning is ignored andconfigure
is null, an exception is thrown.Currently, there are four work-arounds:
Configure()
with an if check.configure ??= _ => { };
This continues to add an instanceConfigureNamedOptions()
to the container with an empty body, which is not ideal.Configure()
.I personally went with option 4, naming it
ConfigureOptional()
, but I feel like this should be something native to the library.Please do provide feedback. I'm sure there's stuff I've missed here that would provide either a better solution to this or justification for not accepting null in the first place.
I'm also curious what you guys may propose or an API surface for this.
Beta Was this translation helpful? Give feedback.
All reactions