Pass IServiceProvider to configureBuilder of AddKafkaConsumer and AddKafkaProducer#4327
Conversation
|
The public API modification should be binary backward compatible I followed guidance from https://github.com/dotnet/roslyn/blob/main/docs/Adding%20Optional%20Parameters%20in%20Public%20API.md. |
|
Can you add some unit tests for all new API and functionality? |
@joperezr - thoughts on getting the package validation https://learn.microsoft.com/dotnet/fundamentals/apicompat/package-validation/overview hooked up in the repo now that we have shipped 8.0? |
| static Microsoft.Extensions.Hosting.AspireKafkaConsumerExtensions.AddKeyedKafkaConsumer<TKey, TValue>(this Microsoft.Extensions.Hosting.IHostApplicationBuilder! builder, string! name, System.Action<Aspire.Confluent.Kafka.KafkaConsumerSettings!>? configureSettings = null, System.Action<Confluent.Kafka.ConsumerBuilder<TKey, TValue>!>? configureBuilder = null) -> void | ||
| static Microsoft.Extensions.Hosting.AspireKafkaProducerExtensions.AddKafkaProducer<TKey, TValue>(this Microsoft.Extensions.Hosting.IHostApplicationBuilder! builder, string! connectionName, System.Action<Aspire.Confluent.Kafka.KafkaProducerSettings!>? configureSettings = null, System.Action<Confluent.Kafka.ProducerBuilder<TKey, TValue>!>? configureBuilder = null) -> void | ||
| static Microsoft.Extensions.Hosting.AspireKafkaProducerExtensions.AddKeyedKafkaProducer<TKey, TValue>(this Microsoft.Extensions.Hosting.IHostApplicationBuilder! builder, string! name, System.Action<Aspire.Confluent.Kafka.KafkaProducerSettings!>? configureSettings = null, System.Action<Confluent.Kafka.ProducerBuilder<TKey, TValue>!>? configureBuilder = null) -> void | ||
| static Microsoft.Extensions.Hosting.AspireKafkaConsumerExtensions.AddKafkaConsumer<TKey, TValue>(this Microsoft.Extensions.Hosting.IHostApplicationBuilder! builder, string! connectionName) -> void |
There was a problem hiding this comment.
This is a lot of new APIs (we went from 4 to 24). Are all these needed?
There was a problem hiding this comment.
We previously have 4 APIs with 4 parameters from which 2 were optional. To ensure backwards compatibility I dropped the default values and exposed each combination of the previous APIs. we here fo from 4 to 4 * 4 APIs.
The new overloads replace Action<ProducerBuilder<TKey, TValue>> and Action<ConsumerBuilder<TKey, TValue>> parameters by Action<IServiceProvider, ProducerBuilder<TKey, TValue>> and Action<IServiceProvider, ConsumerBuilder<TKey, TValue>> which add 4 * 2 APIs.
At both side, consumer and producer, the APIs forward all the call to the same internal implementation.
796ddc3 to
0f67a27
Compare
0f67a27 to
e8ec081
Compare
|
@mitchdenny / @eerhardt : PR is updated with latest changed from main :) edit: build is broken stating that some shipped public API no longer exist. I've followed https://github.com/dotnet/roslyn/blob/main/docs/Adding%20Optional%20Parameters%20in%20Public%20API.md but it looks that the analyzer is failing to map the new methods to existing ones. @joperezr may i ask some guidance about how to solve this. |
I resolved this build error by adding the |
Thank you! i did not know that. |
| /// <inheritdoc cref="AddKafkaProducerInternal{TKey, TValue}(IHostApplicationBuilder, string, Action{KafkaProducerSettings}?, Action{IServiceProvider, ProducerBuilder{TKey, TValue}}?, string, string?)"/> | ||
| public static void AddKeyedKafkaProducer<TKey, TValue>(this IHostApplicationBuilder builder, string name, Action<ProducerBuilder<TKey, TValue>>? configureBuilder) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(name); | ||
| AddKafkaProducerInternal<TKey, TValue>(builder, $"{DefaultConfigSectionName}:{name}", null, Wrap(configureBuilder), connectionName: name, serviceKey: name); | ||
| } | ||
|
|
||
| /// <inheritdoc cref="AddKafkaProducerInternal{TKey, TValue}(IHostApplicationBuilder, string, Action{KafkaProducerSettings}?, Action{IServiceProvider, ProducerBuilder{TKey, TValue}}?, string, string?)"/> | ||
| public static void AddKeyedKafkaProducer<TKey, TValue>(this IHostApplicationBuilder builder, string name, Action<IServiceProvider, ProducerBuilder<TKey, TValue>>? configureBuilder) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(name); | ||
| AddKafkaProducerInternal<TKey, TValue>(builder, $"{DefaultConfigSectionName}:{name}", null, configureBuilder, connectionName: name, serviceKey: name); | ||
| } | ||
|
|
||
| /// <inheritdoc cref="AddKafkaProducerInternal{TKey, TValue}(IHostApplicationBuilder, string, Action{KafkaProducerSettings}?, Action{IServiceProvider, ProducerBuilder{TKey, TValue}}?, string, string?)"/> |
There was a problem hiding this comment.
You don't want to inhertdoc from AddKafkaProducerInternal. That method doesn't have any xml doc.
There was a problem hiding this comment.
@eerhardt good catch. sorry for that. this is now fixed.
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=716654&view=codecoverage-tab |
|
Looks like we took a dip in code coverage. |
Hum, this PR replace methods with default parameters by methods with all combinations of those parameters. The code coverage was not really meaningful for some parameter combinations. |
…hods to use IServiceProvider in configureBuilder param
Mark the public APIs with default values as removed to make PublicAPI analyzer happy.
059a6f3 to
c368c79
Compare
|
@eerhardt @mitchdenny i updated UT to cover all parameter combinations as it was before that PR. |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
mitchdenny
left a comment
There was a problem hiding this comment.
LGTM. The overload explosion is unfortunate but lessons learned about API design I say ;)
I agree.. I guess this is the drawback of defaulting multiple parameters! |
Resolves #4323
I had to deal with RS0027 and RS0028 and finally moved from optional parameters to explicit parameters overloads as parameter types differ.
sample usage:
Microsoft Reviewers: Open in CodeFlow