Coder Social home page Coder Social logo

Comments (2)

kgrzybek avatar kgrzybek commented on May 21, 2024 9

Thank you for question @jgozner !

Firstly, let me quote nice explanation what policy is (from https://developer.ibm.com/technologies/java/tutorials/reactive-in-practice-1/):

Reactions (also known as policies) help to model system-initiated commands in response to events happening. For instance, we may want to initiate a command when something else happens. It’s this ‘when, then‘ notation that makes reactions very handy to use in modelling workshops. By convention, reactions are represented using lavender sticky notes. We can insert them between an event or a command, which makes it easy to model policies, with multiple commands being triggered from one event, or to attach the lavender sticky directly to a command, where a policy only has a single command associated with it.

Answering your question, in my opinion: policy logic should be placed in Event Handler when it is simple. When the logic is complex, this logic should be placed in your Domain (for example in Domain Service) and Event Handler should only delegate and coordinate this process.

There is one example of this very easy logic policy in this project:

  • Given Attendee is added to Meeting
  • When Fee is not empty
  • Then create a Meeting Payment
internal class MeetingAttendeeAddedIntegrationEventHandler : INotificationHandler<MeetingAttendeeAddedIntegrationEvent>
{
    private readonly ICommandsScheduler _commandsScheduler;

    internal MeetingAttendeeAddedIntegrationEventHandler(ICommandsScheduler commandsScheduler)
    {
        _commandsScheduler = commandsScheduler;
    }

    public async Task Handle(MeetingAttendeeAddedIntegrationEvent notification, CancellationToken cancellationToken)
    {
        if (notification.FeeValue.HasValue)
        {
            await _commandsScheduler.EnqueueAsync(new CreateMeetingPaymentCommand(
                Guid.NewGuid(),
                new PayerId(notification.AttendeeId), 
                new MeetingId(notification.MeetingId),
                notification.FeeValue.Value, 
                notification.FeeCurrency));
        }
    }
}

from modular-monolith-with-ddd.

jgozner avatar jgozner commented on May 21, 2024

That makes so much sense! Thanks for taking the time to reply and explain that :)

from modular-monolith-with-ddd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.