TackleMcClean 🏅
03/11/2025, 10:18 AMbuilder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers()
.Build();
Let's say I want to conditionally add Azure blob storage, how would I do this?
This won't work:
if (shouldUseBlobStorage)
{
builder.AddAzureBlobMediaFileSystem()
.AddAzureBlobImageSharpCache();
}
since 'WebApplicationBuilder' does not contain a definition for 'AddAzureBlobMediaFileSystem'.
Should I hold off with calling Build()
until everything conditional has been sorted, and store the umbracoBuilder?
var umbracoBuilder = builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers();
// do conditional stuff
umbracoBuilder.Build();
?
What then happens with my previous builder
variable? Magic methods like Build()
in ASP.NET confuse me 😕Matt Wise
03/11/2025, 10:20 AMTackleMcClean 🏅
03/11/2025, 10:23 AMUmbraco.StorageProviders.AzureBlob
package?
Or do you mean:
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers()
// add conditional statement mid-chain here somehow
.Build();
?TackleMcClean 🏅
03/11/2025, 10:25 AMMatt Wise
03/11/2025, 10:28 AMTackleMcClean 🏅
03/11/2025, 10:29 AMvar umbracoBuilder = builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers();
var blobConnectionString = builder.Configuration["Umbraco:Storage:AzureBlob:Media:ConnectionString"];
var blobContainer = builder.Configuration["Umbraco:Storage:AzureBlob:Media:ContainerName"];
if (!string.IsNullOrEmpty(blobConnectionString) && !string.IsNullOrEmpty(blobContainer))
{
umbracoBuilder.AddAzureBlobMediaFileSystem().AddAzureBlobImageSharpCache();
}
umbracoBuilder.Build();
WebApplication app = builder.Build();
await app.BootUmbracoAsync();
But composer looks betterMatt Wise
03/11/2025, 10:30 AMSebastiaan
03/11/2025, 10:38 AMMike Chambers
03/11/2025, 3:35 PMprivate readonly IOptionsMonitor<AzureBlobFileSystemOptions> _optionsMonitor;
for the appsettings discoveryMike Chambers
03/11/2025, 3:58 PMkdx-perbol
03/12/2025, 7:48 AMProgram.cs
to make it easy to find. A composer in a separate project would at least need a comment in Program.cs
to let people know the builder is being amended elsewhence.
Sometimes we use just `if`s and sometimes preprocessor directives. But yeah, "keeping Program.cs
untouched from the template" would also be useful.
Also, questions about code readability, discoverability, understandability, maintainability, upgradability etc are never
> a beginner C# question
. 🙂