Skip to content

[question] domain pollution #106

@SpareShade

Description

@SpareShade

Hello @vardius

Thank you for sharing this library, it is very helpful in many regards!

My question is about your choice of appending the metadata in the aggregate itself. Eg.

func (u *User) trackChange(ctx context.Context, event *domain.Event) error {
	var meta domain.EventMetadata
	if i, hasIdentity := identity.FromContext(ctx); hasIdentity {
		meta.Identity = i
	}
	if m, ok := metadata.FromContext(ctx); ok {
		meta.IPAddress = m.IPAddress
		meta.UserAgent = m.UserAgent
		meta.Referer = m.Referer
	}
	if !meta.IsEmpty() {
		event.WithMetadata(&meta)
	}

	u.changes = append(u.changes, event)
	u.version++

	return nil
}

Seeing the UserAgent or IP exposed in the aggregate feels a bit like pollution of a domain with application/infra data.
I understand that the aggregate essentially proxies this data from the command handler, which usually is acceptable practice, as aggregate is not making use of that data.

I am wondering if you would not mind sharing your thoughts as to why you chose to enrich the event in the aggregate as opposed to eg. in the aggregate repository implementation.

Thanks again for sharing!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions