예제 #1
0
        // Apply the deltas to mutate our state
        public void Apply(InvoiceCreated @event)
        {
            Id = @event.InvoiceNumber.ToString(CultureInfo.InvariantCulture);

            // Ensure to update version on every Apply method.
            Version++;
        }
예제 #2
0
        public Invoice(int invoiceNumber)
        {
            if (invoiceNumber <= 0)
            {
                throw new ArgumentException("Invoice number needs to be positive", nameof(invoiceNumber));
            }

            // Instantiation creates our initial event, capturing the invoice number
            var @event = new InvoiceCreated(invoiceNumber);

            // Call Apply to mutate state of aggregate based on event
            Apply(@event);

            // Add the event to uncommitted events to use it while persisting the events to Marten events store
            AddUncommittedEvent(@event);
        }
 // Apply the deltas to mutate our state
 private void Apply(InvoiceCreated @event)
 {
     Id = @event.InvoiceNumber.ToString(CultureInfo.InvariantCulture);
 }