Where do I put startup work in a Blazor app?

David Thielen 3,186 Reputation points
2023-07-30T16:01:55.79+00:00

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,067 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,664 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 71,266 Reputation points
    2023-07-30T16:25:51.3566667+00:00

    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.