u/kincade1905

▲ 3 r/DomainDrivenDesign+1 crossposts

I am trying to follow, Domain Modelling Made Functional, honestly I am hitting some very annoying walls than expected. Her's my latest annoyance.

I have two worfklow; SignIn and ConfirmSignup.

ConfirmSignup's contract looks something like this:

type SignupError =
    | ValidationFailed of ValidationError list
    | EmailAlreadyExists
    | VerificationCodeDeliveryFailure
    | PasswordPolicyNotMet
    

// Ports
type SignupUser = SignupCommand -> TaskResult<SignupResult, Error>

type SignupWorkflow = SignupRequest -> TaskResult<SignupResult, SignupError>

The flow is:
SignupWorkflow --> Validate Request --> Other business stuff --> Calls port

As you might observe, The erorr type for the port has ValidationFailed error which it got nothing to do with.

Now, Let's say I have added two more ports and one more aggregate? Then, surely, I can't give the flat DU erorr to all of these ports.

I could do follwing:

>type SignupPortError =
| | EmailAlreadyExists
| VerificationCodeDeliveryFailure
| PasswordPolicyNotMet

type SignupError =
| ValidationFailed of ValidationError list
| SignupError of SignupPortErrror (naming is hard!!!!!!!!!!!!)

But the problem is, What if I want to use the port, Signup in another workflow? Now, I have to reference SignupWorfkow's contract file in another Workflow, which it got nothing to do with it!!!!!!!!!!!!!!!!!!!!!

How do you guys resolve this issue?

reddit.com
u/kincade1905 — 10 days ago
▲ 4 r/fsharp

Novice here, loving f# and Domain Modelling Made Functional book so far.

While I love the book, it sorts of do hand wavy for the things which might actually crop up in actual implementation, I find.

Let's say, I have authentication service. Since I want to be good citizen, I created signupWorkflow, I have ports and adapters. I have neatly created contract for the adapters to obey. All neat and clean till now.

But hang on, what about infrastructure error returned by adapter itself ? Surely, service down or misconfigured service or wrong key returned by adapter be domain error of workflow ?

But I still need to tell user of my workflow(maybe api layer)or service, hey, the upstream service shat the bed. How can this be done ?

Also, if I only have some normal workflow which takes one adapter then, ignoring infrastructure error handling(which I have no idea how to do), it's quite simple, workflow returns either domain success or failure. It validates the input, throws it's domain validation error, happy days.

But... I have workflow which takes two adapter; confirmSignnup, saveDB. ConfirmSingup takes validated confirmSingup command and saveDB takes validated User command and these two aren't same. These two return completely different error.

How does confirmSignup workflow handles these validation error ?

Flow is:

confirmSignnup ->Workflow -> validate confrimSignup command -> call confrimSignup adapter -> call saveDB. Now, while calling db, its validation failed? What happens now ?

reddit.com
u/kincade1905 — 11 days ago
▲ 7 r/fsharp

Hello, I am newbie and trying F# by building basic authentication service.

Let's say, I have register user fuction, it takes un-validated raw request containg username and password and returns Registereduser or SignupErrors.

The problem I am facing is, there are too darn errros DUs.
For example, I have,

type EmailValidationError =
    | FieldRequired
    | MaxLengthExceeded of int
    | MalformedEmail

type PasswordValidationError =
    | FieldRequired
    | MaxLengthExceeded    of int
    | MinLengthNotMet      of int
    | MissingUppercase
    | MissingLowercase

These two error DU's are just validation error returned by Smart Constructor of email and password. And, SignupError look like this.

type SignupFieldError =
    | EmailErrors    of SignupEmail.EmailValidationError 
    | PasswordErrors of SignupPassword.PasswordValidationErrotype 


type SignupError =
    | ValidationFailed   of FieldError list
    | EmailAlreadyExists

As you can see, this gets ugly very soon. What I like to return is:
| ValidationError : EmailValidatioNError | PasswordValidationErrror list ??

| EmailAlreadyExists

Does anyone has better ideas? I really hate my currrent solution.

Thank you in advance. 😄

reddit.com
u/kincade1905 — 16 days ago