Giter Club home page Giter Club logo

mehdihadeli / food-delivery-modular-monolith Goto Github PK

View Code? Open in Web Editor NEW
282.0 9.0 34.0 4.15 MB

๐ŸŒญ A practical and imaginary food delivery modular monolith, built with .Net 7, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.

License: MIT License

C# 100.00%
clean-architechture cqrs ddd ddd-example domain-driven-design dotnet dotnetcore event-driven-architecture integration-testing message-broker

food-delivery-modular-monolith's Issues

Modular DI

Hi, I want to isolate the dependency injection between modules, which means that we can have an interface sharing across modules and each module has it own implementation. Do you have any idea ?
For example I have Catalog module which use IRepository and a MongoDbRepository class for using mongo db.
Another module called Order Module also use IRepository and a EfCoreRepositoryClass for using ef core.

I would like to ask you that how can I inject or can I isolate DI for each Module ?

Service Not Registered, Calling Module from other Module

using BuildingBlocks.Abstractions.CQRS.Command;
using BuildingBlocks.Abstractions.Messaging;
using BuildingBlocks.Abstractions.Messaging.Context;
using BuildingBlocks.Abstractions.Persistence;
using BuildingBlocks.Core.Messaging;
using ECommerce.Modules.Customers.RestockSubscriptions.Features.ProcessingRestockNotification;

namespace ECommerce.Modules.Customers.Products.Features.ReplenishingProductStock.Events.External;

public record ProductStockReplenished(long ProductId, int NewStock, int ReplenishedQuantity) :
    IntegrationEvent,
    ITxRequest;

public class ProductStockReplenishedConsumer : IMessageHandler<ProductStockReplenished>
{
    private readonly ICommandProcessor _commandProcessor;
    private readonly ILogger<ProductStockReplenishedConsumer> _logger;

    public ProductStockReplenishedConsumer(
        ICommandProcessor commandProcessor,
        ILogger<ProductStockReplenishedConsumer> logger)
    {
        _commandProcessor = commandProcessor;
        _logger = logger;
    }

    // If this handler is called successfully, it will send a ACK to rabbitmq for removing message from the queue and if we have an exception it send an NACK to rabbitmq
    // and with NACK we can retry the message with re-queueing this message to the broker
    public async Task HandleAsync(
        IConsumeContext<ProductStockReplenished> messageContext,
        CancellationToken cancellationToken = default)
    {
        var productStockReplenished = messageContext.Message;

        await _commandProcessor.SendAsync(
            new ProcessRestockNotification(productStockReplenished.ProductId, productStockReplenished.NewStock),
            cancellationToken);

        _logger.LogInformation(
            "Sending restock notification command for product {ProductId}",
            productStockReplenished.ProductId);
    }
}

Above SendAsync method works sometimes, sometimes throw an error:

Error constructing handler for request of type MediatR.IRequestHandler`2[ECommerce.Modules.Customers.RestockSubscriptions.Features.ProcessingRestockNotification.ProcessRestockNotification,MediatR.Unit]. Register your handlers with the container. See the samples in GitHub for examples.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.