Reference for the original Orleans.FSharp authoring APIs kept for existing applications.
This page is deliberately outside the current API reference. The APIs below remain runnable but are deprecated for new code.
The eventSourcedGrain { } CE and its JournaledGrain bridge. Not deprecated, and not the same
thing as the journaledGrainFor definition builder above: this one needs a C#-declared grain
interface and the CodeGen that comes with it. See Event Sourcing .
Type Description EventSourcedGrainDefinition<'State, 'Event, 'Command>Event-sourced grain specification (DefaultState, Apply, Handle, ConsistencyProvider, CustomStorage, SnapshotStrategy) SnapshotStrategy<'State>Never, Every of int, Condition of (int -> 'State -> bool)CustomStorageAdapterBoxed read/write pair for a custom log-consistency store IEventStoreContext<'Event>Event store abstraction for the C# CodeGen bridge (RaiseEvent, ConfirmEvents, Version) FSharpEventSourcedGrain<'State,'Event,'Command>Generic JournaledGrain base bridging a definition to Orleans FSharpEventSourcedGrainAttributeBinds an implementation to a grain interface
CE Builder Description eventSourcedGrain { }EventSourcedGrainBuilderDefine event-sourced grain behavior
Keyword Signature Description defaultState'StateInitial state value apply'State -> 'Event -> 'StateThe pure fold handle'State -> 'Command -> 'Event listCommand handler; an empty list is a refusal logConsistencyProviderstringNamed Orleans log-consistency provider snapshotSnapshotStrategy<'State>Snapshot strategy (honoured only by a custom store) customStorageread + writeCustom log-consistency storage pair
Function Signature Description foldEventsdefinition -> 'State -> 'Event list -> 'StateReplay events onto state handleCommanddefinition -> 'State -> 'Command -> 'State * 'Event listProcess a command, returning the folded state and the events
Function Signature Description processCommanddefinition -> 'State -> 'Command -> 'Event listProduce events from a command applyEventdefinition -> 'State -> 'Event -> 'StateApply a single event replayEventsdefinition -> 'State -> 'Event list -> 'StateReplay an event list shouldSnapshotdefinition -> int -> 'State -> boolEvaluate the snapshot strategy
Method Signature Description AddFSharpEventSourcedGrain<'State,'Event,'Command>IServiceCollection -> definition -> IServiceCollectionRegister one definition AddFSharpEventSourcedGrainsFromAssemblyIServiceCollection -> Assembly -> IServiceCollectionRegister every definition an assembly declares
Everything below carries [<Obsolete>] (warning, not error) and is kept runnable. The replacement
for each entry is the functional grain runtime ; see
Functional grains , “Migrating from the grain { } CE”, for the rewrite
recipe.
Type Description Replacement GrainDefinition<'State, 'Message>Immutable record describing a grain’s behavior FunctionalGrainDefinition<...> from grainForGrainContextGrain factory, service provider, and named states FunctionalGrainContext<'Actor,'Key>AdditionalStateSpecNamed additional persistent state specification PersistentState.create + usePersistentStateFSharpGrainAttributeMarks a definition for assembly discovery — (a definition is registered by value) FSharpGrainHandle<'S,'M>Zero-alloc struct handle for a string-keyed grain FunctionalGrain.ref / rawRefFSharpGrainGuidHandle<'S,'M>Zero-alloc struct handle for a GUID-keyed grain FunctionalGrain.ref / rawRefFSharpGrainIntHandle<'S,'M>Zero-alloc struct handle for an int64-keyed grain FunctionalGrain.ref / rawRef
CE Builder Description grain { }GrainBuilderDefine grain behavior declaratively
Keyword Handler Signature Description defaultState'StateInitial state value handle'State -> 'Msg -> Task<'State * obj>Register handler with manual box handleState'State -> 'Msg -> Task<'State>Handler returning only state (no result value) handleTyped'State -> 'Msg -> Task<'State * 'R>Handler with typed result — no box needed handleWithContextGrainContext -> 'State -> 'Msg -> Task<'State * obj>Handler with DI/grain-to-grain access handleStateWithContextGrainContext -> 'State -> 'Msg -> Task<'State>Context + state-only return handleTypedWithContextGrainContext -> 'State -> 'Msg -> Task<'State * 'R>Context + typed result handleCancellable'State -> 'Msg -> CancellationToken -> Task<'State * obj>Cancellation, manual box handleStateCancellable'State -> 'Msg -> CancellationToken -> Task<'State>Cancellation, state-only return handleTypedCancellable'State -> 'Msg -> CancellationToken -> Task<'State * 'R>Cancellation, typed result handleWithContextCancellableGrainContext -> 'State -> 'Msg -> CancellationToken -> Task<'State * obj>Context + cancellation handleStateWithContextCancellableGrainContext -> 'State -> 'Msg -> CancellationToken -> Task<'State>Context + cancellation, state-only return handleTypedWithContextCancellableGrainContext -> 'State -> 'Msg -> CancellationToken -> Task<'State * 'R>Context + cancellation, typed result persiststringName of the storage provider for state additionalState<'T>string (name) + string (storage) + 'T (default)Named additional persistent state onActivate'State -> Task<'State>Activation hook; may replace the state onDeactivate'State -> Task<unit>Deactivation hook; cleanup only onReminderstring + ('State -> string -> TickStatus -> Task<'State>)Named reminder with a stateful handler onTimerstring + TimeSpan (due) + TimeSpan (period) + ('State -> Task<'State>)Declarative timer onLifecycleStageint + (CancellationToken -> Task<unit>)Hook a raw Orleans grain-lifecycle stage number interleaveMessageSystem.TypeAllow a message type to interleave (interleaveMessage typeof<Query>)
Each handle* keyword also has a *WithServices form (handleWithServices,
handleStateWithServices, handleTypedWithServices, and their Cancellable variants) taking an
IServiceProvider instead of a GrainContext. See
legacy Grain Definition guide for the full keyword list. Per-grain Orleans
attributes ([Reentrant], [StatelessWorker], placement, [OneWay], [ReadOnly],
[ImplicitStreamSubscription], …) are applied via the C# CodeGen path, not grain { } keywords.
On the functional grain runtime they are ordinary contract and definition
operations instead — reentrant, statelessWorker, placement, oneWay, readOnly, and
onStream / onBroadcast for implicit subscriptions.
Function Signature Description getService<'T>GrainContext -> 'TResolve a DI service getState<'T>GrainContext -> string -> IPersistentState<'T>Get named additional persistent state getGrainByString<'T>GrainContext -> string -> GrainRef<'T, string>Get grain ref by string key getGrainByGuid<'T>GrainContext -> Guid -> GrainRef<'T, Guid>Get grain ref by GUID key getGrainByInt64<'T>GrainContext -> int64 -> GrainRef<'T, int64>Get grain ref by int64 key getGrainByGuidCompound<'T>GrainContext -> Guid -> string -> GrainRef<'T, CompoundGuidKey>Compound GUID key getGrainByIntCompound<'T>GrainContext -> int64 -> string -> GrainRef<'T, CompoundIntKey>Compound int64 key deactivateOnIdleGrainContext -> unitRequest grain deactivation when idle delayDeactivationGrainContext -> TimeSpan -> unitDelay grain deactivation grainIdGrainContext -> GrainIdGet the GrainId primaryKeyStringGrainContext -> stringGet string primary key primaryKeyGuidGrainContext -> GuidGet Guid primary key primaryKeyInt64GrainContext -> int64Get int64 primary key emptyGrainContextEmpty context for unit tests (all fields null/None)
Function Signature Description hasAnyHandlerGrainDefinition -> boolTrue if any handler is registered getHandlerGrainDefinition -> 'State -> 'Message -> Task<'State * obj>Get plain handler getContextHandlerGrainDefinition -> GrainContext -> 'State -> 'Message -> Task<'State * obj>Get context-aware handler getCancellableContextHandlerGrainDefinition -> GrainContext -> 'State -> 'Message -> CT -> Task<'State * obj>Get cancellable context handler invokeHandlerGrainDefinition -> 'State -> 'Message -> Task<'State * obj>Invoke handler (C# interop) invokeContextHandlerGrainDefinition -> GrainContext -> 'State -> 'Message -> Task<'State * obj>Invoke context handler (C# interop) invokeCancellableContextHandlerGrainDefinition -> GrainContext -> 'State -> 'Message -> CT -> Task<'State * obj>Invoke cancellable (C# interop) invokeOnActivateGrainDefinition -> 'State -> Task<'State>Run the activation hook directly invokeOnDeactivateGrainDefinition -> 'State -> TaskRun the deactivation hook directly invokeReminderHandlerGrainDefinition -> 'State -> string -> TickStatus -> Task<'State>Run one named reminder handler directly
Function Signature Description registerGrain -> string -> TimeSpan -> TimeSpan -> Task<IGrainReminder>Register/update reminder unregisterGrain -> string -> Task<unit>Unregister reminder getGrain -> string -> Task<IGrainReminder option>Get reminder by name
Replacement: onReminder on a functional definition, which reconciles declared reminders on every
activation.
Function Signature Description registerGrain -> (CT -> Task<unit>) -> TimeSpan -> TimeSpan -> IGrainTimerRegister timer registerWithState<'T>Grain -> ('T -> CT -> Task<unit>) -> 'T -> TimeSpan -> TimeSpan -> IGrainTimerTimer with state
Replacement: onTimer on a functional definition.
Registered once with AddFSharpGrain, called from anywhere with FSharpGrain.ref. Replacement:
grainContract + grainFor + FunctionalGrain.ref, which types the reply per operation instead of
boxing one message DU.
Function Signature Description FSharpGrain.ref<'S,'M>IGrainFactory -> string -> FSharpGrainHandle<'S,'M>Handle for string-keyed grain FSharpGrain.refGuid<'S,'M>IGrainFactory -> Guid -> FSharpGrainGuidHandle<'S,'M>Handle for GUID-keyed grain FSharpGrain.refInt<'S,'M>IGrainFactory -> int64 -> FSharpGrainIntHandle<'S,'M>Handle for int64-keyed grain FSharpGrain.send<'S,'M>'M -> FSharpGrainHandle<'S,'M> -> Task<'S>Send command, return typed state FSharpGrain.post<'S,'M>'M -> FSharpGrainHandle<'S,'M> -> TaskFire-and-forget command FSharpGrain.ask<'S,'M,'R>'M -> FSharpGrainHandle<'S,'M> -> Task<'R>Send command, return typed result (can differ from state) FSharpGrain.sendGuid<'S,'M>'M -> FSharpGrainGuidHandle<'S,'M> -> Task<'S>Send to GUID-keyed grain FSharpGrain.postGuid<'S,'M>'M -> FSharpGrainGuidHandle<'S,'M> -> TaskPost to GUID-keyed grain FSharpGrain.askGuid<'S,'M,'R>'M -> FSharpGrainGuidHandle<'S,'M> -> Task<'R>Ask GUID-keyed grain for typed result FSharpGrain.sendInt<'S,'M>'M -> FSharpGrainIntHandle<'S,'M> -> Task<'S>Send to int64-keyed grain FSharpGrain.postInt<'S,'M>'M -> FSharpGrainIntHandle<'S,'M> -> TaskPost to int64-keyed grain FSharpGrain.askInt<'S,'M,'R>'M -> FSharpGrainIntHandle<'S,'M> -> Task<'R>Ask int64-keyed grain for typed result
DI registration (call once per grain definition at silo startup):
// Automatically registers FSharpBinaryCodec (idempotent)
services.AddFSharpGrain < CounterState , CounterCommand >( counterGrain ) |> ignore
AddFSharpGrainsFromAssembly registers every [<FSharpGrain>]-marked definition an assembly
declares.
Function Signature Description GrainMock.withFSharpGrain<'S,'M>string -> GrainDefinition<'S,'M> -> MockGrainFactory -> MockGrainFactoryRegister an F# grain definition as a mock, by string key GrainMock.withFSharpGrainGuid<'S,'M>Guid -> GrainDefinition<'S,'M> -> MockGrainFactory -> MockGrainFactoryThe same, by GUID key GrainMock.withFSharpGrainInt<'S,'M>int64 -> GrainDefinition<'S,'M> -> MockGrainFactory -> MockGrainFactoryThe same, by int64 key TestHarness.getFSharpGrain<'S,'M>TestHarness -> string -> FSharpGrainHandle<'S,'M>Handle from a test cluster, by string key TestHarness.getFSharpGrainGuid<'S,'M>TestHarness -> Guid -> FSharpGrainGuidHandle<'S,'M>The same, by GUID key TestHarness.getFSharpGrainInt<'S,'M>TestHarness -> int64 -> FSharpGrainIntHandle<'S,'M>The same, by int64 key
The following helpers support C# CodeGen interfaces or the older class-based transactional model;
they are not part of the functional authoring surface.
API Purpose Functional replacement GrainRef.ofString/ofGuid/ofInt64 and GrainRef.invokeWrap a generated C# grain interface FunctionalGrain.ref / rawRefGrainState.read/write/clear/currentOperate directly on an injected IPersistentState PersistentState.create, stateFrom, and context.persistentStateObserver.createRef/deleteRef/subscribe and FSharpObserverManagerGenerated C# observer interfaces observerContract, FunctionalObserver, and FunctionalObserverManagerTransactions.TransactionalStateWrap an injected ITransactionalState transactionalStateFrom and FunctionalTransactionalState
These settings apply to Legacy C# CodeGen grain interfaces. Current functional contracts use
version, acceptsVersions, and sinceVersion on grainContract instead.
API Members CompatibilityStrategyBackwardCompatible, StrictVersion, AllVersionsVersionSelectorStrategyAllCompatibleVersions, LatestVersion, MinimumVersionVersioningcompatibilityStrategyName, versionSelectorStrategyNameTransactionalGrainDefinition, FSharpTransactionalGrain, AtmGrainDefinition, FSharpAtmGrainClass-based transactional grains