App Declaration

In Bloqs, every application needs a way to declare its app model. This is done by implementing the IAppDeclaration interface. It defines how your application is described and how its pages, entities, storage, and configuration are assembled.

The Interface

using System.Threading.Tasks;

namespace Bloqs.App.Engine.AppModel;

public interface IAppDeclaration
{
    Task<IAppDefinition> BuildAppDefinition(BuildAppDefinitionArgs args);
}

Purpose

  • IAppDeclaration is the contract for declaring your application.

  • It requires you to implement BuildAppDefinition, which is where you set up the app model.

  • The method returns an IAppDefinition, which contains all metadata about your app (pages, entities, menus, storages, etc.).

Key Points

  • Every Bloqs app must have an IAppDeclaration implementation.

  • This is the central place to define your application model.

  • BuildAppDefinition runs when the app is initialized, so it’s the right place to register storages, entities, pages, and access control.

Reloading the App Model

When coding the app model in Visual Studio, C#, the model is cached in the database. After making changes, you need to reload the app model to see the updates in your app.

You can do this using the Modeler menu in your app:

  1. Open the app.

  2. Open the modeler menu.

  3. Go to About.

  4. Click the Reset app model button.

This ensures that your changes in code are applied and reflected in the running application.

Reloading the App Declaration on API Start

To reload your app declaration on every API or Aspire project start — clearing any stored model changes — set the reset argument to true in the Register call in Program.cs:

// reset app model on API start, throw away all model changes in database
await result.AppModelProvider.Register(result.AppName, result.ModelStore, true);

Explanation:

  • The third parameter (true) forces a full reload of the app model from your declarations.

  • Any runtime changes that were made in the database will be discarded.

  • This is useful during development when you want to ensure your model always reflects the latest code declarations.

Warning: Do not use this in production, as it will erase all runtime model changes stored in the database. (unless that's what you want to achieve)

Last updated