Share via

Where do I put startup work in a Blazor app?

David Thielen 3,191 Reputation points
Jul 30, 2023, 4:01 PM

Hi all;

In my Blazor server app, when it starts up, I want to create any Azure Storage BLOB containers that I expect that don't exist yet. Where is the appropriate place to put code like this?

Is it ok to put it at the end of the Program.cs main() method? And if so, how do I get an instance of the service I need to accomplish this there? Do I call:

app.Services.GetService<IMyService>();

thanks - dave

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,111 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,665 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 72,356 Reputation points
    Jul 30, 2023, 4:25 PM

    In the section where you are adding services, you should create the container and inject the container access.

    if you created a container access wrapper, it could also create in first access. Just inject the connection settings.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.