InitApp

The InitAppCommand handler allows you to run custom code when the app starts. This is executed once when your app is initialized and is useful for setting up in-memory data, default values, or performing other startup tasks.

When to Use

  • Initialize default settings, configuration, or cache.

  • Log or audit app startup events.

  • Register services or perform other app-wide initialization logic.

Sample API / UI Implementation

using Bloqs.App.Engine.Commands;

namespace Templates.SampleApp.Api.Commands;

[EntityCommandHandler]
public class InitApp : ICommandHandler<InitAppCommand, InitAppCommandResult>
{
    public Task<InitAppCommandResult> HandleAsync(
        InitAppCommand command,
        CancellationToken cancellationToken = default
    )
    {
        Console.WriteLine($"{AppConstants.App.Name}: Initializing app...");

        // Example: add some startup logic

        return Task.FromResult(InitAppCommandResult.CreateSuccess());
    }
}

Notes

  • Runs once when the app starts.

  • Can be implemented in UI, API, or both, depending on your needs.

  • Exceptions thrown here can prevent the app from fully initializing.

Last updated