Vault Lifecycle Hooks
Vault lifecycle hooks have been removed from the framework. The previous interfaces (IBeforeVaultCreate, IOnVaultCreate, IAfterVaultCreate, IBeforeVaultSave, IAfterVaultSave) are no longer available.
What Changed
Altruist now favors explicit initialization over implicit hooks:
- Seeding data — use
[PostConstruct]on a service method to seed data after the database is ready - Validation before save — validate in your service layer before calling vault operations
- Post-save logic — handle it in your service after the save call returns
Seeding Data at Startup
Use a service with [PostConstruct] to seed your database:
[Service]
public class DatabaseSeeder
{
private readonly IVault<AccountModel> _accounts;
public DatabaseSeeder(IVault<AccountModel> accounts)
{
_accounts = accounts;
}
[PostConstruct]
public async Task SeedAsync()
{
var existing = await _accounts.Where(a => a.Username == "admin").FirstOrDefaultAsync();
if (existing == null)
{
await _accounts.SaveAsync(new AccountModel
{
Username = "admin",
PasswordHash = "secure-hash"
});
}
}
}
Note:
For database seeding with ordering control and automatic discovery, consider using Database Initializers instead — they're purpose-built for this use case.
Validation Before Save
Handle validation explicitly in your service:
[Service]
public class PlayerService
{
private readonly IPrefabs _prefabs;
public PlayerService(IPrefabs prefabs)
{
_prefabs = prefabs;
}
public async Task UpdatePlayer(CharacterPrefab prefab)
{
// Validate before saving
if (prefab.Character.Level < 1)
throw new InvalidOperationException("Level must be at least 1");
await prefab.SaveAsync();
// Post-save logic (e.g., notify other systems)
}
}