Skip to content

Configuration

A. Shafie edited this page Nov 24, 2023 · 7 revisions

Nuget Packages

LiteBus has different Nuget Packages for its various modules and features. Add these packages to your project as needed:

All-in-One Package

Command Module Packages

These packages provide components for handling commands, which include:

  • ICommand: A command without a result.
  • ICommand<TResult>: A command that returns a result.

Query Module Packages

These packages provide components for handling queries, including:

  • IQuery<TResult>: Standard query.
  • IStreamQuery<TResult>: Query that yields IAsyncEnumerable<TResult>.

Event Module Packages

These packages offer components for handling events:

  • IEvent: Represents an event.

Configuring with Microsoft Dependency Injection (For ASP.NET Core)

To set up LiteBus modules for ASP.NET Core, use the ConfigureServices method in Startup.cs:

services.AddLiteBus(builder =>
{
    builder.AddCommandModule(builder =>
    {
        builder.RegisterFromAssembly(typeof(CreateProductCommand).Assembly) // Registers all handlers from a specific assembly.
               .Register<ProductValidationHandler>()
               .Register<ProductAuditingHandler>();
    })
    .AddQueryModule(builder =>
    {
        builder.RegisterFromAssembly(typeof(GetAllProducts).Assembly); 
    })
    .AddEventModule(builder =>
    {
        builder.RegisterFromAssembly(typeof(ProductCreatedEvent).Assembly);
    });
});

RegisterFromAssembly: This method registers all handlers from a specified assembly.

Register<T>: This method registers a specific handler. Any type of handler or message can be registered via this method.