Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Console
open Axial.FileSystem
open Axial.Hosting
open Axial.Hosting.Browser
open Axial.Hosting.Node
open Axial.State
open Axial.Telemetry
open Axial.Telemetry.JavaScriptTutorial: Composing Built-in Services
An application environment holds dependencies with authority: configuration, repositories, HTTP clients, files and process execution. Clock, ordinary random values and GUIDs come from the runtime. Logging and telemetry are write-only observation slots. None of those runtime slots needs forwarding interfaces on your record.
Declare application authority
An application record carries authority and exposes only what its workflows need:
Show page setup
open System
open System.Threading.Tasks
open Axial
open Axial
let shouldEqual expected actual =
if actual <> expected then failwithf "Expected %A but got %A" expected actualtype IAppSettings =
abstract Mode: string
type AppEnv =
{ Settings: IAppSettings }
let loadMode : Flow<AppEnv, Never, string> =
flow {
let! now = Clock.utcDateTime
let! mode = Flow.envWith (fun env -> env.Settings.Mode)
do! Log.info $"[{now:O}] starting in mode {mode}"
return mode
}
FsLiveDocsGeneratedPage2_4232598D5E1C.IAppSettingsMode: IAppSettings -> unit -> stringstringAn abbreviation for the CLI type . Basic Types
FsLiveDocsGeneratedPage2_4232598D5E1C.AppEnvSettings: IAppSettingsloadMode: Flow<AppEnv,Never,string>Axial.Flow`3Axial.NeverRepresents an error channel that cannot occur.
flow: FlowBuilderThe universal flow { } computation expression.
now: DateTimeAxial.ClockHelpers for the clock service.
utcDateTime: Flow<'env,'error,DateTime>Reads the current UTC date/time from an explicit clock service.
mode: stringAxial.FlowenvWith: ('env -> 'value) -> Flow<'env,'error,'value>Projects one value from the current environment. This is the primary way to access app dependencies, configuration, or request metadata stored in env. The projection runs only when the flow is executed, so constructing the flow is still pure and side-effect free. Prefer small projections over passing a large environment deeper into reusable helpers. A function that extracts a value from the environment. A containing the projected value. let region () = Flow.envWith (fun (environment: {| Region: string |}) -> environment.Region)
env: AppEnvMode: stringAxial.LogHelpers for the logging service.
info: string -> Flow<'env,'error,unit>Writes an informational message to the installed log sink.
Requires & types
Requires: open Axial (packages: Axial)val loadMode: Flow<AppEnv,Never,string>Only the settings projection constrains the application environment. The clock and log destination can be
controlled without changing AppEnv or the workflow. Loading configuration into IAppSettings at the edge is
covered in the configuration guide.
Add application dependencies
An ordinary projection needs no service interface:
type IOrderRepository =
abstract Count: unit -> int
type ShopEnv =
{ Orders: IOrderRepository }
let countOrders : Flow<ShopEnv, Never, int> = Flow.envWith (fun env -> env.Orders.Count())
FsLiveDocsGeneratedPage2_4232598D5E1C.IOrderRepositoryCount: IOrderRepository -> unit -> intunitThe type 'unit', which has only one value "()". This value is special and always uses the representation 'null'. Basic Types
intAn abbreviation for the CLI type . Basic Types
FsLiveDocsGeneratedPage2_4232598D5E1C.ShopEnvOrders: IOrderRepositorycountOrders: Flow<ShopEnv,Never,int>Axial.Flow`3Axial.NeverRepresents an error channel that cannot occur.
Axial.FlowenvWith: ('env -> 'value) -> Flow<'env,'error,'value>Projects one value from the current environment. This is the primary way to access app dependencies, configuration, or request metadata stored in env. The projection runs only when the flow is executed, so constructing the flow is still pure and side-effect free. Prefer small projections over passing a large environment deeper into reusable helpers. A function that extracts a value from the environment. A containing the projected value. let region () = Flow.envWith (fun (environment: {| Region: string |}) -> environment.Region)
env: ShopEnvCount: unit -> intRequires & types
Requires: open Axial (packages: Axial)val countOrders: Flow<ShopEnv,Never,int>Use Flow.envWith _.Orders when the workflow belongs to this record. Add a named authority contract only when
helpers should work across environment shapes; see custom services.
Run at the edge
let runLive (settings: IAppSettings) : Task<Exit<string, Never>> =
loadMode
|> Flow.startTask { Settings = settings }
runLive: IAppSettings -> Task<Exit<string,Never>>settings: IAppSettingsFsLiveDocsGeneratedPage2_4232598D5E1C.IAppSettingsSystem.Threading.Tasks.Task`1Represents an asynchronous operation that can return a value. The type of the result produced by this .
Axial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
stringAn abbreviation for the CLI type . Basic Types
Axial.NeverRepresents an error channel that cannot occur.
loadMode: Flow<AppEnv,Never,string>(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.FlowstartTask: 'env -> Flow<'env,'error,'value> -> Task<Exit<'value,'error>>Starts the workflow immediately and returns a task handle for its final exit. The work is already in flight when this returns. Use Flow.toAsync for a cold handle. The environment used by the workflow. The workflow to start. A task that completes with the workflow exit. let running = workflow |> Flow.startTask environment
Settings: IAppSettingsRequires & types
Requires: open Axial; open System.Threading.Tasks (packages: Axial)val runLive: IAppSettings -> Task<Exit<string,Never>>The host constructs the application authority at the edge and supplies it in the environment. The runtime supplies live clock/random/GUID values and an Information+ stderr log sink. Generic Host and HTTP host adapters can install their own sinks; an inner scoped override still wins.
Test without global state
A workflow that reads runtime values can be tested without global state by overriding the scoped values:
let testEnv =
{ Settings = { new IAppSettings with member _.Mode = "diagnostic" } }
let log = Log.memory ()
loadMode
|> Flow.withClock (Clock.fromValue (DateTimeOffset(2026, 1, 1, 0, 0, 0, TimeSpan.Zero)))
|> Flow.withLogSink log
|> Flow.run testEnv
|> shouldEqual (Exit.Success "diagnostic")
log.Entries |> Seq.map _.Message |> Seq.toList
|> shouldEqual ["[2026-01-01T00:00:00.0000000Z] starting in mode diagnostic"]
testEnv: AppEnvSettings: IAppSettingsFsLiveDocsGeneratedPage2_4232598D5E1C.IAppSettings_: IAppSettingsMode: unit -> stringlog: TestLogAxial.LogHelpers for the logging service.
memory: unit -> TestLogloadMode: Flow<AppEnv,Never,string>(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.FlowwithClock: IClock -> Flow<'env,'error,'value> -> Flow<'env,'error,'value>Overrides the clock within this flow and its descendants.
Axial.ClockHelpers for the clock service.
fromValue: DateTimeOffset -> ManualClockCreates a manual clock starting at the supplied instant. Sleeps require explicit advancement.
``.ctor``: int * int * int * int * int * int * TimeSpan -> unitInitializes a new instance of the structure using the specified year, month, day, hour, minute, second, and offset. The year (1 through 9999). The month (1 through 12). The day (1 through the number of days in ). The hours (0 through 23). The minutes (0 through 59). The seconds (0 through 59). The time's offset from Coordinated Universal Time (UTC). does not represent whole minutes. is less than one or greater than 9999. -or- is less than one or greater than 12. -or- is less than one or greater than the number of days in . -or- is less than zero or greater than 23. -or- is less than 0 or greater than 59. -or- is less than 0 or greater than 59. -or- is less than -14 hours or greater than 14 hours. -or- The property is earlier than or later than .
System.TimeSpanRepresents a time interval.
Zero: TimeSpanRepresents the zero value. This field is read-only.
withLogSink: ILogSink -> Flow<'env,'error,'value> -> Flow<'env,'error,'value>Replaces the log destination within this flow and its descendants.
run: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
shouldEqual: 'a -> 'a -> unitAxial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
SuccessThe workflow completed successfully.
Entries: Collections.Generic.IReadOnlyList<LogEntry>The recorded entries, in the order they were written.
Microsoft.FSharp.Collections.SeqModuleContains operations for working with values of type .
map: ('T -> 'U) -> 'T seq -> 'U seqBuilds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The given function will be applied as elements are demanded using the MoveNext method on enumerators retrieved from the object. The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently. A function to transform items from the input sequence. The input sequence. The result sequence. Thrown when the input sequence is null. let inputs = ["a"; "bbb"; "cc"] inputs |> Seq.map (fun x -> x.Length) Evaluates to a sequence yielding the same results as seq { 1; 3; 2 }
_arg1: LogEntryMessage: stringtoList: 'T seq -> 'T listBuilds a list from the given collection. The input sequence. The result list. Thrown when the input sequence is null. let inputs = seq { 1; 2; 5 } inputs |> Seq.toList Evaluates to [ 1; 2; 5 ].
Requires & types
Requires: open Axial; open System (packages: Axial)val testEnv: AppEnvval log: TestLogFlow.withRandom and Flow.withGuid follow the same scope rule as withClock and withLogSink; descendants
inherit them and outer values are restored afterwards. Flow.runTest env installs a fresh deterministic
TestPlatform, including a recording log, without moving authority out of the environment.
Use layers when constructing the application environment acquires resources or can fail. Use runtime overrides for values and observation slots, not as a general-purpose dependency registry.

