Skip to content

Commit f4771d1

Browse files
ZeegaanCopilotkjac
authored andcommitted
Delivery API: Only add default strategy if delivery API is not registered. (#20982)
* Only add if not already present * Update src/Umbraco.Cms.Api.Management/DependencyInjection/WebhooksBuilderExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Kenn Jacobsen <kja@umbraco.dk>
1 parent 4b3ce53 commit f4771d1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Umbraco.Cms.Api.Management/DependencyInjection/WebhooksBuilderExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Extensions.DependencyInjection;
1+
using Microsoft.Extensions.DependencyInjection.Extensions;
22
using Umbraco.Cms.Api.Common.Accessors;
33
using Umbraco.Cms.Api.Common.Rendering;
44
using Umbraco.Cms.Api.Management.Factories;
@@ -16,9 +16,10 @@ internal static IUmbracoBuilder AddWebhooks(this IUmbracoBuilder builder)
1616
builder.Services.AddUnique<IWebhookPresentationFactory, WebhookPresentationFactory>();
1717
builder.AddMapDefinition<WebhookEventMapDefinition>();
1818

19-
// deliveryApi will overwrite these more basic ones.
20-
builder.Services.AddScoped<IOutputExpansionStrategy, ElementOnlyOutputExpansionStrategy>();
21-
builder.Services.AddSingleton<IOutputExpansionStrategyAccessor, RequestContextOutputExpansionStrategyAccessor>();
19+
// We have to use TryAdd here, as if they are registered by the delivery API, we don't want to register them
20+
// Delivery API will also overwrite these IF it is enabled.
21+
builder.Services.TryAddScoped<IOutputExpansionStrategy, ElementOnlyOutputExpansionStrategy>();
22+
builder.Services.TryAddSingleton<IOutputExpansionStrategyAccessor, RequestContextOutputExpansionStrategyAccessor>();
2223

2324
return builder;
2425
}

0 commit comments

Comments
 (0)