InitStorage
The InitStorageCommand handler allows you to initialize storage-related data. It runs in the API project only and is useful for populating default data, ensuring required tenants exist, or preparing the database for operations.
When to Use
Seed default entities or tenants in the database.
Ensure required reference data exists.
Initialize collections or indexes in storage.
Perform migrations or upgrades when the storage is loaded.
Sample API Implementation
using Bloqs.App.Engine.Commands;
namespace Templates.SampleApp.Api.Commands;
[EntityCommandHandler]
public class InitStorage : ICommandHandler<InitStorageCommand, InitStorageCommandResult>
{
public Task<InitStorageCommandResult> HandleAsync(
InitStorageCommand command,
CancellationToken cancellationToken = default
)
{
Console.WriteLine($"{AppConstants.App.Name} [API]: Initializing storage...");
// Example: init some data in the database
return Task.FromResult(InitStorageCommandResult.CreateSuccess());
}
}Notes
Runs only in the API when the storage is loaded.
Ideal for initializing database content, tenants, or default entities.
Exceptions here prevent storage from being fully loaded.
Last updated