Compze.Teventive.MemoryImageStateStore
0.1.0-alpha
See the version list below for details.
dotnet add package Compze.Teventive.MemoryImageStateStore --version 0.1.0-alpha
NuGet\Install-Package Compze.Teventive.MemoryImageStateStore -Version 0.1.0-alpha
<PackageReference Include="Compze.Teventive.MemoryImageStateStore" Version="0.1.0-alpha" />
<PackageVersion Include="Compze.Teventive.MemoryImageStateStore" Version="0.1.0-alpha" />
<PackageReference Include="Compze.Teventive.MemoryImageStateStore" />
paket add Compze.Teventive.MemoryImageStateStore --version 0.1.0-alpha
#r "nuget: Compze.Teventive.MemoryImageStateStore, 0.1.0-alpha"
#:package Compze.Teventive.MemoryImageStateStore@0.1.0-alpha
#addin nuget:?package=Compze.Teventive.MemoryImageStateStore&version=0.1.0-alpha&prerelease
#tool nuget:?package=Compze.Teventive.MemoryImageStateStore&version=0.1.0-alpha&prerelease
Compze.Teventive.MemoryImageStateStore
The memory image state store: a memory image of Compze taggregates. Every taggregate is held in memory for the container's life, and rebuilt at the store's start from a snapshot of each, which its storage keeps: it keeps taggregates as their state, not their history.
What is Compze?
Compze is a .NET framework for building expressive domains through Teventive programming and Typermedia APIs. Learn more
What's in this package?
- The memory image state store — composed with
MemoryImageStateStore(...), it keeps the taggregate classes declared for it in memory, and in JSON files if they are declared. - JSON files —
StoredInJsonFiles(...): a file for each taggregate, in a folder for each class, written with the consumer'sJsonSerializerOptions, and a unit of work's files written all or none. Compze.Teventive.MemoryImageStateStore.MemoryPack adds a cache to start from, so a start reads only the files changed since.ITaggregateJsonFilesgives the path of each taggregate's file, and the taggregate each file is the file of. For specifications,OnAFileSystemInMemory(), in theTestingnamespace, puts the files on a file system in memory, read and changed throughIFileSystemInMemory, with no disk I/O. - Reloads and rewrites —
IMemoryImageStateStore.LoadFromStorage()loads the files again and reports which taggregates another program added, changed or removed, comparing only the files changed since the store last read or wrote them, so snapshot types need no equality.IMemoryImageStateStore.WriteAllToStorage()writes every file anew, as one commit, after a change to the snapshot types or to the serializer's options. - Units of work with private copies — each unit of work changes its own copy of a taggregate, holding its lock until it completes, and the copy becomes the committed instance when it commits.
- Synchronous dispatch — the tevents a unit of work's taggregates publish are dispatched as each publish cascade ends, once the taggregate's invariants hold, so participation handlers run inside the domain call and the unit of work's transaction.
- Indexes defined by state —
ITaggregateIndex<TTaggregate, TKey>files taggregates under keys their state gives, in no particular order, and reads its own unit of work's changes. A store has one index for each pair of taggregate class and key type, and a key function reads only the taggregate's own state. - Every taggregate of a class —
ITaggregateStoreBulkReader.ReferencesToAll<TTaggregate>(), in no particular order. - What holding everything costs — its memory is the whole data set, and it loads every taggregate at its first use, on that use's thread: call
LoadFromStorage()at the application's start to choose when. A failure after a commit's journal is written stops the process (Environment.FailFast), and the next start finishes the commit. The files are written, not flushed to the disk. Its waits, for a taggregate's lock and between a load and the units of work, give up after 30 seconds.
The interfaces it implements, ITaggregateStoreReader, ITaggregateStoreBulkReader and ITaggregateStoreUpdater, are in Compze.Teventive.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Compze.Abstractions (>= 0.4.0-alpha)
- Compze.Contracts (>= 0.7.2)
- Compze.DependencyInjection (>= 0.10.0-alpha)
- Compze.Internals.SystemCE (>= 0.9.0-internal)
- Compze.Tessaging.Abstractions (>= 0.6.0-alpha)
- Compze.Teventive (>= 0.7.0-alpha)
- Compze.Threading (>= 0.12.0-alpha)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Compze.Teventive.MemoryImageStateStore:
| Package | Downloads |
|---|---|
|
Compze.Teventive.MemoryImageStateStore.MemoryPack
A MemoryPack cache for Compze.Teventive.MemoryImageStateStore's JSON files, so a memory image state store kept in files starts from the cache and reads only the files changed since. |
|
|
Compze.Teventive.MemoryImageStateStore.MySql
The MySQL tables of Compze's memory image state store: MySqlMemoryImageStateStoreSqlLayer(), for a memory image state store kept in the tables of a MySQL domain database, which several memory images, in other processes or other containers, share. |
|
|
Compze.Teventive.MemoryImageStateStore.PostgreSql
The PostgreSQL tables of Compze's memory image state store: PgSqlMemoryImageStateStoreSqlLayer(), for a memory image state store kept in the tables of a PostgreSQL domain database, which several memory images, in other processes or other containers, share. |
|
|
Compze.Teventive.MemoryImageStateStore.MicrosoftSql
The SQL Server tables of Compze's memory image state store: MsSqlMemoryImageStateStoreSqlLayer(), for a memory image state store kept in the tables of a SQL Server domain database, which several memory images, in other processes or other containers, share. |
|
|
Compze.Teventive.MemoryImageStateStore.Sqlite
The SQLite tables of Compze's memory image state store: SqliteMemoryImageStateStoreSqlLayer(), for a memory image state store kept in the tables of a SQLite domain database, which several memory images, in other processes or other containers, share. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.2.0-alpha | 0 | 11/25/2026 |
| 0.1.0-alpha | 80 | 11/19/2026 |
- **The memory image state store, a memory image of taggregates: every taggregate held in memory for the container's life, rebuilt at its start from a snapshot of each, which its storage keeps.** It keeps taggregates as their state, not their history. Composed with `MemoryImageStateStore(...)`, which declares the taggregate classes it keeps, each with a factory for empty instances, its indexes, and its storage.
- Each unit of work gets a private copy of each taggregate it gets for update, and holds the taggregate's lock until it completes.
- The tevents the copies publish are dispatched synchronously as each publish cascade ends, once the taggregate's invariants hold, so participation handlers run inside the unit of work's transaction, and a handler's failure comes out of the domain call.
- A committed taggregate is read only, and read without a lock.
- A taggregate that publishes an `ITaggregateDeletedTevent` is taken out of the store, its indexes and its storage when the unit of work commits. One added and deleted in the same unit of work writes nothing.
- `ITaggregateIndex<TTaggregate, TKey>` files taggregates under keys their state gives, and reads its own unit of work's changes. A lookup gives its references in no particular order, as an `IReadOnlyCollection`: a caller that needs an order sorts what it finds. An index keeps no record of each taggregate's keys: a commit takes a changed taggregate's old keys from its committed instance, so a key function must give keys from the taggregate's own state alone; one that doesn't fails the unit of work, which rolls back. A store has one index for each pair of taggregate class and key type, and a second is refused where it's declared. For a moment during a commit, a lookup outside the unit of work can find a taggregate under a key its new state no longer gives.
- A taggregate class is declared with a factory for its empty instances, `Taggregate(() => new StoredVocab())`, or, when its instances need services of the container, with a registration of the container, with as many dependencies as its constructor takes: `Taggregate(TrackedTransient.For<VocabNote>().CreatedBy((Dictionary dictionary, Readings readings) => new VocabNote(dictionary, readings)))`. The store registers it and resolves each empty instance from the container's root, so the services must be singletons: a registration that takes a scoped service, directly or through a tracked transient it takes, is refused when the container is built, with a message naming the class and the scoped service, the same with every DI container. The registration must be a `TrackedTransient`, and the class not `IDisposable`.
- `IMemoryImageStateStore.LoadFromStorage` loads everything again while running, keeping every reference, and reports which taggregates were added, changed or removed, as collections in no particular order. `LoadFromStorage(changeTheStorageFirst)` first runs a change to the storage, such as a fast-forward of a checkout, while no unit of work is open and new ones wait. A taggregate counts as changed when the state its file holds isn't the state the store held, as the store's serializer and the consumer's options write state, so snapshot types need no equality: a file unchanged since the store last read or wrote it, by its length and last write time, is compared with nothing, and a changed one is compared with what the store would write for the taggregate it held.
- `IMemoryImageStateStore.WriteAllToStorage()` writes every taggregate's file anew, as the store's serializer and the consumer's options write its snapshot now, as one commit through the journal, while no unit of work is open: after a change to the snapshot types or to the serializer's options, so that the files don't stay a mix of the old form and the new.
- `ITaggregateStoreBulkReader.ReferencesToAll<TTaggregate>()` gives a reference to every taggregate of a class the memory image state store keeps, and inside a unit of work reads its own additions and deletions.
- The store loads everything from its storage at its first use, on that use's thread and inside its transaction, if any: `LoadFromStorage()` called at the application's start chooses when. It writes each unit of work in two steps, prepare and commit. Its storage is JSON files, or memory only when none is declared. The storage seam is internal: Compze's JSON store, on the disk or on a file system in memory, covers what a consumer's own storage was for, the files in a consumer's layout and format, and in-memory storage for specifications.
- `StoredInJsonFiles(folder, options, files => files.FolderOf<TTaggregate>(folder))` keeps the store in JSON files: a folder for each class, and a file for each taggregate, `<first two hex digits of the id>/<id>.json` in its class's folder. A file holds exactly what the consumer's `JsonSerializerOptions` make of the snapshot, in UTF-8 without a byte order mark. A unit of work's files are written all or none: each is written whole under a temporary name when the unit of work prepares, and at the commit a journal of the renames and deletions is written before any is made, so a start after a crash finishes the commit or discards it. The store's own files are in `.state-store` under the folder. For a folder that a service of the container knows, `StoredInJsonFiles((CorpusPaths paths) => paths.Corpus, options, files => ...)` resolves the service from the container's root, so it can't be scoped: a scoped one, or one that takes a scoped service, directly or through a tracked transient it takes, is refused when the container is built, with a message naming the scoped service, the same with every DI container.
- **A unit of work that writes the JSON files can't also hold a database connection,** by default. The files and the database commit one after the other, so a crash between the two commits could lose one of the changes. Such a unit of work is refused, and rolls back: for Compze's own connections, such as the tevent store's and the exactly-once outbox's and inbox's, and for any SQL Server connection. A unit of work that only reads the store is never refused, and a container may hold this store and the tevent store. A consumer to whom that loss is acceptable declares `files.AcceptingNonAtomicCommitsWithADatabase()`.
- **What it does when it fails or waits:** a failure after a commit's journal is written, such as a file another program holds for more than about two seconds, stops the process (`Environment.FailFast`), and the next start finishes the commit from its journal. The files are written, not flushed to the disk, so a commit outlives the process, not the machine losing its power. Its waits are fixed at 30 seconds: a get for update's for another unit of work's lock, `LoadFromStorage`'s and `WriteAllToStorage`'s for the open units of work, and a unit of work's for a load again to end; each then throws.
- A store kept in files can start from a cache that a package of its own plugs in, such as Compze.Teventive.MemoryImageStateStore.MemoryPack's `StartingFromAMemoryPackCache()`: it reads only the files that are new, or whose length or last write time changed since the cache was written.
- `ITaggregateJsonFiles`, which the container resolves for a store kept in JSON files, finds the way between the files and the taggregates without knowing the layout: `PathOf<TTaggregate>(id)` gives the full path of a taggregate's file, whether it exists yet or not, `PathOf(taggregate)` gives it for a taggregate in hand, by its class at runtime and its id, for code that holds taggregates of several classes through a type they share, and `TaggregateWhoseFileIs(path)` gives the class and id of the taggregate whose file a full path is, as a `TaggregateOfAFile`, or null for any other path: such as for a view of what version control lists as changed. It reads only the path, so it answers for a deleted file too. Paths are compared ignoring case, as the store compares them.
- For specifications, in the namespace `Compze.Teventive.MemoryImageStateStore.Testing`: `files.OnAFileSystemInMemory()` puts a store's files on a file system in memory instead of on the disk: the store works as on the disk, with the same layout, the consumer's JSON options, the journal and any cache, and touches no file on the disk. A specification reads and changes the files by path through `IFileSystemInMemory`, such as to change a file behind the store before a reload.