Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge #51 #82 #84 #85
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Briguglia committed Nov 3, 2019
2 parents 92608c8 + 654d202 commit 1f27c7d
Show file tree
Hide file tree
Showing 115 changed files with 1,043 additions and 1,788 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# Kledex (formerly OpenCQRS)
# Kledex

[![Build Status](https://lucabriguglia.visualstudio.com/Kledex/_apis/build/status/lucabriguglia.Kledex?branchName=master)](https://lucabriguglia.visualstudio.com/Kledex/_build/latest?definitionId=1&branchName=master)

Kledex is a .NET Core framework that can be used to create a simple and clean design by enforcing single responsibility and separation of concerns.
Kledex (formerly OpenCQRS) is a .NET Core framework that can be used to create a simple and clean design by enforcing single responsibility and separation of concerns.
Its advanced features are ideal for Domain Driven Design (DDD), Command Query Responsibilty Segragation (CQRS) and Event Sourcing.
Kledex also has Azure Service Bus and RabbitMQ integrations.

## Nuget Packages

### Main

[![Nuget Package](https://img.shields.io/badge/Kledex-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex)
[![Nuget Package](https://img.shields.io/badge/Kledex-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex)

### Storage

[![Nuget Package](https://img.shields.io/badge/Kledex.Store.Cosmos.Mongo-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.Cosmos.Mongo)
[![Nuget Package](https://img.shields.io/badge/Kledex.Store.Cosmos.Mongo-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.Cosmos.Mongo)

[![Nuget Package](https://img.shields.io/badge/Kledex.Store.Cosmos.Sql-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.Cosmos.Sql)
[![Nuget Package](https://img.shields.io/badge/Kledex.Store.Cosmos.Sql-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.Cosmos.Sql)

[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.MySql-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.MySql)
[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.MySql-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.MySql)

[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.PostgreSql-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.PostgreSql)
[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.PostgreSql-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.PostgreSql)

[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.Sqlite-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.Sqlite)
[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.Sqlite-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.Sqlite)

[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.SqlServer-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.SqlServer)
[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.SqlServer-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.SqlServer)

[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.InMemory-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.InMemory)
[![Nuget Package](https://img.shields.io/badge/Kledex.Store.EF.InMemory-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.InMemory)

### Bus

[![Nuget Package](https://img.shields.io/badge/Kledex.Bus.ServiceBus-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Bus.ServiceBus)
[![Nuget Package](https://img.shields.io/badge/Kledex.Bus.ServiceBus-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex.Bus.ServiceBus)

[![Nuget Package](https://img.shields.io/badge/Kledex.Bus.RabbitMQ-1.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Bus.RabbitMQ)
[![Nuget Package](https://img.shields.io/badge/Kledex.Bus.RabbitMQ-2.0.0-blue.svg)](https://www.nuget.org/packages/Kledex.Bus.RabbitMQ)

## Samples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Kledex.Sample.EventSourcing.Domain.Commands
{
public class CreateProduct : DomainCommand
public class CreateProduct : DomainCommand<Product>
{
public string Name { get; set; }
public string Description { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Kledex.Sample.EventSourcing.Domain.Commands
{
public class DeleteProduct : DomainCommand
public class DeleteProduct : DomainCommand<Product>
{
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Kledex.Domain;
using System.Threading.Tasks;
using Kledex.Commands;

namespace Kledex.Sample.EventSourcing.Domain.Commands.Handlers
{
public class CreateProductHandler : IDomainCommandHandlerAsync<CreateProduct>
public class CreateProductHandler : ICommandHandlerAsync<CreateProduct>
{
private readonly IRepository<Product> _repository;

public CreateProductHandler(IRepository<Product> repository)
{
_repository = repository;
}

public async Task<IEnumerable<IDomainEvent>> HandleAsync(CreateProduct command)
public async Task<CommandResponse> HandleAsync(CreateProduct command)
{
var product = new Product(command.AggregateRootId, command.Name, command.Description, command.Price);

return await Task.FromResult(product.Events);
return await Task.FromResult(new CommandResponse
{
Events = product.Events,
Result = true
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Kledex.Commands;
using Kledex.Domain;

namespace Kledex.Sample.EventSourcing.Domain.Commands.Handlers
{
public class DeleteProductHandler : IDomainCommandHandlerAsync<DeleteProduct>
public class DeleteProductHandler : ICommandHandlerAsync<DeleteProduct>
{
private readonly IRepository<Product> _repository;

Expand All @@ -14,7 +14,7 @@ public DeleteProductHandler(IRepository<Product> repository)
_repository = repository;
}

public async Task<IEnumerable<IDomainEvent>> HandleAsync(DeleteProduct command)
public async Task<CommandResponse> HandleAsync(DeleteProduct command)
{
var product = await _repository.GetByIdAsync(command.AggregateRootId);

Expand All @@ -25,7 +25,10 @@ public async Task<IEnumerable<IDomainEvent>> HandleAsync(DeleteProduct command)

product.Delete();

return product.Events;
return new CommandResponse
{
Events = product.Events
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Kledex.Commands;
using Kledex.Domain;

namespace Kledex.Sample.EventSourcing.Domain.Commands.Handlers
{
public class PublishProductHandler : IDomainCommandHandlerAsync<PublishProduct>
public class PublishProductHandler : ICommandHandlerAsync<PublishProduct>
{
private readonly IRepository<Product> _repository;

Expand All @@ -14,7 +14,7 @@ public PublishProductHandler(IRepository<Product> repository)
_repository = repository;
}

public async Task<IEnumerable<IDomainEvent>> HandleAsync(PublishProduct command)
public async Task<CommandResponse> HandleAsync(PublishProduct command)
{
var product = await _repository.GetByIdAsync(command.AggregateRootId);

Expand All @@ -25,7 +25,10 @@ public async Task<IEnumerable<IDomainEvent>> HandleAsync(PublishProduct command)

product.Publish();

return product.Events;
return new CommandResponse
{
Events = product.Events
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Kledex.Commands;
using Kledex.Domain;

namespace Kledex.Sample.EventSourcing.Domain.Commands.Handlers
{
public class UpdateProductHandler : IDomainCommandHandlerAsync<UpdateProduct>
public class UpdateProductHandler : ICommandHandlerAsync<UpdateProduct>
{
private readonly IRepository<Product> _repository;

Expand All @@ -14,7 +14,7 @@ public UpdateProductHandler(IRepository<Product> repository)
_repository = repository;
}

public async Task<IEnumerable<IDomainEvent>> HandleAsync(UpdateProduct command)
public async Task<CommandResponse> HandleAsync(UpdateProduct command)
{
var product = await _repository.GetByIdAsync(command.AggregateRootId);

Expand All @@ -25,7 +25,10 @@ public async Task<IEnumerable<IDomainEvent>> HandleAsync(UpdateProduct command)

product.Update(command.Name, command.Description, command.Price);

return product.Events;
return new CommandResponse
{
Events = product.Events
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Kledex.Commands;
using Kledex.Domain;

namespace Kledex.Sample.EventSourcing.Domain.Commands.Handlers
{
public class WithdrawProductHandler : IDomainCommandHandlerAsync<WithdrawProduct>
public class WithdrawProductHandler : ICommandHandlerAsync<WithdrawProduct>
{
private readonly IRepository<Product> _repository;

Expand All @@ -14,7 +14,7 @@ public WithdrawProductHandler(IRepository<Product> repository)
_repository = repository;
}

public async Task<IEnumerable<IDomainEvent>> HandleAsync(WithdrawProduct command)
public async Task<CommandResponse> HandleAsync(WithdrawProduct command)
{
var product = await _repository.GetByIdAsync(command.AggregateRootId);

Expand All @@ -25,7 +25,10 @@ public async Task<IEnumerable<IDomainEvent>> HandleAsync(WithdrawProduct command

product.Withdraw();

return product.Events;
return new CommandResponse
{
Events = product.Events
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Kledex.Sample.EventSourcing.Domain.Commands
{
public class PublishProduct : DomainCommand
public class PublishProduct : DomainCommand<Product>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Kledex.Sample.EventSourcing.Domain.Commands
{
public class UpdateProduct : DomainCommand
public class UpdateProduct : DomainCommand<Product>
{
public string Name { get; set; }
public string Description { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Kledex.Sample.EventSourcing.Domain.Commands
{
public class WithdrawProduct : DomainCommand
public class WithdrawProduct : DomainCommand<Product>
{
}
}
3 changes: 1 addition & 2 deletions samples/Kledex.Sample.EventSourcing/Pages/Create.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Kledex.Sample.EventSourcing.Domain;
using Kledex.Sample.EventSourcing.Domain.Commands;
using Kledex.Sample.EventSourcing.Reporting.Data;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -28,7 +27,7 @@ public async Task<IActionResult> OnPostAsync()
Price = Product.Price
};

await _dispatcher.SendAsync<CreateProduct, Product>(command);
await _dispatcher.SendAsync(command);

return RedirectToPage("/List");
}
Expand Down
3 changes: 1 addition & 2 deletions samples/Kledex.Sample.EventSourcing/Pages/Edit.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using Kledex.Sample.EventSourcing.Domain;
using Kledex.Sample.EventSourcing.Domain.Commands;
using Kledex.Sample.EventSourcing.Reporting.Data;
using Kledex.Sample.EventSourcing.Reporting.Queries;
Expand Down Expand Up @@ -50,7 +49,7 @@ public async Task<IActionResult> OnPostAsync(Guid id)
Price = Product.Price
};

await _dispatcher.SendAsync<UpdateProduct, Product>(command);
await _dispatcher.SendAsync(command);

return RedirectToPage("./Edit", new { id });
}
Expand Down
2 changes: 1 addition & 1 deletion samples/Kledex.Sample.EventSourcing/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

<p>
In this sample project the domain data is stored in a SQLServer database without using event sourcing and the domain data (aggregates, commands and events) is stored in a CosmosDB with SQL API.
In this sample project the domain data is stored in a CosmosDB database using event sourcing and the read model is stored in a SQL Server database.
</p>

<p>
Expand Down
7 changes: 3 additions & 4 deletions samples/Kledex.Sample.EventSourcing/Pages/List.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Kledex.Sample.EventSourcing.Domain;
using Kledex.Sample.EventSourcing.Domain.Commands;
using Kledex.Sample.EventSourcing.Reporting.Data;
using Kledex.Sample.EventSourcing.Reporting.Queries;
Expand Down Expand Up @@ -34,7 +33,7 @@ public async Task<IActionResult> OnPostDeleteAsync(Guid id)
AggregateRootId = id
};

await _dispatcher.SendAsync<DeleteProduct, Product>(command);
await _dispatcher.SendAsync(command);

return RedirectToPage();
}
Expand All @@ -46,7 +45,7 @@ public async Task<IActionResult> OnPostPublishAsync(Guid id)
AggregateRootId = id
};

await _dispatcher.SendAsync<PublishProduct, Product>(command);
await _dispatcher.SendAsync(command);

return RedirectToPage();
}
Expand All @@ -58,7 +57,7 @@ public async Task<IActionResult> OnPostWithdrawAsync(Guid id)
AggregateRootId = id
};

await _dispatcher.SendAsync<WithdrawProduct, Product>(command);
await _dispatcher.SendAsync(command);

return RedirectToPage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Kledex.Sample.EventSourcing.Reporting.Data
{
public class ReportingDbContext : DbContext
{
public ReportingDbContext(DbContextOptions options)
public ReportingDbContext(DbContextOptions<ReportingDbContext> options)
: base(options)
{
}
Expand Down
8 changes: 8 additions & 0 deletions samples/Kledex.Sample.EventSourcing/Services/EmailSent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Kledex.Events;

namespace Kledex.Sample.EventSourcing.Services
{
public class EmailSent : Event
{
}
}
8 changes: 8 additions & 0 deletions samples/Kledex.Sample.EventSourcing/Services/SendEmail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Kledex.Commands;

namespace Kledex.Sample.EventSourcing.Services
{
public class SendEmail : Command
{
}
}
21 changes: 21 additions & 0 deletions samples/Kledex.Sample.EventSourcing/Services/SendEmailHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Kledex.Commands;
using Kledex.Events;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Kledex.Sample.EventSourcing.Services
{
public class SendEmailHandler : ICommandHandlerAsync<SendEmail>
{
public Task<CommandResponse> HandleAsync(SendEmail command)
{
return Task.FromResult(new CommandResponse
{
Events = new List<IEvent>()
{
new EmailSent()
}
});
}
}
}
Loading

0 comments on commit 1f27c7d

Please sign in to comment.