Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<!-- Workaround for https://github.com/dotnet/sourcelink/issues/572 -->
<PropertyGroup>
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
</PropertyGroup>
<ItemGroup>
<EmbeddedFiles Include="$(GeneratedAssemblyInfoFile)"/>
</ItemGroup>
<!-- Workaround for https://github.com/dotnet/sourcelink/issues/572 -->
<PropertyGroup>
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
</PropertyGroup>
<ItemGroup>
<EmbeddedFiles Include="$(GeneratedAssemblyInfoFile)"/>
</ItemGroup>
</Project>
23 changes: 10 additions & 13 deletions samples/DFlow.Example/AggregateFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AggregateFactory : AggregateFactoryBase
private readonly IEventStore<Guid> _eventStore;
private readonly long INITIAL_VERSION = 1;

public AggregateFactory(IEventStore<Guid> eventStore, ISnapshotRepository<Guid> snapshotRepository = null)
public AggregateFactory(IEventStore<Guid> eventStore, ISnapshotRepository<Guid> snapshotRepository = null)
: base(eventStore, snapshotRepository)
{
_eventStore = eventStore;
Expand All @@ -26,19 +26,16 @@ public override TAggregate Create<TAggregate>()
public override TAggregate Create<TAggregate>(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<Guid>(id);
var events = new List<IEvent>() { createEvent};
var stream = new EventStream(){ Version = INITIAL_VERSION, Events = events};
TAggregate aggregate = (TAggregate) Activator.CreateInstance(typeof(TAggregate), new object[] {stream});
var events = new List<IEvent> { createEvent };

var stream = new EventStream { Version = INITIAL_VERSION, Events = events };

var aggregate = (TAggregate)Activator.CreateInstance(typeof(TAggregate), stream);

aggregate.Changes.Add(createEvent);
return aggregate;
}
Expand Down
22 changes: 10 additions & 12 deletions samples/DFlow.Example/Aggregates/ProductCatalogAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -18,46 +18,44 @@ public class ProductCatalogAggregate : AggregateRoot<Guid>
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<Guid> e)
{
Id = e.Id;
Expand Down
9 changes: 4 additions & 5 deletions samples/DFlow.Example/Commands/AddProductCommand.cs
Original file line number Diff line number Diff line change
@@ -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()
{
}
Expand All @@ -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; }
}
}
9 changes: 4 additions & 5 deletions samples/DFlow.Example/Commands/ChangeProductNameCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }
}
}
6 changes: 3 additions & 3 deletions samples/DFlow.Example/Commands/CreateProductCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
26 changes: 8 additions & 18 deletions samples/DFlow.Example/Commands/CreateProductCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,32 @@ 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;
}

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; }
}
}
8 changes: 4 additions & 4 deletions samples/DFlow.Example/DFlow.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Tests' ">
<DefineConstants>TRACE;TEST_BUILD</DefineConstants>
<DefineConstants>TRACE;TEST_BUILD</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release Profilling' ">
<Optimize Condition=" '$(Optimize)' == '' ">true</Optimize>
<Optimize Condition=" '$(Optimize)' == '' ">true</Optimize>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\DFlow\DFlow.csproj" />
<ProjectReference Include="..\..\src\DFlow\DFlow.csproj"/>
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions samples/DFlow.Example/Entities/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;

using DFlow.Interfaces;

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; }
}
}
11 changes: 4 additions & 7 deletions samples/DFlow.Example/Events/ProductCreated.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
8 changes: 4 additions & 4 deletions samples/DFlow.Example/Events/ProductNameChanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
3 changes: 1 addition & 2 deletions samples/DFlow.Example/Exceptions/BusinesException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ namespace DFlow.Example.Exceptions
public class BusinesException : Exception
{
public BusinesException(string msg)
: base(msg)
: base(msg)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using DFlow.Base.Events;
using DFlow.Interfaces;

Expand Down
2 changes: 1 addition & 1 deletion samples/DFlow.Example/Handlers/IProductQueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace DFlow.Example.Handlers
public interface IProductQueryHandler
{
IList<ProductDTO> ListAllProducts();

IList<ProductDTO> ListByFilter(Func<ProductDTO, bool> query);

ProductDTO GetById(Guid id);
Expand Down
1 change: 0 additions & 1 deletion samples/DFlow.Example/Handlers/ProductQueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using DFlow.Example.Views;
using DFlow.Interfaces;

namespace DFlow.Example.Handlers
{
Expand Down
Loading