Application State Provider
An Application State Provider is the access path to the Application State.
It supplies the facts a capability reads, and records the facts a capability produces.
It is a Provider with one difference from the others. It does not reach an external resource. It reaches the domain's own state.
Inside the Domain
An external Provider reaches a resource the domain does not own, and sits outside the domain.
An Application State Provider reaches the Application State, which the domain owns. It sits inside the domain.
What It Does
It performs two operations for a capability.
It reads: it loads the facts the decision needs into the context.
It writes: it records the consequences of an accepted outcome.
It does not decide. The decision is the Functional Core of the Request Processing Unit. The Application State Provider gives the shell its facts and takes its results.
It Holds the Storage Technology
The Application State Provider is where the storage lives.
Behind it can be an event store, a relational database, table storage, a document database, or another store.
The capability does not change when the store changes. The request, the context, the decision, and the outcome stay the same. Only the Application State Provider knows the tables, the streams, the queries, or the API of the store.
This is what makes storage a separate decision in practice.
It Enforces Command Context Consistency
Command Context Consistency is carried out here.
The guarded read and the guarded commit are operations of the Application State Provider.
In a relational store: the shared lock on the rows the decision read, and the constraint checked at the write.
In an event store: the context version recorded at the read, and the conditional append at the commit.
The provider performs the check and the commit as one atomic step. A conflict comes back to the shell as a business situation, which the capability maps to a rejection.
Replaceable for Tests
Because a capability reaches the Application State only through this provider, a test can replace it.
The Functional Core is tested with plain values and needs no store. The shell is tested with a real Application State Provider or a replacement, to check that it reads the context, protects it, and records the result.
Summary
An Application State Provider is:
- the access path to the Application State
- a Provider that reaches the domain's own state, not an external resource
- inside the domain
- the single place the storage technology lives: event store, relational, table, document, or another store
- where Command Context Consistency is performed
- replaceable in tests