From b7002aebefb4c20591a8c45e692ab58379ef4342 Mon Sep 17 00:00:00 2001 From: Brant Burnett Date: Fri, 6 Mar 2026 08:12:56 -0500 Subject: [PATCH] Disambiguate WithShawarma overloads Motivation ---------- The current overloads of WithShawarma leave ambiguity in overload resolution, in particular if you want to call with no parameters or with only an endpoint name. Modifications ------------- Add overloads and change defaults in a way that is both source and binary backward compatible. Also eliminate a minor heap allocation in the case where `autoStart` is passed as `false` by reusing the shared default options. --- .../ShawarmaResourceBuilderExtensions.cs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Shawarma.Aspire.Hosting/ShawarmaResourceBuilderExtensions.cs b/src/Shawarma.Aspire.Hosting/ShawarmaResourceBuilderExtensions.cs index 71e773f..e76c72c 100644 --- a/src/Shawarma.Aspire.Hosting/ShawarmaResourceBuilderExtensions.cs +++ b/src/Shawarma.Aspire.Hosting/ShawarmaResourceBuilderExtensions.cs @@ -40,17 +40,35 @@ private static Func NamedEndpointSelector(IResourc extension(IResourceBuilder builder) where T : IResourceWithEndpoints { + /// + /// Add commands to enable and disable Shawarma services for the resource. + /// + /// Automatically enable Shawarma services when the resource is ready. + /// The . + public IResourceBuilder WithShawarma(bool autoStart = false) => + builder.WithShawarma(null, autoStart); + + /// + /// Add commands to enable and disable Shawarma services for the resource. + /// + /// Optional configuration for Shawarma. + /// The . + public IResourceBuilder WithShawarma(ShawarmaOptions? options) => + builder.WithShawarma((Func?)null, options); + /// /// Add commands to enable and disable Shawarma services for the resource. /// /// The name of the HTTP endpoint on this resource to send the request to when the command is invoked. /// Automatically enable Shawarma services when the resource is ready. /// The . - public IResourceBuilder WithShawarma([EndpointName] string? endpointName = null, bool autoStart = false) => - builder.WithShawarma(endpointName, new ShawarmaOptions() - { - AutoStart = autoStart - }); + public IResourceBuilder WithShawarma([EndpointName] string? endpointName, bool autoStart = false) => + builder.WithShawarma(endpointName, autoStart + ? new ShawarmaOptions() + { + AutoStart = true + } + : ShawarmaOptions.Default); /// /// Add commands to enable and disable Shawarma services for the resource. @@ -58,7 +76,7 @@ public IResourceBuilder WithShawarma([EndpointName] string? endpointName = nu /// The name of the HTTP endpoint on this resource to send the request to when the command is invoked. /// Optional configuration for Shawarma. /// The . - public IResourceBuilder WithShawarma([EndpointName] string? endpointName = null, ShawarmaOptions? options = null) => + public IResourceBuilder WithShawarma([EndpointName] string? endpointName, ShawarmaOptions? options) => builder.WithShawarma( endpointSelector: endpointName is not null ? NamedEndpointSelector(builder, endpointName)