Skip to content
/ comque Public

Comque is a .NET command query execution library using the mediator pattern.

License

Notifications You must be signed in to change notification settings

RonaldV/comque

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comque

Comque is a .NET command query execution library using the mediator pattern. It is a PCL library so it can be used in most platforms.

A nuget package is available.

Examples

Query

public class GetHelloName : IQuery<string>
{
    public string Name { get; set; }
}

Query handler

public class GetHelloNameHandler : IQueryHandler<GetHelloName, string>
{
    public string Handle(GetHelloName query)
    {
        return string.Format("Hello {0}!", query.Name);
    }
}

Async query handler

public class GetHelloNameAsyncHandler : IAsyncQueryHandler<GetHelloName, string>
{
    public async Task<string> HandleAsync(GetHelloName query)
    {
        // await some long running process
        return string.Format("Hello {0}!", query.Name);
    }
}

Query execution

// Synchronous
var message = mediator.Execute(new GetHelloName { Name = "world" });

// Asynchronous
var message = await mediator.ExecuteAsync(new GetHelloName { Name = "world" });

Command

public class WriteToConsole : ICommand
{
    public string Message { get; set; }
}

Command handler

Needed for synchronous execution

public class WriteToConsoleHandler : ICommandHandler<WriteToConsole, Result>
{
    public Result Handle(WriteToConsole command)
    {
        Console.WriteLine(command.Message);
      
        return Result.Success();
    }
}

Async command handler

Needed for asynchronous execution

public class WriteToConsoleAsyncHandler : IAsyncCommandHandler<WriteToConsole, Result>
{
    public async Task<Result> HandleAsync(WriteToConsole command)
    {
        // await some long running process
        Console.WriteLine(command.Message);
        
        return Result.Success();
    }
}

Command execution

// Synchronous
mediator.Execute(new WriteToConsole { Message = message });

// Asynchronous
await mediator.ExecuteAsync(new WriteToConsole { Message = message });

About

Comque is a .NET command query execution library using the mediator pattern.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published