Bootstrapping
The ultimate objective of write side bootstrapping is to make a call to FCQRS.Actor.api which initializes the actor system and starts the write side. This API requires a configuration and a logger factory. The configuration is used to configure the actor system and the logger factory is used to log messages from the actor system.
open System.IO
open Microsoft.Extensions.Configuration
open Hocon.Extensions.Configuration
open Microsoft.Extensions.Logging
let configBuilder =
ConfigurationBuilder()
.AddHoconFile(Path.Combine(__SOURCE_DIRECTORY__, "config.hocon"))
let config = configBuilder.Build()
let loggerFactory =
LoggerFactory.Create(fun builder -> builder.AddConsole() |> ignore)
You don't have to use HOCON configuration. You can use any configuration system you like , as long as you can build a configuration object that implements IConfiguration
.
let actorApi = FCQRS.Actor.api config loggerFactory
actorApi.InitializeSagaStarter (fun _ -> [])
Next we create a shard for the User aggregate. A shard is like parent of aggregate actors. And initilize the shard.
let env = new Environments.AppEnv(config,loggerFactory)
let userShard = User.factory env actorApi
User.init env actorApi |> ignore
We create a helper function to send commands to the actor. cid means corralation id and it is used to track the command.
let userSubs cid = actorApi.CreateCommandSubscription userShard cid
Finally we initialize the query side. But also gets subscription for the query side.
let sub handleEventWrapper offsetCount =
FCQRS.Query.init actorApi offsetCount (handleEventWrapper env)
type ConfigurationBuilder = interface IConfigurationBuilder new: unit -> unit member Add: source: IConfigurationSource -> IConfigurationBuilder member Build: unit -> IConfigurationRoot member Properties: IDictionary<string,obj> member Sources: IList<IConfigurationSource>
<summary> Builds key/value-based configuration settings for use in an application. </summary>
--------------------
ConfigurationBuilder() : ConfigurationBuilder
<summary>Performs operations on <see cref="T:System.String" /> instances that contain file or directory path information. These operations are performed in a cross-platform manner.</summary>
Path.Combine([<System.ParamArray>] paths: string array) : string
Path.Combine(path1: string, path2: string) : string
Path.Combine(path1: string, path2: string, path3: string) : string
Path.Combine(path1: string, path2: string, path3: string, path4: string) : string
type LoggerFactory = interface ILoggerFactory interface IDisposable new: unit -> unit + 5 overloads member AddProvider: provider: ILoggerProvider -> unit member CreateLogger: categoryName: string -> ILogger member Dispose: unit -> unit static member Create: configure: Action<ILoggingBuilder> -> ILoggerFactory
<summary> Produces instances of <see cref="T:Microsoft.Extensions.Logging.ILogger" /> classes based on the given providers. </summary>
--------------------
LoggerFactory() : LoggerFactory
LoggerFactory(providers: System.Collections.Generic.IEnumerable<ILoggerProvider>) : LoggerFactory
LoggerFactory(providers: System.Collections.Generic.IEnumerable<ILoggerProvider>, filterOptions: LoggerFilterOptions) : LoggerFactory
LoggerFactory(providers: System.Collections.Generic.IEnumerable<ILoggerProvider>, filterOption: Extensions.Options.IOptionsMonitor<LoggerFilterOptions>) : LoggerFactory
LoggerFactory(providers: System.Collections.Generic.IEnumerable<ILoggerProvider>, filterOption: Extensions.Options.IOptionsMonitor<LoggerFilterOptions>, options: Extensions.Options.IOptions<LoggerFactoryOptions>) : LoggerFactory
LoggerFactory(providers: System.Collections.Generic.IEnumerable<ILoggerProvider>, filterOption: Extensions.Options.IOptionsMonitor<LoggerFilterOptions>, ?options: Extensions.Options.IOptions<LoggerFactoryOptions>, ?scopeProvider: IExternalScopeProvider) : LoggerFactory
(extension) ILoggingBuilder.AddConsole(configure: System.Action<Console.ConsoleLoggerOptions>) : ILoggingBuilder
type AppEnv = interface IConfigurationWrapper interface ILoggerFactoryWrapper new: config: IConfiguration * loggerFactory: ILoggerFactory -> AppEnv
<summary> Composition root for the application environment. While being a god object is an anti-pattern, it plays nicely with F# partial application. Much better than DI magic with reflection. It wraps IConfiguration and ILoggerFactory. </summary>
--------------------
new: config: IConfiguration * loggerFactory: ILoggerFactory -> Environments.AppEnv