I have some code which I have simplified below.
(I’m trying to follow the Domain-Driven Design model in Scott Wlaschin’s book “Domain Modelling Make Functional”.)
I’ve removed all of the Result processing of the original code, and a lot of the actual code, to focus on the organisational stuff.
I have the system domain in the Domain namespace.
I have the data transfer stuff (edge of domain) in the DataTransfer namespace.
I have the data access stuff (outside of domain) in the DataAccess namespace.
namespace Domain
open System
type Thing =
{ Id : Guid
Name : string }
module Thing =
let validate item = item
let moreChecks item = item
let create item =
item
|> validate
|> moreChecks
|> DataTransfer.serialise
|> DataAccess.saveToDisk
namespace DataTransfer
open Domain
type ThingDto =
{ Id : string
Name : string }
module DataTransfer =
let serialise (item : Thing) =
{ ThingDto.Id = item.Id.ToString()
Name = item.Name }
namespace DataAccess
open DataTransfer
module DataAccess =
let saveToDisk (item : ThingDto) = printfn $"Item {item.Id} Saved"
However, I cannot access the serialise or saveToDisk functions as they are defined after they are used.
I could define the DataTransfer and DataAccess namespaces before the Domain namespace but that would mean that the Thing type would be defined after the functions in the DataTransfer namespace which need to know about it.
I can’t figure out how I can define things in the right order so they are usable by the things which need them but are also not all ‘bunched together’ in a single (messy) module.
Can anyone help?