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

Commit

Permalink
Merge #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Briguglia committed Nov 15, 2019
2 parents 8430590 + 5058020 commit 14b2ca5
Show file tree
Hide file tree
Showing 97 changed files with 990 additions and 273 deletions.
33 changes: 33 additions & 0 deletions Kledex.sln
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kledex.UI", "src\Kledex.UI\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kledex.Validation.FluentValidation", "src\Kledex.Validation.FluentValidation\Kledex.Validation.FluentValidation.csproj", "{EC89F18E-266A-4C33-8E70-9F3AB331BB6C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kledex.Caching.Memory", "src\Kledex.Caching.Memory\Kledex.Caching.Memory.csproj", "{4AA061EE-6DBE-464B-B467-08BDA68D9F40}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kledex.Caching.Redis", "src\Kledex.Caching.Redis\Kledex.Caching.Redis.csproj", "{60755BA7-4F80-4AEC-8B0E-32414C1C6553}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{1282A8FB-D7A5-4562-8B9B-1C27B83EE580}"
ProjectSection(SolutionItems) = preProject
docs\Basics.md = docs\Basics.md
docs\Caching.md = docs\Caching.md
docs\Commands.md = docs\Commands.md
docs\Configuration.md = docs\Configuration.md
docs\Domain.md = docs\Domain.md
docs\Events.md = docs\Events.md
docs\index.md = docs\index.md
docs\Installation.md = docs\Installation.md
docs\Message-Bus.md = docs\Message-Bus.md
docs\Queries.md = docs\Queries.md
docs\Release-Notes.md = docs\Release-Notes.md
docs\Samples.md = docs\Samples.md
docs\Validation.md = docs\Validation.md
docs\With-Event-Sourcing.md = docs\With-Event-Sourcing.md
docs\Without-Event-Sourcing.md = docs\Without-Event-Sourcing.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -134,6 +157,14 @@ Global
{EC89F18E-266A-4C33-8E70-9F3AB331BB6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC89F18E-266A-4C33-8E70-9F3AB331BB6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC89F18E-266A-4C33-8E70-9F3AB331BB6C}.Release|Any CPU.Build.0 = Release|Any CPU
{4AA061EE-6DBE-464B-B467-08BDA68D9F40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AA061EE-6DBE-464B-B467-08BDA68D9F40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AA061EE-6DBE-464B-B467-08BDA68D9F40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AA061EE-6DBE-464B-B467-08BDA68D9F40}.Release|Any CPU.Build.0 = Release|Any CPU
{60755BA7-4F80-4AEC-8B0E-32414C1C6553}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60755BA7-4F80-4AEC-8B0E-32414C1C6553}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60755BA7-4F80-4AEC-8B0E-32414C1C6553}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60755BA7-4F80-4AEC-8B0E-32414C1C6553}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -156,6 +187,8 @@ Global
{99E0EA26-E961-40A1-A580-BCB255B37838} = {FF129AB8-1B8D-4BAA-AB1F-39D2FA497397}
{698A5F31-4E71-46EF-A93F-8B80AAA62F77} = {A9692D21-8091-4A3F-8F7C-54B821EFDF97}
{EC89F18E-266A-4C33-8E70-9F3AB331BB6C} = {A9692D21-8091-4A3F-8F7C-54B821EFDF97}
{4AA061EE-6DBE-464B-B467-08BDA68D9F40} = {A9692D21-8091-4A3F-8F7C-54B821EFDF97}
{60755BA7-4F80-4AEC-8B0E-32414C1C6553} = {A9692D21-8091-4A3F-8F7C-54B821EFDF97}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {154500C3-9A83-4F15-9D78-E1C285AD80AE}
Expand Down
74 changes: 23 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,27 @@

[![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 (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.
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.
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-2.1.0-blue.svg)](https://www.nuget.org/packages/Kledex)

### Storage

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

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

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

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

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

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

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

### Bus

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

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

### Validation

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

## Samples

Run the sample web projects to view how Kledex works and how it produces the same results with or without using event sourcing. The sample web applications use an experimental Kledex.UI package that returns a DTO containing the aggregate model with all events.

The following is a list of products created using the sample web application:

![List](https://github.com/lucabriguglia/Kledex/blob/master/docs/images/list.PNG)

And this is a detailed view of a product with all associated events:

![Product](https://github.com/lucabriguglia/Kledex/blob/master/docs/images/product.PNG)

## Resources

- [Wiki](https://github.com/lucabriguglia/Kledex/wiki)
- [Roadmap](https://github.com/lucabriguglia/Kledex/wiki/Roadmap)
With Kledex you can automatically dispatch events to a message bus (Service Bus or RabbitMQ), validate your commands before they are sent to the command handler and automatically cache the result of your queries (Memory or Redis).

**Full Documentation**: [https://lucabriguglia.github.io/Kledex](https://lucabriguglia.github.io/Kledex)

## Packages

| Package | Latest Stable |
| --- | --- |
| [Kledex](https://www.nuget.org/packages/Kledex) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex) |
| [Kledex.Store.Cosmos.Mongo](https://www.nuget.org/packages/Kledex.Store.Cosmos.Mongo) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.Cosmos.Mongo) |
| [Kledex.Store.Cosmos.Sql](https://www.nuget.org/packages/Kledex.Store.Cosmos.Sql) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.Cosmos.Sql) |
| [Kledex.Store.EF.MySql](https://www.nuget.org/packages/Kledex.Store.EF.MySql) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.MySql) |
| [Kledex.Store.EF.PostgreSql](https://www.nuget.org/packages/Kledex.Store.EF.PostgreSql) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.PostgreSql) |
| [Kledex.Store.EF.Sqlite](https://www.nuget.org/packages/Kledex.Store.EF.Sqlite) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.Sqlite) |
| [Kledex.Store.EF.SqlServer](https://www.nuget.org/packages/Kledex.Store.EF.SqlServer) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.SqlServer) |
| [Kledex.Store.EF.InMemory](https://www.nuget.org/packages/Kledex.Store.EF.InMemory) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Store.EF.InMemory) |
| [Kledex.Bus.ServiceBus](https://www.nuget.org/packages/Kledex.Bus.ServiceBus) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Bus.ServiceBus) |
| [Kledex.Bus.RabbitMQ](https://www.nuget.org/packages/Kledex.Bus.RabbitMQ) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Bus.RabbitMQ) |
| [Kledex.Validation.FluentValidation](https://www.nuget.org/packages/Kledex.Validation.FluentValidation) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Validation.FluentValidation) |
| [Kledex.Caching.Memory](https://www.nuget.org/packages/Kledex.Caching.Memory) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Caching.Memory) |
| [Kledex.Caching.Redis](https://www.nuget.org/packages/Kledex.Caching.Redis) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.Caching.Redis) |
| [Kledex.UI](https://www.nuget.org/packages/Kledex.UI) | [![Nuget Package](https://img.shields.io/badge/nuget-2.2.0-blue.svg)](https://www.nuget.org/packages/Kledex.UI) |
13 changes: 10 additions & 3 deletions docs/Basics.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# Basic

There is a single interface to use, **IDispatcher** in Kledex namespace.
Note that all handlers are available as asynchronous as well as synchronous.
The **IDispatcher** interface contains all the methods needed to send commands, publish events and get results from queries.

The **IRepository<T>** interface can be used to load an aggregate from history by replaying all the associated events.

Note that all methods and handlers are available as asynchronous as well as synchronous.

There are 3 kinds of messages:
- [Commands](https://github.com/lucabriguglia/Kledex/wiki/Commands) (single handler)
- [Events](https://github.com/lucabriguglia/Kledex/wiki/Events) (multiple handlers)
- [Queries](https://github.com/lucabriguglia/Kledex/wiki/Queries) (single handler)

Mapping between dispatcher methods and message handlers:
Mapping between dispatcher methods and handlers:

| Method | Handler |
| --- | --- |
| SendAsync | ICommandHandlerAsync |
| PublishAsync | IEventHandlerAsync |
| GetResultAsync | IQueryHandlerAsync |

It's also possible to use the following interfaces directly without going through the framework flows:
- ICacheManager
- IValidationService
4 changes: 2 additions & 2 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ services
<a name="caching"></a>
### Caching

...
Add a caching provider if you want the result of your queries to be automatically cached:

| Package | Method |
| --- | --- |
Expand All @@ -169,7 +169,7 @@ services
<a name="ui"></a>
### UI

...
Experimental package to get a view of an aggregate and all associated events:

```C#
services
Expand Down
31 changes: 2 additions & 29 deletions docs/Release-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Kledex 2.2
_**Released ??/??/2019**_
- Cache Manager
- Change configuration
- Changes to configuration

## Kledex 2.1
_**Released 11/11/2019**_
Expand All @@ -28,31 +28,4 @@ _**Released 18/07/2019**_

## Kledex 1.0
_**Released 25/05/2019**_
Identical to OpenCQRS 6.1 but re-branded.

## OpenCQRS 6.1
_**Released 06/05/2019**_
- Event type mapper configuration in startup
- Support for RabbitMQ

## OpenCQRS 6.0
_**Released 23/03/2019**_
- Optional command saving
- IDispatcher refactoring
- Add aggregate store

## OpenCQRS 5.3
_**Released 22/09/2018**_
- Add in memory data provider

## OpenCQRS 5.2
_**Released 18/08/2018**_
- Add expected version to domain commands

## OpenCQRS 5.1
_**Released 09/08/2018**_
- Add Topics to Azure Service Bus plugin

## OpenCQRS 5.0
_**Released 21/07/2018**_
- Azure Service Bus Integration (Queues only)
- Initial release
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Kledex

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.
Its advanced features are ideal for Domain Driven Design (DDD), Command Query Responsibilty Segragation (CQRS) and Event Sourcing.
With Kledex you can automatically dispatch events to a message bus (Service Bus or RabbitMQ), validate your commands before they are sent to the command handler and automatically cache the result of your queries (Memory or Redis).

- [Installation](Installation)
- [Configuration](Configuration)
- [Basics](Basics)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Kledex.Bus.ServiceBus\Kledex.Bus.ServiceBus.csproj" />
<ProjectReference Include="..\..\src\Kledex.Caching.Memory\Kledex.Caching.Memory.csproj" />
<ProjectReference Include="..\..\src\Kledex.Caching.Redis\Kledex.Caching.Redis.csproj" />
<ProjectReference Include="..\..\src\Kledex.Store.Cosmos.Sql\Kledex.Store.Cosmos.Sql.csproj" />
<ProjectReference Include="..\..\src\Kledex.Store.EF.SqlServer\Kledex.Store.EF.SqlServer.csproj" />
<ProjectReference Include="..\..\src\Kledex.UI\Kledex.UI.csproj" />
Expand Down
7 changes: 7 additions & 0 deletions samples/Kledex.Sample.EventSourcing/Reporting/CacheKeys.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Kledex.Sample.EventSourcing.Reporting
{
public static class CacheKeys
{
public static string ProductsCacheKey = "Kledex | Products";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Threading.Tasks;
using Kledex.Caching;
using Kledex.Events;
using Kledex.Sample.EventSourcing.Domain.Events;

namespace Kledex.Sample.EventSourcing.Reporting.EventHandlers
{
public class EventHandlersForCaching :
IEventHandlerAsync<ProductCreated>,
IEventHandlerAsync<ProductDeleted>,
IEventHandlerAsync<ProductPublished>,
IEventHandlerAsync<ProductUpdated>,
IEventHandlerAsync<ProductWithdrew>
{
private readonly ICacheManager _cacheManager;

public EventHandlersForCaching(ICacheManager cacheManager)
{
_cacheManager = cacheManager;
}

public Task HandleAsync(ProductCreated @event)
{
return RemoveCacheAsync();
}

public Task HandleAsync(ProductDeleted @event)
{
return RemoveCacheAsync();
}

public Task HandleAsync(ProductPublished @event)
{
return RemoveCacheAsync();
}

public Task HandleAsync(ProductUpdated @event)
{
return RemoveCacheAsync();
}

public Task HandleAsync(ProductWithdrew @event)
{
return RemoveCacheAsync();
}

private Task RemoveCacheAsync()
{
return _cacheManager.RemoveAsync(CacheKeys.ProductsCacheKey);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Kledex.Caching;
using Kledex.Events;
using Kledex.Sample.EventSourcing.Domain.Events;
using Kledex.Sample.EventSourcing.Reporting.Data;
Expand All @@ -8,10 +9,12 @@ namespace Kledex.Sample.EventSourcing.Reporting.EventHandlers
public class ProductCreatedHandler : IEventHandlerAsync<ProductCreated>
{
private readonly ReportingDbContext _dbContext;
private readonly ICacheManager _cacheManager;

public ProductCreatedHandler(ReportingDbContext dbContext)
public ProductCreatedHandler(ReportingDbContext dbContext, ICacheManager cacheManager)
{
_dbContext = dbContext;
_cacheManager = cacheManager;
}

public async Task HandleAsync(ProductCreated @event)
Expand All @@ -26,6 +29,8 @@ public async Task HandleAsync(ProductCreated @event)
});

await _dbContext.SaveChangesAsync();

await _cacheManager.RemoveAsync(CacheKeys.ProductsCacheKey);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Kledex.Sample.EventSourcing.Reporting.Queries
{
public class GetAllProducts : IQuery<IList<ProductEntity>>
public class GetAllProducts : Query<IList<ProductEntity>>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Kledex.Sample.EventSourcing.Reporting.Queries
{
public class GetProduct : IQuery<ProductEntity>
public class GetProduct : Query<ProductEntity>
{
public Guid ProductId { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

namespace Kledex.Sample.EventSourcing.Reporting.Queries
{
public class GetProducts : IQuery<IList<ProductEntity>>
public class GetProducts : CacheableQuery<IList<ProductEntity>>
{
public GetProducts()
{
CacheKey = CacheKeys.ProductsCacheKey;
CacheTime = 10;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Kledex.Sample.EventSourcing.Reporting.Queries
{
public class GetPublishedProducts : IQuery<IEnumerable<ProductEntity>>
public class GetPublishedProducts : Query<IEnumerable<ProductEntity>>
{
}
}
Loading

0 comments on commit 14b2ca5

Please sign in to comment.