A lightweight framework to help creating CQRS and Eventsourcing applications in C#
A lightweight framework to help creating CQRS and Eventsourcing applications in C#
A lightweight CQRS and Event Sourcing framework for .NET
CQRSlite is a small, focused CQRS (Command Query Responsibility Segregation) and Event Sourcing framework for .NET. It provides the essential building blocks for implementing CQRS/ES patterns while maintaining flexibility and pluggability.
Key Characteristics:
CQRSlite originated as a CQRS sample project by Greg Young and Gaute Magnussen in 2010. Original code: http://github.com/gregoryyoung/m-r
dotnet add package CQRSlite// Command
public class CreateProduct : ICommand
{
public Guid Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
// Event
public class ProductCreated : IEvent
{
public Guid Id { get; set; }
public int Version { get; set; }
public DateTimeOffset TimeStamp { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}public class Product : AggregateRoot
{
private string _name;
private decimal _price;
public Product(Guid id, string name, decimal price)
{
Id = id;
ApplyChange(new ProductCreated(id, name, price));
}
private Product() { } // Required for rehydration
private void Apply(ProductCreated e)
{
_name = e.Name;
_price = e.Price;
}
}public class ProductCommandHandler : ICommandHandler
{
private readonly ISession _session;
public async Task Handle(CreateProduct message)
{
var product = new Product(message.Id, message.Name, message.Price);
await _session.Add(product);
await _session.Commit();
}
}// Register Router
var router = new Router();
services.AddSingleton(router);
services.AddSingleton(router);
services.AddSingleton(router);
services.AddSingleton(router);
// Register core services
services.AddSingleton(); // You must implement this
services.AddScoped(sp => new Repository(sp.GetService()));
services.AddScoped();
// Auto-register handlers
var registrar = new RouteRegistrar(serviceProvider);
registrar.Register(typeof(ProductCommandHandler).Assembly);Great introductions to CQRS and CQRSlite:
You must implement your own IEventStore for persistence. CQRSlite provides the framework but intentionally does not include a default event store implementation, as storage requirements vary greatly between applications.
Example event stores:
See DEVELOPER.md for implementation guidance.
CQRSlite follows clean CQRS/ES principles:
Application Layer
↓
Commands → CommandHandlers → Aggregates → Events → EventStore
↓ ↓
Queries → QueryHandlers → ReadModels ← EventHandlersWrite Side (Commands):
Read Side (Queries):
Contributions are welcome! Please see DEVELOPER.md for guidelines.
Copyright 2020 Gaute Magnussen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
No open issues yet, or sync has not completed.