-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: nested DU support? #33
Comments
@CumpsD ran into this - will reply in more depth later TL;DR use StreamName to route at high level but UnionEncoder only works on top level unions There is a Need to be AFK for a bit - perhaps @CumpsD can explain in mode depth if this is not clear |
I ran into the same, yes: https://github.com/exira/FsCodec/blob/creating-events/tests/FsCodec.NewtonsoftJson.Tests/DomainExample.fsx#L227-L236 I'll let @bartelink reply more on it, I'm currently taking another approach by playing with Chiron to serialize DUs in DUs :) |
@TerenceHinrichsen Finally have time to expand on this The general pattern being catered for is
For that reason, DU hierarchies are definitely not on the table as they rarely represent the cleanest way to model as directly as possible the domain's events. type WeirdThing = {value: string; active: bool}
type WeirdThing2 = {value: string; active: bool; location: string }
type Something =
| WeirdThing of WeirdThing
| WeirdThing2 of WeirdThing2
type Event =
| [<DataMember(Name = "Created")>] Created of New
| [<DataMember(Name = "SomethingWierd")>] Something of WierdThing
| [<DataMember(Name = "SomethingWierd2")>] Something2 of WierdThing2
with interface IUnionContract But, I have to declare I've done it, and don't completely regret it, so I'll invest no further time dissuading you from it! In the box, the UnionConverter enables this. You'd take your code and tag as follows: type WeirdThing = {value: string; active: bool}
type WeirdThing2 = {value: string; active: bool; location: string }
[<Newtonsoft.Json.JsonConverter(typeof<FsCodec.NewtonsoftJson.UnionConverter>)>]
type Something =
| WeirdThing of WeirdThing
| WeirdThing2 of WeirdThing2
type Event =
| [<DataMember(Name = "Created")>] Created of New
| [<DataMember(Name = "Something")>] Something of Something
with interface IUnionContract There's a small chance that that'll fall foul of the "ensure all bodies are records" restriction - that can be inhibited by passing Perhaps you'd care to expand more on your real use case - there may be a cleaner solution; feel free to DM in DDD-CQRS-ES slack if you can't share it here |
Thanks @bartelink & @CumpsD |
Interesting - I've serialized lots of snapshots over time (with plenty I'd agree that for a Snapshotted event it's more valid than it is for an organic event. Also, as part of versioning, having a top level record (as the exception forces you) also gives you an extensibility point (aside from stuffing it into the (The fact UnionEncoder has this restriction by default, in addition to requiring the marker interface is that experience showed him that the relatively unobtrusive nature of how you define the types can leave random devs making tweaks pretty unaware that these things are versioned union contracts, so over time you'll come to appreciate these nudges, even if they seem very arbitrary from the off) Let us know if you run into any inconsistencies. |
This might just be my ignorance, but I am having great difficulty in using the UnionEncoder, with Equinox to create events.
I have this:
I get no error during BUILD - so syntax is good, however, during runtime, when I create an event
Something
I get a exception:So now I am wondering whether a DU nested inside a DU is possible using the TypeShape UnionEncoder? What am I missing?
The text was updated successfully, but these errors were encountered: