Polymorphic support? Newtonsoft support? #33
-
I'm trying to implement an event sourcing event store using this library and came across a few things I was hoping someone might help me answer. I would like to have a stream of events for a particular interface and have the ability to correctly deserialize those objects to their correct implementation. My plan was to use a custom system.text.json converter, to add a type field on serialization which would be used on deserialization to deserialize to the correct derived type. Basically the same concept as TypeNameHandling.All in newtonsoft. Which brings me to my first question - is it possible to use newtonsoft instead of system.text.json? I have defined a stream that has all the permutations of possible columns, including the ClassName field. I think using the json converter I can get it to deserialize properly, but the issue I'm having is actually on save. I have a list of IDomainEvents which I save to the stream with this code:
However when it gets persisted, only the columns on the IDomainEvent interface are persisted. It never goes through my json converter until it deserializes. Is there a way to write the actual instance instead of just the IDomainEvent fields? I could do it through a kafka producer, but I was hoping to do it through this library. Example stream schema:
Example inheritance structure:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Hi @jhoward321, In your case it shouldn't matter because the insertion of records ( I spotted a possible issue. In your case you are using a record field (named ExtraField) so I added support for them too. The library extracted values only from properties up to this time. By default the insert statement is generated from public instance props and fields.
You can try to explore the generated insert statement as described here. I published the package with the above mentioned improvement:
Let me know if it helped you to progress with your PoC. In case that it didn't help I would like to ask you to extend your example with the underlying class for Thank you very much! Regards Tomas. |
Beta Was this translation helpful? Give feedback.
-
Thank you @jhoward321 for the details. Now I understand what was the missing part in my understanding. Could you please review this commit, please? The generated Insert statement in the provided unit test is the following:
This should cover your use case where you are providing an interface. |
Beta Was this translation helpful? Give feedback.
-
Good point regarding the breaking change. Thx for mentioning it. Is |
Beta Was this translation helpful? Give feedback.
-
Here is the commit log from our new iteration. In case that you will confirm me that the rc-3 works properly I will publish you a release. It will contain also the |
Beta Was this translation helpful? Give feedback.
Here is the commit log from our new iteration.
In case that you will confirm me that the rc-3 works properly I will publish you a release. It will contain also the
InsertProperties.UseInstanceType
config.