meteor-space / event-sourcing

CQRS and Event Sourcing Infrastructure for Meteor.
MIT License
63 stars 9 forks source link

Standardize way to map fields on DDD elements #48

Open qejk opened 8 years ago

qejk commented 8 years ago

Currently, there are two ways to map(describe) fields in DDD elements - via methods and objects:

We should have standardized way to map fields, so there is no confusion what type of mapping we need to use on each DDD element and how to access them everywhere(this is very important). Another option is to allow both mappings (by doing in every place where its needed - a check for fn/object and acting accordingly) however by doing so - this can be confusing on long run.

By allowing objects were supporting extensibility, but the cost of confusion that you can extend anything from anywhere easily like that can let to bad design choices in developers code.

rhyslbw commented 8 years ago

I have a feeling we need to use a method for objects that are extended from Space.Struct including Entity and ValueObject. @DominikGuzei is that right?

rhyslbw commented 8 years ago

Also need to consider if this backwards compatibility class should be removed now, freeing up the mixin to be named `Space.messaging.Serializable'

DominikGuzei commented 8 years ago

We just have to mixin Space.messaging.SerializableMixin into Space.eventSourcing.Aggregate and update the internal code so that it uses the fields method instead. The switch to remove the compatibilitty class is a bit bigger and needs careful consideration.

rhyslbw commented 8 years ago

Consideration for upgrade path, or internal? Right now it's a little disjointed as we have an extended object that's really suited to being a trait that's added via a mixin, so can't use the obvious name in the current API.

DominikGuzei commented 8 years ago

We just have to check where it is used and update all places :wink:

rhyslbw commented 8 years ago

If that's the only issue I'd suggest we proceed with that. I can do it this evening so we can release messaging without a delay. Now is the time for breaking things if there's a good reason :smile:

@qejk Thoughts?

DominikGuzei commented 8 years ago

Haha, yeah it seems like it's never a good time to break things :wink: but yes, let's do that.

qejk commented 8 years ago

Yes! Like we spoke @DominikGuzei Aggregates/Processes also should be serializable Space.messaging.SerializableMixin. This will bring very niffty concept later for interacting with app layer if will start adding Repositories to the mix. Long story short:

We store on MongoDB our Aggregate via Repository (not the one from ES, related to storing our domain part via projections) and there use toData().

Then afterwards, when we need to talk with persistence (via find/findOne etc) and need whole/partial document - we recreate it with toData() and again we can interact with it normally like with EJSON's one (and still preserve sanity in doc structure yey).

IMPORTANT: will it work for partial data that have mappings in fields as non Match.Optional(so required)?

rhyslbw commented 8 years ago

FYI the mixin is now named Space.messaging.Ejsonable since it's a hard implementation for EJSON.

IMPORTANT: will it work for partial data that have mappings in fields as non Match.Optional(so required)?

If I'm understanding correctly, yes since it's all based on your match statement per field.

darko-mijic commented 8 years ago

Are we sure we want to refactor Space.messaging.Command and Space.messaging.Event also?

DominikGuzei commented 8 years ago

It's not so much about refactoring the names of the classes but splitting up the domain related parts (sourceId, timestamp, targetId etc.) into a separate Space.domain.Event / Command class.

rhyslbw commented 8 years ago

Ok so I agree here that switching the fields prop on Aggregate to a method makes sense, but we should retain the ability in the style to use an object for fields in a define static method.

DominikGuzei commented 8 years ago

define static method? you mean like Space.messaging.define?

rhyslbw commented 8 years ago

@DominikGuzei Yep, but as you pointed out in Slack, we could support object field props, which is better

DominikGuzei commented 8 years ago

Yep, that's definitely an option. This would be an issue for people using ES6 / CS class though.

ghost commented 8 years ago

Yes, please make Aggregate.fields a method for consistency with the rest of space:base and space:domain.