It is an ASP.NET Core 3.1 based microservice using RabbitMQ with MassTransit, EntityFramework Core with MS SQL Server as well as Bogus, AutoMapper, etc.
- BusinessLayer
The business layer is responsible for performing operations on data coming from the DAL (Data Access Layer).
- DAL
The Data Access Layer is responsible for providing simplified and data access. Uses Models to access the database.
- Models
The Model Layer is responsible for storing data models for accessing the database.
- Accounts (directly the web project itself)
Uses Multiple Response Types
technique
public class GetArticleConsumer : IConsumer<ArticleByIdRequestDto>
{
private readonly OperationArticles _operationArticles;
private readonly IMapper _mapper;
public GetArticleConsumer(IMapper mapper, OperationArticles operationArticles)
{
_mapper = mapper;
_operationArticles = operationArticles;
}
public async Task Consume(ConsumeContext<ArticleByIdRequestDto> context)
{
try
{
var result = await _operationArticles.GetByIdArticleAsync(context.Message.ArticleGuid);
var article = _mapper.Map<ArticleDto>(result);
await context.RespondAsync(new ArticleResponseDto
{
ArticleDto = article
});
}
catch (NoArticlesFoundForAuthorAppException e)
{
await context.RespondAsync(new NoArticlesFound
{
CodeException = e.CodeException,
MassageException = $"{e.Message}"
});
}
catch (Exception e)
{
await context.RespondAsync(new NoArticlesFound
{
MassageException = $"{e.Message}"
});
}
}
}
Consumer is added to MassTransit in ConfigureServicesMassTransitRabbitMq
public static void ConfigureService(IServiceCollection services, IConfiguration configuration)
{
var section = configuration.GetSection("MassTransit");
ConfigureServicesMassTransit.ConfigureServices(services, configuration, new MassTransitConfiguration()
{
IsDebug = section.GetValue<bool>("IsDebug"),
ServiceName = "Articles",
Configurator = busMassTransit =>
{
busMassTransit.AddConsumer<GetArticlesByIdAuthorConsumer>();
busMassTransit.AddConsumer<GetArticlesConsumer>();
busMassTransit.AddConsumer<GetArticleConsumer>();
busMassTransit.AddConsumer<GoArchiveArticleConsumer>();
busMassTransit.AddConsumer<CreateArticleConsumer>();
}
});
}