Skip to content

CrisBogucki/.NET-Core-Api-with-CQRS

Repository files navigation

Events Core Api with CQRS

Segregation with events, comands and queries

Using Command

add command bus in constructor use dependency inject

private readonly ICommandBus commandBus;

public MyController(ICommandBus commandBus)
{
    this.commandBus = commandBus;
}

method using by async

public async Task RunCommandAsync()
{
    MessageCommand _msg = new MessageCommand() { ... };
    this.commandBus.SendCommandAsync(_msg);
}

or void synchro

public void RunCommand()
{
    MessageCommand _msg = new MessageCommand() { ... };
    this.commandBus.SendCommand(_msg);
}

Using Query

add query bus in constructor use dependency inject

private readonly IQueryBus queryBus;

public MyController(IQueryBus queryBus)
{
    this.queryBus = queryBus;
}

method using by async

public async Task RunQueryAsync()
{
    MessageQuery _msg = new MessageQuery() { ... };
    var result = await this.queryBus.SendQueryAsync(_msg);
}

or void synchro

public void RunQuery()
{
    MessageQuery _msg = new MessageQuery() { ... };
    var result = this.queryBus.SendQuery(_msg);
}

Using Events

add events bus in constructor use dependency inject

private readonly IEventBus eventsBus;

public MyController(IEventBus eventsBus)
{
    this.eventsBus = eventsBus;
}

method using by async

public async Task RunEventsAsync()
{
    MessageEvent _msg = new MessageEvent() { ... };
    await this.eventsBus.PublishEventAsync(msg);
}

or void synchro

public void RunEvents()
{
    MessageEvent _msg = new MessageEvent() { ... };
    this.eventsBus.PublishEvent(msg);
}

About

CQRS - segregation commands

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages