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

Using multiple constructors in the aggregate #194

Open
mehdihadeli opened this issue Dec 28, 2022 · 0 comments
Open

Using multiple constructors in the aggregate #194

mehdihadeli opened this issue Dec 28, 2022 · 0 comments

Comments

@mehdihadeli
Copy link

mehdihadeli commented Dec 28, 2022

Hi Oskar,
I have a question about this private constructor in th Order.

    private Order(Guid id, Guid clientId, IReadOnlyList<PricedProductItem> productItems, decimal totalPrice)
    {
        var @event = OrderInitialized.Create(
            id,
            clientId,
            productItems,
            totalPrice,
            DateTime.UtcNow
        );

        Enqueue(@event);
        Apply(@event);
    }

Why do you need this constructor? We can just call this functionality inner Initialize static method, like below code and remove this parameters constructor:

    public static Order Initialize(
        Guid orderId,
        Guid clientId,
        IReadOnlyList<PricedProductItem> productItems,
        decimal totalPrice)
    {
        var order = new Order();

        var @event = OrderInitialized.Create(
            id,
            clientId,
            productItems,
            totalPrice,
            DateTime.UtcNow
        );

        order.Enqueue(@event);
        order.Apply(@event);

        return order;
    }

It is less code :D

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