UseInMemory
Package Trax.Effect.Data.InMemoryNamespaces Trax.Effect.Data.InMemory.Extensions, Trax.Effect.Data.InMemory.Services.InMemoryContextFactorySource ServiceExtensions.cs, InMemoryContexFactory.cs
The in-memory data provider. Keeps the trax tables in an EF Core in-memory database that lives as long as the
process: nothing to run, nothing kept after the host stops.
Signature
public static TraxEffectBuilderWithData UseInMemory(
this TraxEffectBuilder configurationBuilder
)Returns
TraxEffectBuilderWithData, which carries the methods that need a data provider. See
AddEffects.
Behavior
Each call creates one InMemoryDatabaseRoot, and every context the provider creates, through the factory or the
scoped IDataContext, shares it, so they all see the same data. It sets HasDataProvider but not
HasDatabaseProvider: the scheduler then runs its in-memory set of services and skips the startup work that needs a
database, and no ISqlDialect or IQueuedWorkListener is registered. NUL characters are stored unchanged.
Registered services
| Service | Lifetime | Role |
|---|---|---|
IDataContextProviderFactory | Singleton | An InMemoryContextProviderFactory over the shared root, registered as a non-toggleable effect |
| IDataContext | Scoped | A context over the shared root |
ICheckpointRows | Singleton, if none is registered | The rows checkpoints are stored in |
ITraxFeatureDbConfigurator | Singleton | A DelegateFeatureDbConfigurator that points a feature's own DbContext at the same in-memory store |
InMemoryContextProviderFactory
public class InMemoryContextProviderFactory(InMemoryDatabaseRoot databaseRoot) : IDataContextProviderFactory| Member | Description |
|---|---|
Create() | A new context over databaseRoot |
CreateDbContextAsync(cancellationToken) | The same, as a task |
Transactions are accepted and ignored, as the EF Core in-memory provider does.
Example
services.AddTrax(trax => trax
.AddEffects(effects => effects
.UseInMemory()
)
.AddMediator(typeof(IShipOrderTrain).Assembly)
);