diff --git a/Directory.Build.targets b/Directory.Build.targets
index 31cc06a..fad54dc 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -1,9 +1,9 @@
-
-
- $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))
-
-
-
-
+
+
+ $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))
+
+
+
+
\ No newline at end of file
diff --git a/samples/DFlow.Example/AggregateFactory.cs b/samples/DFlow.Example/AggregateFactory.cs
index 1ca7a9c..ee0eb56 100644
--- a/samples/DFlow.Example/AggregateFactory.cs
+++ b/samples/DFlow.Example/AggregateFactory.cs
@@ -12,7 +12,7 @@ public class AggregateFactory : AggregateFactoryBase
private readonly IEventStore _eventStore;
private readonly long INITIAL_VERSION = 1;
- public AggregateFactory(IEventStore eventStore, ISnapshotRepository snapshotRepository = null)
+ public AggregateFactory(IEventStore eventStore, ISnapshotRepository snapshotRepository = null)
: base(eventStore, snapshotRepository)
{
_eventStore = eventStore;
@@ -26,19 +26,16 @@ public override TAggregate Create()
public override TAggregate Create(Guid id)
{
var existStream = _eventStore.Any(id);
-
- if (existStream)
- {
- throw new DuplicatedRootException(id.ToString());
- }
-
+
+ if (existStream) throw new DuplicatedRootException(id.ToString());
+
var createEvent = new AggregateCreated(id);
- var events = new List() { createEvent};
-
- var stream = new EventStream(){ Version = INITIAL_VERSION, Events = events};
-
- TAggregate aggregate = (TAggregate) Activator.CreateInstance(typeof(TAggregate), new object[] {stream});
-
+ var events = new List { createEvent };
+
+ var stream = new EventStream { Version = INITIAL_VERSION, Events = events };
+
+ var aggregate = (TAggregate)Activator.CreateInstance(typeof(TAggregate), stream);
+
aggregate.Changes.Add(createEvent);
return aggregate;
}
diff --git a/samples/DFlow.Example/Aggregates/ProductCatalogAggregate.cs b/samples/DFlow.Example/Aggregates/ProductCatalogAggregate.cs
index 99f4512..a4971f5 100644
--- a/samples/DFlow.Example/Aggregates/ProductCatalogAggregate.cs
+++ b/samples/DFlow.Example/Aggregates/ProductCatalogAggregate.cs
@@ -3,10 +3,10 @@
using System.Linq;
using DFlow.Base;
using DFlow.Base.Aggregate;
-using DFlow.Interfaces;
using DFlow.Example.Commands;
using DFlow.Example.Entities;
using DFlow.Example.Events;
+using DFlow.Interfaces;
namespace DFlow.Example.Aggregates
{
@@ -18,46 +18,44 @@ public class ProductCatalogAggregate : AggregateRoot
public ProductCatalogAggregate(EventStream stream)
: base(stream)
{
-
}
-
+
public void CreateProduct(CreateProductCommand cmd)
{
- if(!_products.Any(x => x.Id == cmd.Id || x.Name.Equals(cmd.Name)))
+ if (!_products.Any(x => x.Id == cmd.Id || x.Name.Equals(cmd.Name)))
{
var @event = new ProductCreated(cmd.Id, cmd.Name, cmd.Description);
Apply(@event);
Dispatch(@event);
}
}
-
+
public void ChangeProductName(ChangeProductNameCommand cmd)
{
- if(_products.Any(x => x.Id == cmd.ProductId))
+ if (_products.Any(x => x.Id == cmd.ProductId))
{
var @event = new ProductNameChanged(cmd.ProductId, cmd.Name);
Apply(@event);
Dispatch(@event);
}
}
-
+
protected override void Mutate(IEvent e)
{
- ((dynamic) this).When((dynamic)e);
+ ((dynamic)this).When((dynamic)e);
}
-
+
private void When(ProductCreated e)
{
_products.Add(new Product(e.Id, e.Name, e.Description));
-
}
-
+
private void When(ProductNameChanged e)
{
var product = _products.FirstOrDefault(x => x.Id == e.Id);
product.ChangeName(e.Name);
}
-
+
private void When(AggregateCreated e)
{
Id = e.Id;
diff --git a/samples/DFlow.Example/Commands/AddProductCommand.cs b/samples/DFlow.Example/Commands/AddProductCommand.cs
index 701df02..80001cc 100644
--- a/samples/DFlow.Example/Commands/AddProductCommand.cs
+++ b/samples/DFlow.Example/Commands/AddProductCommand.cs
@@ -1,15 +1,10 @@
using System;
-
using DFlow.Interfaces;
namespace DFlow.Example.Commands
{
public class AddProductCommand : ICommand
{
- public Guid OrderId { get; set; }
- public Guid ProductId { get; set; }
- public decimal Qtd { get; set; }
-
public AddProductCommand()
{
}
@@ -20,5 +15,9 @@ public AddProductCommand(Guid orderId, Guid productId, decimal qtd)
ProductId = productId;
Qtd = qtd;
}
+
+ public Guid OrderId { get; set; }
+ public Guid ProductId { get; set; }
+ public decimal Qtd { get; set; }
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/Commands/ChangeProductNameCommand.cs b/samples/DFlow.Example/Commands/ChangeProductNameCommand.cs
index 342c86d..e4da61c 100644
--- a/samples/DFlow.Example/Commands/ChangeProductNameCommand.cs
+++ b/samples/DFlow.Example/Commands/ChangeProductNameCommand.cs
@@ -3,13 +3,8 @@
namespace DFlow.Example.Commands
{
-
public class ChangeProductNameCommand : ICommand
{
- public Guid RootId { get; set; }
- public Guid ProductId { get; set; }
- public string Name { get; set; }
-
public ChangeProductNameCommand(Guid rootId)
{
RootId = rootId;
@@ -21,5 +16,9 @@ public ChangeProductNameCommand(Guid rootId, Guid productId, string name)
Name = name;
RootId = rootId;
}
+
+ public Guid RootId { get; set; }
+ public Guid ProductId { get; set; }
+ public string Name { get; set; }
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/Commands/CreateProductCatalog.cs b/samples/DFlow.Example/Commands/CreateProductCatalog.cs
index 203f4ac..c7d162f 100644
--- a/samples/DFlow.Example/Commands/CreateProductCatalog.cs
+++ b/samples/DFlow.Example/Commands/CreateProductCatalog.cs
@@ -5,14 +5,14 @@ namespace DFlow.Example.Commands
{
public class CreateProductCatalog : ICommand
{
- public Guid Id { get; set; }
-
public CreateProductCatalog(Guid rootId)
{
- if(rootId == Guid.Empty)
+ if (rootId == Guid.Empty)
throw new Exception("não é possível criar catalogos com ID vazio");
Id = rootId;
}
+
+ public Guid Id { get; set; }
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/Commands/CreateProductCommand.cs b/samples/DFlow.Example/Commands/CreateProductCommand.cs
index 36d862f..b8bcd3f 100644
--- a/samples/DFlow.Example/Commands/CreateProductCommand.cs
+++ b/samples/DFlow.Example/Commands/CreateProductCommand.cs
@@ -6,11 +6,6 @@ namespace DFlow.Example.Commands
{
public class CreateProductCommand : ICommand
{
- public Guid RootId { get; set; }
- public Guid Id { get; set; }
- public string Name { get; set; }
- public string Description { get; set; }
-
protected CreateProductCommand(Guid rootId)
{
RootId = rootId;
@@ -18,30 +13,25 @@ protected CreateProductCommand(Guid rootId)
public CreateProductCommand(Guid rootId, Guid id, string name, string description)
{
- if (id == Guid.Empty)
- {
- throw new BusinesException("não é possível criar produtos com ID vazio");
- }
+ if (id == Guid.Empty) throw new BusinesException("não é possível criar produtos com ID vazio");
- if (string.IsNullOrEmpty(name))
- {
- throw new BusinesException("não é possível criar produtos sem nome");
- }
+ if (string.IsNullOrEmpty(name)) throw new BusinesException("não é possível criar produtos sem nome");
if (string.IsNullOrEmpty(description))
- {
throw new BusinesException("não é possível criar produtos sem descrição");
- }
if (rootId == Guid.Empty)
- {
throw new BusinesException("não é possível criar produtos sem adiciona-lo a um cátalogo existente");
- }
-
+
Description = description;
RootId = rootId;
Id = id;
Name = name;
}
+
+ public Guid RootId { get; set; }
+ public Guid Id { get; set; }
+ public string Name { get; set; }
+ public string Description { get; set; }
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/DFlow.Example.csproj b/samples/DFlow.Example/DFlow.Example.csproj
index ec52e81..5af2e58 100644
--- a/samples/DFlow.Example/DFlow.Example.csproj
+++ b/samples/DFlow.Example/DFlow.Example.csproj
@@ -9,19 +9,19 @@
- TRACE;TEST_BUILD
+ TRACE;TEST_BUILD
- true
+ true
-
+
-
+
diff --git a/samples/DFlow.Example/Entities/Product.cs b/samples/DFlow.Example/Entities/Product.cs
index 75da9f9..f04b24c 100644
--- a/samples/DFlow.Example/Entities/Product.cs
+++ b/samples/DFlow.Example/Entities/Product.cs
@@ -13,13 +13,14 @@ public Product(Guid id, string name, string description)
Description = description;
}
+ public string Name { get; private set; }
+ public string Description { get; private set; }
+
+ public Guid Id { get; private set; }
+
public void ChangeName(string name)
{
Name = name;
}
-
- public Guid Id { get; private set; }
- public string Name { get; private set; }
- public string Description { get; private set; }
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/Events/ProductCatalogAggregateCreated.cs b/samples/DFlow.Example/Events/ProductCatalogAggregateCreated.cs
index ab1965f..3735e80 100644
--- a/samples/DFlow.Example/Events/ProductCatalogAggregateCreated.cs
+++ b/samples/DFlow.Example/Events/ProductCatalogAggregateCreated.cs
@@ -1,5 +1,4 @@
using System;
-
using DFlow.Interfaces;
namespace DFlow.Example.Events
@@ -7,11 +6,11 @@ namespace DFlow.Example.Events
[Serializable]
public class ProductCatalogAggregateCreated : IDomainEvent
{
- public Guid Id { get; private set; }
-
public ProductCatalogAggregateCreated(Guid id)
{
Id = id;
}
+
+ public Guid Id { get; private set; }
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/Events/ProductCreated.cs b/samples/DFlow.Example/Events/ProductCreated.cs
index 580cd9c..e14195c 100644
--- a/samples/DFlow.Example/Events/ProductCreated.cs
+++ b/samples/DFlow.Example/Events/ProductCreated.cs
@@ -1,23 +1,20 @@
using System;
-
using DFlow.Interfaces;
-using DFlow.Example.Commands;
namespace DFlow.Example.Events
{
[Serializable]
public class ProductCreated : IDomainEvent
{
- public Guid Id { get; private set; }
- public string Name { get; private set; }
- public string Description { get; private set; }
-
-
public ProductCreated(Guid id, string name, string description)
{
Id = id;
Name = name;
Description = description;
}
+
+ public Guid Id { get; private set; }
+ public string Name { get; private set; }
+ public string Description { get; private set; }
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/Events/ProductNameChanged.cs b/samples/DFlow.Example/Events/ProductNameChanged.cs
index cc52e4b..2c08f1c 100644
--- a/samples/DFlow.Example/Events/ProductNameChanged.cs
+++ b/samples/DFlow.Example/Events/ProductNameChanged.cs
@@ -6,16 +6,16 @@ namespace DFlow.Example.Events
[Serializable]
public class ProductNameChanged : IDomainEvent
{
- public Guid Id { get; private set; }
- public string Name { get; private set; }
-
public ProductNameChanged(Guid id, string name)
{
if (id == Guid.Empty || string.IsNullOrEmpty(name))
throw new Exception("Dados inválidos");
-
+
Id = id;
Name = name;
}
+
+ public Guid Id { get; private set; }
+ public string Name { get; private set; }
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/Exceptions/BusinesException.cs b/samples/DFlow.Example/Exceptions/BusinesException.cs
index 4b749f2..9040158 100644
--- a/samples/DFlow.Example/Exceptions/BusinesException.cs
+++ b/samples/DFlow.Example/Exceptions/BusinesException.cs
@@ -5,9 +5,8 @@ namespace DFlow.Example.Exceptions
public class BusinesException : Exception
{
public BusinesException(string msg)
- : base(msg)
+ : base(msg)
{
-
}
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/Handlers/IProductCatalogCommandHandler.cs b/samples/DFlow.Example/Handlers/IProductCatalogCommandHandler.cs
index 23c25e3..0770469 100644
--- a/samples/DFlow.Example/Handlers/IProductCatalogCommandHandler.cs
+++ b/samples/DFlow.Example/Handlers/IProductCatalogCommandHandler.cs
@@ -1,4 +1,3 @@
-
using DFlow.Base.Events;
using DFlow.Interfaces;
diff --git a/samples/DFlow.Example/Handlers/IProductQueryHandler.cs b/samples/DFlow.Example/Handlers/IProductQueryHandler.cs
index b812227..2f23958 100644
--- a/samples/DFlow.Example/Handlers/IProductQueryHandler.cs
+++ b/samples/DFlow.Example/Handlers/IProductQueryHandler.cs
@@ -7,7 +7,7 @@ namespace DFlow.Example.Handlers
public interface IProductQueryHandler
{
IList ListAllProducts();
-
+
IList ListByFilter(Func query);
ProductDTO GetById(Guid id);
diff --git a/samples/DFlow.Example/Handlers/ProductQueryHandler.cs b/samples/DFlow.Example/Handlers/ProductQueryHandler.cs
index ef38f81..657b2de 100644
--- a/samples/DFlow.Example/Handlers/ProductQueryHandler.cs
+++ b/samples/DFlow.Example/Handlers/ProductQueryHandler.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using DFlow.Example.Views;
-using DFlow.Interfaces;
namespace DFlow.Example.Handlers
{
diff --git a/samples/DFlow.Example/Handlers/ProductServiceCommandHandler.cs b/samples/DFlow.Example/Handlers/ProductServiceCommandHandler.cs
index 4985cb8..0c9db71 100644
--- a/samples/DFlow.Example/Handlers/ProductServiceCommandHandler.cs
+++ b/samples/DFlow.Example/Handlers/ProductServiceCommandHandler.cs
@@ -1,14 +1,11 @@
using System;
-using System.Collections.Generic;
using System.Linq;
using DFlow.Base;
-using DFlow.Base.Aggregate;
using DFlow.Base.Events;
using DFlow.Base.Exceptions;
-using DFlow.Interfaces;
using DFlow.Example.Aggregates;
using DFlow.Example.Commands;
-using DFlow.Example.Events;
+using DFlow.Interfaces;
namespace DFlow.Example.Handlers
{
@@ -27,12 +24,12 @@ public ProductServiceCommandHandler(IEventStore eventStore,
public CommandEvent When(CreateProductCatalog cmd)
{
var productCatalog = _factory.Create(cmd.Id);
-
+
try
{
_eventStore.AppendToStream(cmd.Id, productCatalog.Version,
productCatalog.Changes, productCatalog.DomainEvents.ToArray());
-
+
return new CommandEvent(OperationStatus.Success);
}
catch (EventStoreConcurrencyException ex)
@@ -40,22 +37,18 @@ public CommandEvent When(CreateProductCatalog cmd)
HandleConcurrencyException(ex, productCatalog);
return new CommandEvent(OperationStatus.Success);
}
- catch(Exception)
- {
- throw;
- }
}
-
+
public CommandEvent When(CreateProductCommand cmd)
{
var productCatalog = _factory.Load(cmd.RootId);
productCatalog.CreateProduct(cmd);
-
+
try
{
_eventStore.AppendToStream(cmd.RootId, productCatalog.Version,
productCatalog.Changes, productCatalog.DomainEvents.ToArray());
-
+
//_publisher.Publish(arry event)
return new CommandEvent(OperationStatus.Success);
}
@@ -64,17 +57,13 @@ public CommandEvent When(CreateProductCommand cmd)
HandleConcurrencyException(ex, productCatalog);
return new CommandEvent(OperationStatus.Success);
}
- catch(Exception)
- {
- throw;
- }
}
-
+
public CommandEvent When(ChangeProductNameCommand cmd)
{
var productCatalog = _factory.Load(cmd.RootId);
productCatalog.ChangeProductName(cmd);
-
+
try
{
_eventStore.AppendToStream(cmd.RootId, productCatalog.Version,
@@ -86,10 +75,6 @@ public CommandEvent When(ChangeProductNameCommand cmd)
HandleConcurrencyException(ex, productCatalog);
return new CommandEvent(OperationStatus.Success);
}
- catch(Exception)
- {
- throw;
- }
}
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/MemoryAppendOnlyStore.cs b/samples/DFlow.Example/MemoryAppendOnlyStore.cs
index f91ba4a..4aefae8 100644
--- a/samples/DFlow.Example/MemoryAppendOnlyStore.cs
+++ b/samples/DFlow.Example/MemoryAppendOnlyStore.cs
@@ -11,7 +11,7 @@ public class MemoryAppendOnlyStore : AppendOnlyBase, IAppendOnlyStore
private ICollection> _eventsStorage = new List>();
- public MemoryAppendOnlyStore(IEventBus eventBus) : base()
+ public MemoryAppendOnlyStore(IEventBus eventBus)
{
}
@@ -35,7 +35,7 @@ public override IEnumerable ReadRecords(Guid aggregateId, long
.Take(maxCount)
.Select(x => new DataWithVersion(x.Version, x.Data));
}
-
+
public IEnumerable ReadRecords(long afterVersion, int maxCount)
{
var aggregateType = typeof(T).Name;
@@ -60,14 +60,13 @@ public override bool Any(Guid aggregateId)
public void Close()
{
-
}
-
+
protected override void Save(Guid id, string aggregateType, long version, byte[] data)
{
- _eventsStorage.Add(new EventDTO(id, aggregateType, version, data));
+ _eventsStorage.Add(new EventDTO(id, aggregateType, version, data));
}
-
+
//DTO para poder inserir em qualquer modelo de banco
private class EventDTO
@@ -80,11 +79,11 @@ public EventDTO(TKey aggregateId, string aggregateType, long version, byte[] dat
Data = data;
}
- public TKey AggregateId { get; set; }
-
- public string AggregateType { get; set; }
- public long Version { get; set; }
- public byte[] Data { get; set; }
+ public TKey AggregateId { get; }
+
+ public string AggregateType { get; }
+ public long Version { get; }
+ public byte[] Data { get; }
}
}
}
\ No newline at end of file
diff --git a/samples/DFlow.Example/MemoryResolver.cs b/samples/DFlow.Example/MemoryResolver.cs
index 48ab867..9271d9a 100644
--- a/samples/DFlow.Example/MemoryResolver.cs
+++ b/samples/DFlow.Example/MemoryResolver.cs
@@ -14,28 +14,22 @@ public MemoryResolver()
{
_subscribers = new Dictionary>();
}
-
+
public IEnumerable