Skip to content

Commit

Permalink
Merge pull request #102 from roadtoagility/dflow-eventing
Browse files Browse the repository at this point in the history
eventing was born
  • Loading branch information
drr00t authored May 18, 2022
2 parents 520bb83 + 709b954 commit 6b44032
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 87 deletions.
4 changes: 2 additions & 2 deletions samples/DFlow.Samples/DFlow.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

<ItemGroup>
<ProjectReference Include="..\..\src\contrib\DFlow.Persistence.LiteDB\DFlow.Persistence.LiteDB.csproj" />
<ProjectReference Include="..\..\src\contrib\DFlow.Persistence.EntityFramework\DFlow.Persistence.EntityFramework.csproj" />
<ProjectReference Include="..\..\src\DFlow.Business.Cqrs\DFlow.Business.Cqrs.csproj" />
<ProjectReference Include="..\..\src\DFlow.Domain.Events\DFlow.Domain.Events.csproj" />
<ProjectReference Include="..\..\src\DFlow.Domain\DFlow.Domain.csproj" />
<ProjectReference Include="..\..\src\contrib\DFlow.Persistence.EntityFramework\DFlow.Persistence.EntityFramework.csproj" />
<ProjectReference Include="..\..\src\DFlow.Persistence\DFlow.Persistence.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using System;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.DomainEvents;
using DFlow.Domain.Events.DomainEvents;
using DFlow.Samples.Domain.BusinessObjects;

namespace DFlow.Samples.Domain.Aggregates.Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using DFlow.Domain.Aggregates;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.Events;
using DFlow.Samples.Domain.Aggregates.Events;
using DFlow.Samples.Domain.BusinessObjects;

namespace DFlow.Samples.Domain.Aggregates
{
public sealed class UserEntityBasedAggregationRoot : ObjectBasedAggregationRoot<User, EntityId>
public sealed class UserEntityBasedAggregationRoot : ObjectBasedAggregationRootWithEvents<User, EntityId>
{

private UserEntityBasedAggregationRoot(User user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

using System.Collections.Generic;
using System.Collections.Immutable;
using DFlow.Domain.Aggregates;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.Events;
using DFlow.Domain.Events.BusinessObjects;
using DFlow.Domain.Validation;

namespace DFlow.Domain.Aggregates
namespace DFlow.Domain.Events.Aggregates
{
public class EventBasedAggregationRoot<TEntityId>: BaseValidation, IChangeSet<EventStream<TEntityId>>
{
Expand Down Expand Up @@ -45,10 +46,9 @@ protected void Apply(IDomainEvent domainEvent)
_currentStream.Add(domainEvent);
}

//Need to check tath

protected void Raise(IDomainEvent @event)
{
//this isint right
_changes.Add(@event);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
// Copyright (C) 2022 Road to Agility
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Collections.Generic;
using System.Collections.Immutable;
using DFlow.Domain.Events;
using DFlow.Domain.Validation;
using DFlow.Domain.BusinessObjects;

namespace DFlow.Domain.BusinessObjects
namespace DFlow.Domain.Events.BusinessObjects
{
public class EventStream<TEntityId>: BaseEntity<TEntityId>
{
private EventStream(TEntityId aggregateId, AggregationName aggregationName, VersionId version, IImmutableList<IDomainEvent> events)
:base(aggregateId, version)
private EventStream(TEntityId aggregateId, AggregationName aggregationName
, VersionId version, IImmutableList<IDomainEvent> events)
: base(aggregateId, version)
{
AggregationId = aggregateId;
Name = aggregationName;
Events = events;
}

public TEntityId AggregationId { get; }
public AggregationName Name { get; }
public IImmutableList<IDomainEvent> Events { get; }
Expand Down
4 changes: 4 additions & 0 deletions src/DFlow.Domain.Events/DFlow.Domain.Events.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
<Optimize Condition=" '$(Optimize)' == '' ">true</Optimize>
</PropertyGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020 Road to Agility
// Copyright (C) 2022 Road to Agility
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -7,7 +7,7 @@
using System;
using DFlow.Domain.BusinessObjects;

namespace DFlow.Domain.DomainEvents
namespace DFlow.Domain.Events.DomainEvents
{
public class AggregateAddedDomainEvent<TEntityId> : DomainEvent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (C) 2020 Road to Agility
// Copyright (C) 2022 Road to Agility
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.Events;

namespace DFlow.Domain.DomainEvents
namespace DFlow.Domain.Events.DomainEvents
{
public class DomainEvent : IDomainEvent
{
Expand Down
18 changes: 0 additions & 18 deletions src/DFlow.Domain.Events/IDomainEventBusAsync.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace DFlow.Domain.Events
{
public interface IDomainEventHandlerAsync<in TDomainEvent>
public interface IDomainEvents
{
Task HandleAsync(TDomainEvent @event, CancellationToken cancellationToken);
IReadOnlyList<IDomainEvent> GetEvents();
}
}
29 changes: 29 additions & 0 deletions src/DFlow.Domain.Events/ObjectBasedAggregationRootWithEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2020 Road to Agility
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Collections.Generic;
using System.Collections.Immutable;
using DFlow.Domain.Aggregates;
using DFlow.Domain.BusinessObjects;

namespace DFlow.Domain.Events
{
public abstract class ObjectBasedAggregationRootWithEvents<TChange, TEntityId>:
ObjectBasedAggregationRoot<TChange, TEntityId> where TChange:BaseEntity<TEntityId>
{
private readonly IList<IDomainEvent> _changes = new List<IDomainEvent>();

protected void Raise(IDomainEvent @event)
{
_changes.Add(@event);
}

public IReadOnlyList<IDomainEvent> GetEvents()
{
return _changes.ToImmutableList();
}
}
}
4 changes: 0 additions & 4 deletions src/DFlow.Domain/Aggregates/IChangeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Collections.Generic;
using DFlow.Domain.Events;

namespace DFlow.Domain.Aggregates
{
public interface IChangeSet<out TChange>
{
TChange GetChange();
IReadOnlyList<IDomainEvent> GetEvents();
}
}
14 changes: 0 additions & 14 deletions src/DFlow.Domain/Aggregates/ObjectBasedAggregationRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Collections.Generic;
using System.Collections.Immutable;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.Events;
using DFlow.Domain.Validation;

namespace DFlow.Domain.Aggregates
Expand All @@ -16,26 +13,15 @@ public abstract class ObjectBasedAggregationRoot<TChange, TEntityId>:BaseValidat
IChangeSet<TChange> where TChange: BaseEntity<TEntityId>
{
protected TChange AggregateRootEntity { get; set; }
private readonly IList<IDomainEvent> _changes = new List<IDomainEvent>();

protected void Apply(TChange item)
{
AggregateRootEntity = item;
}

protected void Raise(IDomainEvent @event)
{
_changes.Add(@event);
}

public TChange GetChange()
{
return AggregateRootEntity;
}

public IReadOnlyList<IDomainEvent> GetEvents()
{
return _changes.ToImmutableList();
}
}
}
4 changes: 0 additions & 4 deletions src/DFlow.Domain/DFlow.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
<ItemGroup>
<PackageReference Include="ValueOf" Version="2.0.21" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DFlow.Domain.Events\DFlow.Domain.Events.csproj" />
</ItemGroup>
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions tests/DFlow.Tests/DFlow.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\DFlow.Business.Cqrs\DFlow.Business.Cqrs.csproj" />
<ProjectReference Include="..\..\src\DFlow.Domain\DFlow.Domain.csproj" />
<ProjectReference Include="..\..\src\DFlow.Eventing\DFlow.Eventing.csproj" />
<ProjectReference Include="..\..\src\DFlow.Persistence\DFlow.Persistence.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Immutable;
using DFlow.Domain.Aggregates;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.Events;
using DFlow.Tests.Supporting.DomainObjects.Events;

namespace DFlow.Tests.Supporting.DomainObjects
{
public sealed class BusinessEntityAggregateRoot:ObjectBasedAggregationRoot<BusinessEntity, EntityTestId>
public sealed class BusinessEntityAggregateRoot:ObjectBasedAggregationRootWithEvents<BusinessEntity, EntityTestId>
{
internal BusinessEntityAggregateRoot(BusinessEntity businessEntity)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using DFlow.Domain.Aggregates;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.Events.BusinessObjects;
using DFlow.Tests.Supporting.DomainObjects.Commands;

namespace DFlow.Tests.Supporting.DomainObjects
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// Copyright (C) 2022 Road to Agility
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Collections.Immutable;
using DFlow.Domain.Aggregates;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.Events.Aggregates;
using DFlow.Domain.Events.BusinessObjects;
using DFlow.Tests.Supporting.DomainObjects.Events;

namespace DFlow.Tests.Supporting.DomainObjects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using System;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.DomainEvents;
using DFlow.Domain.Events.DomainEvents;

namespace DFlow.Tests.Supporting.DomainObjects.Events
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using System;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.DomainEvents;
using DFlow.Domain.Events.DomainEvents;

namespace DFlow.Tests.Supporting.DomainObjects.Events
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using System;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.DomainEvents;
using DFlow.Domain.Events.DomainEvents;

namespace DFlow.Tests.Supporting.DomainObjects.Events
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
// Copyright (C) 2020 Road to Agility
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
// Boston, MA 02110-1301, USA.
// Copyright (C) 2022 Road to Agility
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.


using System;
using System.Collections.Immutable;
Expand All @@ -25,14 +14,15 @@
using DFlow.Domain.Aggregates;
using DFlow.Domain.BusinessObjects;
using DFlow.Domain.Events;
using DFlow.Domain.Events.BusinessObjects;
using DFlow.Tests.Supporting.DomainObjects;
using DFlow.Tests.Supporting.DomainObjects.Commands;

namespace DFlow.Tests.Supporting
{
public sealed class UpdateEntityEventBasedCommandHandler : CommandHandler<UpdateEntityCommand, CommandResult<Guid>>
{
private IAggregateFactory<EventStreamBusinessEntityAggregateRoot, EventStream<EntityTestId>>
private readonly IAggregateFactory<EventStreamBusinessEntityAggregateRoot, EventStream<EntityTestId>>
_aggregateFactory;

public UpdateEntityEventBasedCommandHandler(IDomainEventBus publisher,
Expand All @@ -47,7 +37,7 @@ protected override Task<CommandResult<Guid>> ExecuteCommand(UpdateEntityCommand
var agg = _aggregateFactory.Create(
EventStream<EntityTestId>.From(EntityTestId.Empty(),
new AggregationName(),
VersionId.Empty(), new ImmutableArray<IDomainEvent>())
VersionId.Empty(), ImmutableList<IDomainEvent>.Empty)
);
var isSucceed = agg.IsValid;
var okId = Guid.Empty;
Expand Down

0 comments on commit 6b44032

Please sign in to comment.