Skip to content

Commit

Permalink
refactor: moving behaviors implementation to infra
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-shirbandi committed Aug 18, 2024
1 parent 54b8023 commit b93e0c7
Show file tree
Hide file tree
Showing 37 changed files with 75 additions and 219 deletions.
23 changes: 0 additions & 23 deletions src/1-BuildingBlocks/Application/Services/ApplicationExtensions.cs

This file was deleted.

39 changes: 0 additions & 39 deletions src/1-BuildingBlocks/Application/Services/ApplicationService.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using TaskoMask.BuildingBlocks.Domain.Events;

namespace TaskoMask.BuildingBlocks.Application.Behaviors;
namespace TaskoMask.BuildingBlocks.Infrastructure.Behaviors;

public static class BehaviorExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading.Tasks;
using TaskoMask.BuildingBlocks.Application.Queries;

namespace TaskoMask.BuildingBlocks.Application.Behaviors;
namespace TaskoMask.BuildingBlocks.Infrastructure.Behaviors;

/// <summary>
/// Caching response for queries that are mareked by ICacheableQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Threading.Tasks;
using TaskoMask.BuildingBlocks.Domain.Events;

namespace TaskoMask.BuildingBlocks.Application.Behaviors;
namespace TaskoMask.BuildingBlocks.Infrastructure.Behaviors;

/// <summary>
/// Each command must have at least one event to save its changes in event store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using TaskoMask.BuildingBlocks.Application.Notifications;
using TaskoMask.BuildingBlocks.Contracts.Extensions;

namespace TaskoMask.BuildingBlocks.Application.Behaviors;
namespace TaskoMask.BuildingBlocks.Infrastructure.Behaviors;

/// <summary>
/// Automatic validation by checking data annotation and fluent validations (if any)
Expand Down Expand Up @@ -49,7 +49,7 @@ public async Task<TResponse> Handle(TRequest request, CancellationToken cancella
var isValidDataAnnotationValidation = ValidateDataAnnotationValidation(request);

if (!isValidFluentValidation || !isValidDataAnnotationValidation)
throw new Exceptions.ValidationException();
throw new Application.Exceptions.ValidationException();

return await next();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MediatR.Pipeline;
using Microsoft.Extensions.DependencyInjection;

namespace TaskoMask.BuildingBlocks.Application.Exceptions;
namespace TaskoMask.BuildingBlocks.Infrastructure.Exceptions;

public static class ExceptionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using TaskoMask.BuildingBlocks.Application.Notifications;
using TaskoMask.BuildingBlocks.Contracts.Exceptions;

namespace TaskoMask.BuildingBlocks.Application.Exceptions;
namespace TaskoMask.BuildingBlocks.Infrastructure.Exceptions;

/// <summary>
/// Handle all managed exceptions (DomainException,ApplicationException,ValidationException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;
using TaskoMask.BuildingBlocks.Application.Notifications;

namespace TaskoMask.BuildingBlocks.Application.Exceptions;
namespace TaskoMask.BuildingBlocks.Infrastructure.Exceptions;

/// <summary>
/// Handle all unmanaged exceptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using TaskoMask.BuildingBlocks.Infrastructure.Behaviors;
using TaskoMask.BuildingBlocks.Infrastructure.Bus;
using TaskoMask.BuildingBlocks.Infrastructure.EventSourcing;
using TaskoMask.BuildingBlocks.Infrastructure.Exceptions;
using TaskoMask.BuildingBlocks.Infrastructure.Notifications;

namespace TaskoMask.BuildingBlocks.Infrastructure.Extensions;

Expand All @@ -15,9 +18,14 @@ public static void AddBuildingBlocksInfrastructure(
this IServiceCollection services,
IConfiguration configuration,
Type consumerAssemblyMarkerType,
Type handlerAssemblyMarkerType
Type handlerAssemblyMarkerType,
Type validatorAssemblyMarkerType
)
{
services.AddApplicationExceptionHandlers();
services.AddApplicationBehaviors(validatorAssemblyMarkerType);
services.AddDomainNotificationHandler();

services.AddInMemoryBus(handlerAssemblyMarkerType);
services.AddMessageBus(configuration, consumerAssemblyMarkerType);
services.AddRedisEventStoreService();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using TaskoMask.BuildingBlocks.Application.Notifications;

namespace TaskoMask.BuildingBlocks.Application.Notifications;
namespace TaskoMask.BuildingBlocks.Infrastructure.Notifications;

/// <summary>
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using TaskoMask.BuildingBlocks.Application.Notifications;

namespace TaskoMask.BuildingBlocks.Application.Notifications;
namespace TaskoMask.BuildingBlocks.Infrastructure.Notifications;

public static class NotificationsExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TaskoMask.BuildingBlocks.Application.Services;
using TaskoMask.BuildingBlocks.Infrastructure.Extensions;
using TaskoMask.BuildingBlocks.Infrastructure.Mapping;
using TaskoMask.BuildingBlocks.Infrastructure.MongoDB;
using TaskoMask.Services.Boards.Read.Api.Features.Boards.GetBoardById;
using TaskoMask.Services.Boards.Read.Api.Infrastructure.DbContext;
using TaskoMask.Services.Boards.Read.Api.Infrastructure.Mapper;

Expand All @@ -23,11 +21,10 @@ public static void AddModules(this IServiceCollection services, IConfiguration c
services.AddBuildingBlocksInfrastructure(
configuration,
consumerAssemblyMarkerType: typeof(Program),
handlerAssemblyMarkerType: typeof(GetBoardByIdHandler)
handlerAssemblyMarkerType: typeof(Program),
validatorAssemblyMarkerType: typeof(Program)
);

services.AddBuildingBlocksApplication(validatorAssemblyMarkerType: typeof(Program));

services.AddMapper(typeof(MappingProfile));

services.AddMongoDbContext(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde
{
builder.AddCustomSerilog();

builder.Services.AddModules(builder.Configuration, consumerAssemblyMarkerType: typeof(Program));
builder.Services.AddModules(builder.Configuration);

builder.Services.AddWebApiPreConfigured(builder.Configuration);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using TaskoMask.BuildingBlocks.Infrastructure.Extensions;
using TaskoMask.BuildingBlocks.Infrastructure.MongoDB;
using TaskoMask.Services.Boards.Write.Api.Domain.Boards.Data;
using TaskoMask.Services.Boards.Write.Api.Domain.Boards.Services;
using TaskoMask.Services.Boards.Write.Api.Infrastructure.Data.DbContext;
using TaskoMask.Services.Boards.Write.Api.Infrastructure.Data.Repositories;
using TaskoMask.Services.Boards.Write.Api.Infrastructure.Data.Services;
using TaskoMask.Services.Boards.Write.Api.Resources;

namespace TaskoMask.Services.Boards.Write.Api.Infrastructure.CrossCutting.DI;

Expand All @@ -20,9 +18,14 @@ public static class InfrastructureModule
/// <summary>
///
/// </summary>
public static void AddInfrastructureModule(this IServiceCollection services, IConfiguration configuration, Type consumerAssemblyMarkerType)
public static void AddInfrastructureModule(this IServiceCollection services, IConfiguration configuration)
{
services.AddBuildingBlocksInfrastructure(configuration, consumerAssemblyMarkerType, handlerAssemblyMarkerType: typeof(ApplicationMessages));
services.AddBuildingBlocksInfrastructure(
configuration,
consumerAssemblyMarkerType: typeof(Program),
validatorAssemblyMarkerType: typeof(Program),
handlerAssemblyMarkerType: typeof(Program)
);

services.AddMongoDbContext(configuration);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace TaskoMask.Services.Boards.Write.Api.Infrastructure.CrossCutting.DI;

Expand All @@ -12,10 +11,8 @@ public static class ModuleExtensions
/// <summary>
///
/// </summary>
public static void AddModules(this IServiceCollection services, IConfiguration configuration, Type consumerAssemblyMarkerType)
public static void AddModules(this IServiceCollection services, IConfiguration configuration)
{
services.AddInfrastructureModule(configuration, consumerAssemblyMarkerType);

services.AddApplicationModule();
services.AddInfrastructureModule(configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override IServiceProvider GetServiceProvider(string dbNameSuffix)
return configuration;
});

services.AddModules(configuration, typeof(TestsBaseFixture));
services.AddModules(configuration);

var serviceProvider = services.BuildServiceProvider();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Captcha;
using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC;
using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog;
using TaskoMask.Services.Identity.Api.Consumers;
using TaskoMask.Services.Identity.Api.Infrastructure.CrossCutting.DI;

namespace TaskoMask.Services.Identity.Api.Configuration;
Expand All @@ -21,7 +20,7 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde

builder.Services.AddRazorPagesPreConfigured(builder.Configuration);

builder.Services.AddModules(builder.Configuration, consumerAssemblyMarkerType: typeof(OwnerRegisteredConsumer));
builder.Services.AddModules(builder.Configuration);

builder.Services.AddIdentityServer();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using TaskoMask.Services.Identity.Api.Infrastructure.CrossCutting.AspNetIdentity;
using TaskoMask.Services.Identity.Api.Infrastructure.CrossCutting.Mapper;
using TaskoMask.Services.Identity.Api.Infrastructure.Data.DbContext;
using TaskoMask.Services.Identity.Api.UseCases.RegisterUser;

namespace TaskoMask.Services.Identity.Api.Infrastructure.CrossCutting.DI;

Expand All @@ -18,9 +17,14 @@ public static class InfrastructureModule
/// <summary>
///
/// </summary>
public static void AddInfrastructureModule(this IServiceCollection services, IConfiguration configuration, Type consumerAssemblyMarkerType)
public static void AddInfrastructureModule(this IServiceCollection services, IConfiguration configuration)
{
services.AddBuildingBlocksInfrastructure(configuration, consumerAssemblyMarkerType, handlerAssemblyMarkerType: typeof(RegisterUserUseCase));
services.AddBuildingBlocksInfrastructure(
configuration,
consumerAssemblyMarkerType: typeof(Program),
handlerAssemblyMarkerType: typeof(Program),
validatorAssemblyMarkerType: typeof(Program)
);

services.AddMapper(typeof(MappingProfile));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace TaskoMask.Services.Identity.Api.Infrastructure.CrossCutting.DI;

Expand All @@ -12,10 +11,8 @@ public static class ModuleExtensions
/// <summary>
///
/// </summary>
public static void AddModules(this IServiceCollection services, IConfiguration configuration, Type consumerAssemblyMarkerType)
public static void AddModules(this IServiceCollection services, IConfiguration configuration)
{
services.AddInfrastructureModule(configuration, consumerAssemblyMarkerType);

services.AddApplicationModule();
services.AddInfrastructureModule(configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override IServiceProvider GetServiceProvider(string dbNameSuffix)

services.AddLogging();

services.AddModules(configuration, typeof(TestsBaseFixture));
services.AddModules(configuration);

var serviceProvider = services.BuildServiceProvider();

Expand Down
Loading

0 comments on commit b93e0c7

Please sign in to comment.