Skip to content
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

Aggregate Commands may need Deserialize trait #31

Closed
tavakyan opened this issue Oct 6, 2022 · 1 comment
Closed

Aggregate Commands may need Deserialize trait #31

tavakyan opened this issue Oct 6, 2022 · 1 comment

Comments

@tavakyan
Copy link

tavakyan commented Oct 6, 2022

Sending events over channels is possible because DomainEvents can be serialized and deserialized before sending and after receiving.

However, in cases where a command is to be sent, a channel sending and receiving aggregate commands cannot generally be constructed and has to be handled on a case by case basis for each aggregate command type.

One way to fix this is to add a constraint to the Aggregate trait such as:

#[async_trait]
pub trait Aggregate: Default + Serialize + DeserializeOwned + Sync + Send {
    /// Specifies the inbound command used to make changes in the state of the Aggregate.
    type Command: Serialize + DeserializeOwned + fmt::Debug + Sync + Send;
...
}

See #32

@tavakyan
Copy link
Author

tavakyan commented Oct 6, 2022

Actually going to close this because I was missing a simple where clause in the traits I was designing... Just had to do something like

#[async_trait]
pub trait CommandForwarder<A: Aggregate>: Send + Sync {
    async fn forward(&self, cmd: A::Command)
    where
        <A as Aggregate>::Command: Serialize;
}

@tavakyan tavakyan closed this as completed Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant