Registering Saga Starter
We just have to make a small change in our bootstrapper. So that VerificationRequested event will start the saga. We only need the below change.
let userSagaShard = UserSaga.factory env actorApi
let sagaCheck (o: obj) =
match o with
| :? (FCQRS.Common.Event<User.Event>) as e ->
match e.EventDetails with
| User.VerificationRequested _ ->
[ userSagaShard, id |> Some |> PrefixConversion, o ]
| _ -> []
| _ -> []
actorApi.InitializeSagaStarter sagaCheck
We also need to initialize the user and saga actors.
UserSaga.init env actorApi |> ignore
namespace System
namespace System.IO
namespace Microsoft
namespace Microsoft.Extensions
namespace Microsoft.Extensions.Configuration
namespace Hocon
namespace Hocon.Extensions
namespace Hocon.Extensions.Configuration
module Bootstrap
namespace FCQRS
module Common
from FCQRS
<summary> Contains common types like Events and Commands </summary>
<namespacedoc><summary>Functionality for Write Side.</summary></namespacedoc>
<summary> Contains common types like Events and Commands </summary>
<namespacedoc><summary>Functionality for Write Side.</summary></namespacedoc>
val userSagaShard: Akkling.Cluster.Sharding.IEntityRef<obj>
module UserSaga
val factory: actorApi: IActor -> entityId: string -> Akkling.Cluster.Sharding.IEntityRef<obj>
val actorApi: IActor
val sagaCheck: o: obj -> (Akkling.Cluster.Sharding.IEntityRef<obj> * PrefixConversion * obj) list
val o: obj
type obj = System.Object
type Event<'EventDetails> =
{
EventDetails: 'EventDetails
CreationDate: DateTime
Id: MessageId
Sender: AggregateId option
CorrelationId: CID
Version: Version
Metadata: Map<string,string>
}
interface IMessage
interface ISerializable
member Equals: Event<'EventDetails> * IEqualityComparer -> bool
override ToString: unit -> string
<summary> Represents an event generated by an aggregate actor as a result of processing a command. <typeparam name="'EventDetails">The specific type of the event payload.</typeparam> </summary>
<summary> Represents an event generated by an aggregate actor as a result of processing a command. <typeparam name="'EventDetails">The specific type of the event payload.</typeparam> </summary>
module User
type Event =
| LoginSucceeded
| LoginFailed
| AlreadyRegistered
| VerificationRequested of string * string
| VerificationCodeSet of string
| Verified
member Equals: Event * IEqualityComparer -> bool
member IsAlreadyRegistered: bool
member IsLoginFailed: bool
member IsLoginSucceeded: bool
member IsVerificationCodeSet: bool
member IsVerificationRequested: bool
member IsVerified: bool
val e: Event<User.Event>
Event.EventDetails: User.Event
<summary> The specific details or payload of the event. </summary>
<summary> The specific details or payload of the event. </summary>
union case User.Event.VerificationRequested: string * string -> User.Event
val id: x: 'T -> 'T
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
union case PrefixConversion.PrefixConversion: (string -> string) option -> PrefixConversion
--------------------
type PrefixConversion = | PrefixConversion of (string -> string) option
<summary> Default shard name used if no specific sharding strategy is provided. Represents a potential transformation to apply to an entity ID prefix, used in saga routing. Allows sagas to be co-located or routed differently based on the originator's ID structure. </summary>
union case PrefixConversion.PrefixConversion: (string -> string) option -> PrefixConversion
--------------------
type PrefixConversion = | PrefixConversion of (string -> string) option
<summary> Default shard name used if no specific sharding strategy is provided. Represents a potential transformation to apply to an entity ID prefix, used in saga routing. Allows sagas to be co-located or routed differently based on the originator's ID structure. </summary>
abstract IActor.InitializeSagaStarter: (obj -> ((string -> Akkling.Cluster.Sharding.IEntityRef<obj>) * PrefixConversion * obj) list) -> unit
val init: actorApi: IActor -> Akkling.Cluster.Sharding.EntityFac<obj>
val ignore: value: 'T -> unit
FCQRS