Skip to content

Commit

Permalink
refactor: enhance building blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihadeli committed Aug 14, 2024
1 parent 2f967ee commit dfd5462
Show file tree
Hide file tree
Showing 226 changed files with 1,059 additions and 1,661 deletions.
11 changes: 2 additions & 9 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
],
"rollForward": false
},
"cake.tool": {
"version": "2.3.0",
"commands": [
"dotnet-cake"
],
"rollForward": false
},
"csharpier": {
"version": "0.28.2",
"commands": [
Expand All @@ -24,7 +17,7 @@
"rollForward": false
},
"swashbuckle.aspnetcore.cli": {
"version": "6.6.2",
"version": "6.7.0",
"commands": [
"swagger"
],
Expand Down Expand Up @@ -52,4 +45,4 @@
"rollForward": false
}
}
}
}
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
// https://github.com/devcontainers/features/tree/main/src/dotnet#dotnet-cli-dotnet
"ghcr.io/devcontainers/features/dotnet:2": {
// this version should be matched with global.json .net version for working vscode IntelliSense correctly
"version": "8.0.303",
"additionalVersions": "latest, 7.0.410, 8.0.303, 6.0.424",
"version": "8.0.400",
"additionalVersions": "latest, 8.0.400, 8.0.303, 7.0.410, 6.0.424",
"aspNetCoreRuntimeVersions": "latest, 7.0"
},
// https://github.com/devcontainers/features/tree/main/src/github-cli
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

dotnet format --verbosity diagnostic
# dotnet format --verbosity diagnostic
dotnet csharpier . && git add -A .
38 changes: 38 additions & 0 deletions food-delivery-microservices.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AC15A422-22C5-46C7-A9F4-3473AB68E8BE}"
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
src\Directory.Build.targets = src\Directory.Build.targets
src\Directory.Packages.props = src\Directory.Packages.props
src\Packages.props = src\Packages.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiGateway", "ApiGateway", "{5054DD25-B14D-4A6D-A349-951C323BD564}"
EndProject
Expand Down Expand Up @@ -48,6 +54,10 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildingBlocks.Web", "src\BuildingBlocks\BuildingBlocks.Web\BuildingBlocks.Web.csproj", "{D5503E7F-10E7-4BA1-9611-86E92FC19ACD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7528202E-DFFE-4295-BAED-6F40D8D62864}"
ProjectSection(SolutionItems) = preProject
tests\Directory.Build.props = tests\Directory.Build.props
tests\Directory.Packages.props = tests\Directory.Packages.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{F397611D-54BB-4ED3-BB4F-C34BE9308B40}"
EndProject
Expand Down Expand Up @@ -524,6 +534,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test-coverage", "test-cover
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuildingBlocks.Serialization", "src\BuildingBlocks\BuildingBlocks.Serialization\BuildingBlocks.Serialization.csproj", "{DB8543CF-E427-463E-BF94-D0E91ABC16F5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodDelivery.Services.Identity.EndToEndTests", "tests\Services\Identity\FoodDelivery.Services.Identity.EndToEndTests\FoodDelivery.Services.Identity.EndToEndTests.csproj", "{685E3E5C-FBCF-499D-9AE2-F7FE66918F72}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodDelivery.Services.Identity.IntegrationTests", "tests\Services\Identity\FoodDelivery.Services.Identity.IntegrationTests\FoodDelivery.Services.Identity.IntegrationTests.csproj", "{D9A193CB-020A-4367-A954-6D4EDAD9E327}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodDelivery.Services.Identity.UnitTests", "tests\Services\Identity\FoodDelivery.Services.Identity.UnitTests\FoodDelivery.Services.Identity.UnitTests.csproj", "{84A67508-47F8-41D8-95D8-3493FF35554A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodDelivery.Services.Identity.TestShared", "tests\Services\Identity\FoodDelivery.Services.Identity.TestShared\FoodDelivery.Services.Identity.TestShared.csproj", "{D12A7726-3B12-4CCD-A3F4-4ABDD28BD44C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -778,6 +796,22 @@ Global
{DB8543CF-E427-463E-BF94-D0E91ABC16F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB8543CF-E427-463E-BF94-D0E91ABC16F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB8543CF-E427-463E-BF94-D0E91ABC16F5}.Release|Any CPU.Build.0 = Release|Any CPU
{685E3E5C-FBCF-499D-9AE2-F7FE66918F72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{685E3E5C-FBCF-499D-9AE2-F7FE66918F72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{685E3E5C-FBCF-499D-9AE2-F7FE66918F72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{685E3E5C-FBCF-499D-9AE2-F7FE66918F72}.Release|Any CPU.Build.0 = Release|Any CPU
{D9A193CB-020A-4367-A954-6D4EDAD9E327}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9A193CB-020A-4367-A954-6D4EDAD9E327}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9A193CB-020A-4367-A954-6D4EDAD9E327}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9A193CB-020A-4367-A954-6D4EDAD9E327}.Release|Any CPU.Build.0 = Release|Any CPU
{84A67508-47F8-41D8-95D8-3493FF35554A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84A67508-47F8-41D8-95D8-3493FF35554A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84A67508-47F8-41D8-95D8-3493FF35554A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84A67508-47F8-41D8-95D8-3493FF35554A}.Release|Any CPU.Build.0 = Release|Any CPU
{D12A7726-3B12-4CCD-A3F4-4ABDD28BD44C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D12A7726-3B12-4CCD-A3F4-4ABDD28BD44C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D12A7726-3B12-4CCD-A3F4-4ABDD28BD44C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D12A7726-3B12-4CCD-A3F4-4ABDD28BD44C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -930,6 +964,10 @@ Global
{6DA0B023-EEED-417A-AF01-A6C9A7E54B57} = {05AB571B-C141-4520-A5E5-3C67488DD151}
{29AEB77A-F6D1-4196-8ACE-538E558C064F} = {05AB571B-C141-4520-A5E5-3C67488DD151}
{DB8543CF-E427-463E-BF94-D0E91ABC16F5} = {AC8D1CE6-BAF8-4A05-8F87-232598A756C3}
{685E3E5C-FBCF-499D-9AE2-F7FE66918F72} = {A9B8E9D0-8E3C-4495-B8FE-CBBAE3D46E62}
{D9A193CB-020A-4367-A954-6D4EDAD9E327} = {A9B8E9D0-8E3C-4495-B8FE-CBBAE3D46E62}
{84A67508-47F8-41D8-95D8-3493FF35554A} = {A9B8E9D0-8E3C-4495-B8FE-CBBAE3D46E62}
{D12A7726-3B12-4CCD-A3F4-4ABDD28BD44C} = {A9B8E9D0-8E3C-4495-B8FE-CBBAE3D46E62}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AD0585D6-CBA4-4818-86D8-0D914F18E390}
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.303",
"version": "8.0.400",
"rollForward": "latestFeature"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public interface IInvalidateCacheRequest<in TRequest, TResponse>
IEnumerable<string> CacheKeys(TRequest request);
}

public interface IInvalidateCacheRequest<in TRequest> : IInvalidateCacheRequest<TRequest, Unit>
where TRequest : IRequest<Unit> { }
public interface IInvalidateCacheRequest<in TRequest>
where TRequest : IRequest;

public interface IStreamInvalidateCacheRequest<in TRequest, TResponse>
where TRequest : IStreamRequest<TResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BuildingBlocks.Abstractions.Commands;

public interface ICommand : ICommand<Unit>;
public interface ICommand : IRequest;

public interface ICommand<out T> : IRequest<T>
where T : notnull;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BuildingBlocks.Abstractions.Events;

public interface IAggregatesDomainEventsRequestStore
public interface IAggregatesDomainEventsRequestStorage
{
IReadOnlyList<IDomainEvent> AddEventsFromAggregate<T>(T aggregate)
where T : IHaveAggregate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace BuildingBlocks.Abstractions.Messaging;

public interface IExternalEventBus : IBusProducer, IBusConsumer { }
public interface IExternalEventBus : IBusProducer, IBusConsumer;
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
namespace BuildingBlocks.Abstractions.Messaging.PersistMessage;

public class StoreMessage
public class StoreMessage(Guid id, string dataType, string data, MessageDeliveryType deliveryType)
{
public StoreMessage(Guid id, string dataType, string data, MessageDeliveryType deliveryType)
{
Id = id;
DataType = dataType;
Data = data;
DeliveryType = deliveryType;
Created = DateTime.Now;
MessageStatus = MessageStatus.Stored;
RetryCount = 0;
}

public Guid Id { get; private set; }
public string DataType { get; private set; }
public string Data { get; private set; }
public DateTime Created { get; private set; }
public Guid Id { get; private set; } = id;
public string DataType { get; private set; } = dataType;
public string Data { get; private set; } = data;
public DateTime Created { get; private set; } = DateTime.Now;
public int RetryCount { get; private set; }
public MessageStatus MessageStatus { get; private set; }
public MessageDeliveryType DeliveryType { get; private set; }
public MessageStatus MessageStatus { get; private set; } = MessageStatus.Stored;
public MessageDeliveryType DeliveryType { get; private set; } = deliveryType;

public void ChangeState(MessageStatus messageStatus)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class InvalidateCacheRequest<TRequest, TResponse> : IInvalidateC
}

public abstract class InvalidateCacheRequest<TRequest> : IInvalidateCacheRequest<TRequest>
where TRequest : IRequest<Unit>
where TRequest : IRequest
{
public virtual string Prefix => "Ch_";
public abstract IEnumerable<string> CacheKeys(TRequest request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using BuildingBlocks.Abstractions.Domain;
using BuildingBlocks.Abstractions.Events;
using BuildingBlocks.Abstractions.Events.Internal;

namespace BuildingBlocks.Core.Events;

public class AggregatesDomainEventsStore : IAggregatesDomainEventsRequestStore
public class AggregatesDomainEventsStorage : IAggregatesDomainEventsRequestStorage
{
private readonly List<IDomainEvent> _uncommittedDomainEvents = new();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using BuildingBlocks.Abstractions.Events;

namespace BuildingBlocks.Core.Events;

public class DomainEventAccessor(
IAggregatesDomainEventsRequestStorage aggregatesDomainEventsStorage,
IDomainEventContext domainEventContext
) : IDomainEventsAccessor
{
public IReadOnlyList<IDomainEvent> UnCommittedDomainEvents
{
get
{
var events = aggregatesDomainEventsStorage.GetAllUncommittedEvents();
if (events.Count != 0)
{
return events;
}

// Or
return domainEventContext.GetAllUncommittedEvents();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

namespace BuildingBlocks.Core.Events;

public record EventEnvelope<T>(T Data, IEventEnvelopeMetadata? Metadata) : IEventEnvelope<T>
public record EventEnvelope<T>(T Data, IEventEnvelopeMetadata? Metadata = null) : IEventEnvelope<T>
where T : notnull
{
object IEventEnvelope.Data => Data;
}

public static class EventEnvelope
{
public static IEventEnvelope From(object data, IEventEnvelopeMetadata? metadata)
public static IEventEnvelope From(object data, IEventEnvelopeMetadata? metadata = null)
{
var type = typeof(EventEnvelope<>).MakeGenericType(data.GetType());
return (IEventEnvelope)Activator.CreateInstance(type, data, metadata)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BuildingBlocks.Abstractions.Events.Internal;
using BuildingBlocks.Abstractions.Messaging;
using BuildingBlocks.Core.Messaging;
using BuildingBlocks.Core.Persistence.EventStore;
using BuildingBlocks.Core.Reflection;
using Microsoft.Extensions.DependencyInjection.Extensions;

Expand All @@ -23,9 +24,8 @@ internal static IServiceCollection AddEventBus(this IServiceCollection services,
.AddTransient<IInternalEventBus, InternalEventBus>()
.AddTransient<IExternalEventBus, NullExternalEventBus>();

services.AddScoped<IDomainEventsAccessor, NullDomainEventsAccessor>();

services.TryAddTransient<IAggregatesDomainEventsRequestStore, AggregatesDomainEventsStore>();
services.AddTransient<IAggregatesDomainEventsRequestStorage, AggregatesDomainEventsStorage>();
services.AddScoped<IDomainEventsAccessor, DomainEventAccessor>();

RegisterEventMappers(services, assemblies);

Expand Down
Loading

0 comments on commit dfd5462

Please sign in to comment.