Defining Entity Storages

In Bloqs, storages are used to persist entities. You can define them either manually by creating an EntityStorage object, or use helper methods for convenience.

Using Helper Methods

You can quickly create common storages using the StandardStorage helpers:

var globalStorage = StandardStorage.GetDefaultGlobalStorage();
var defaultStorage = StandardStorage.GetDefaultEntityStorage();

Defining Storages Manually

You can also define storages manually using EntityStorage. For example, a global storage:

new EntityStorage
{
    Id = IdGen.GetEntityStorageId(GlobalStorageName),
    Name = GlobalStorageName,
    EntityStorageType = EntityStorageType.Global,
}

Tenant-Level Storage

You can create storages that are specific to a tenant, so data is separated per tenant:

new EntityStorage
{
    Id = IdGen.GetEntityStorageId(DefaultStorageName),
    Name = DefaultStorageName,
    EntityStorageType = EntityStorageType.Tenant,
}

Using Fixed GUIDs

To ensure consistent GUIDs across the application, you can generate them from a named string using the GuidGenerator:

var MyFixedGuid = IdGen.Get("something");

This approach is helpful when you need reproducible GUIDs for storages (or any other object).

In our start template, we use an AppConstants class to conveniently store GUIDs and string names.

Last updated