Merq.DependencyInjection 2.0.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Merq.DependencyInjection --version 2.0.0
NuGet\Install-Package Merq.DependencyInjection -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Merq.DependencyInjection" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Merq.DependencyInjection --version 2.0.0
#r "nuget: Merq.DependencyInjection, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Merq.DependencyInjection as a Cake Addin
#addin nuget:?package=Merq.DependencyInjection&version=2.0.0

// Install Merq.DependencyInjection as a Cake Tool
#tool nuget:?package=Merq.DependencyInjection&version=2.0.0
var builder = WebApplication.CreateBuilder(args);
...
builder.Services.AddMessageBus();

All command handlers and event producers need to be registered with the services collection as usual, using the main interface for the component, such as ICommandHandler<T> and IObservable<TEvent>.

NOTE: Merq makes no assumptions about the lifetime of the registered components, so it's up to the consumer to register them with the desired lifetime.

To drastically simplify registration of handlers and producers, we recommend the Devlooped.Extensions.DependencyInjection.Attributed. package, which provides a simple attribute-based mechanism for automatically emitting at compile-time the required service registrations for all types marked with the provided [Service] attribute, which also allows setting the component lifetime, such as [Service(ServiceLifetime.Transient)] (default lifetime is ServiceLifetime.Singleton for this source generator-based package).

This allows to simply mark all command handlers and event producers as [Service] and then register them all with a single line of code:

builder.Services.AddServices();

Telemetry and Monitoring

The core implementation of the IMessageBus is instrumented with ActivitySource and Metric, providing out of the box support for Open Telemetry-based monitoring, as well as via dotnet trace and dotnet counters.

To export telemetry using Open Telemetry, for example:

using var tracer = Sdk
    .CreateTracerProviderBuilder()
    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("ConsoleApp"))
    .AddSource(source.Name)
    .AddSource("Merq")
    .AddConsoleExporter()
    .AddZipkinExporter()
    .AddAzureMonitorTraceExporter(o => o.ConnectionString = config["AppInsights"])
    .Build();

Collecting traces via dotnet-trace:

dotnet trace collect --name [PROCESS_NAME] --providers="Microsoft-Diagnostics-DiagnosticSource:::FilterAndPayloadSpecs=[AS]Merq,System.Diagnostics.Metrics:::Metrics=Merq"

Monitoring metrics via dotnet-counters:

dotnet counters monitor --process-id [PROCESS_ID] --counters Merq

Example rendering from the included sample console app:

dotnet-counters screenshot

Duck Typing Support

Being able to loosely couple both events (and their consumers) and command execution (from their command handler implementations) is a key feature of Merq. To take this decoupling to the extreme, Merq allows a similar capability as allowed by the TypeScript/JavaScript in VSCode: you can just copy/paste an event/command definition as source into your assembly, and perform the regular operations with it (like Observe an event and Execute a command), in a "duck typing" manner.

As long as the types' full name match, the conversion will happen automatically. Since this functionality isn't required in many scenarios, and since there are a myriad ways to implement such an object mapping functionality, the Merq.Core package only provides the hooks to enable this, but does not provide any built-in implementation for it. In other words, no duck typing is performed by default.

The Merq.AutoMapper package provides one such implementation, based on the excelent AutoMapper library. It can be registered with the DI container as follows:

builder.Services.AddMessageBus<AutoMapperMessageBus>();
// register all services, including handlers and producers
builder.Services.AddServices();

Dogfooding

CI Version Build

We also produce CI packages from branches and pull requests so you can dogfood builds as quickly as they are produced.

The CI feed is https://pkg.kzu.dev/index.json.

The versioning scheme for packages is:

  • PR builds: 42.42.42-pr[NUMBER]
  • Branch builds: 42.42.42-[BRANCH].[COMMITS]

Sponsors

Clarius Org Kirill Osenkov MFB Technologies, Inc. Stephen Shaw Torutek DRIVE.NET, Inc. Daniel Gnägi Ashley Medway Keith Pickford Thomas Bolon Kori Francis Toni Wenzel Giorgi Dalakishvili Mike James Dan Siegel Reuben Swartz Jacob Foshee alternate text is missing from this package README image Eric Johnson Norman Mackay Certify The Web Ix Technologies B.V. David JENNI Jonathan Oleg Kyrylchuk Charley Wu Jakob Tikjøb Andersen Seann Alexander Tino Hager Mark Seemann Angelo Belchior Ken Bonny Simon Cropp agileworks-eu alternate text is missing from this package README image Zheyu Shen Vezel

Sponsor this project  

Learn more about GitHub Sponsors

For usage and authoring of commands and events, see Merq readme.

Sponsors

Clarius Org Kirill Osenkov MFB Technologies, Inc. Stephen Shaw Torutek DRIVE.NET, Inc. Daniel Gnägi Ashley Medway Keith Pickford Thomas Bolon Kori Francis Toni Wenzel Giorgi Dalakishvili Mike James Dan Siegel Reuben Swartz Jacob Foshee alternate text is missing from this package README image Eric Johnson Norman Mackay Certify The Web Ix Technologies B.V. David JENNI Jonathan Oleg Kyrylchuk Charley Wu Jakob Tikjøb Andersen Seann Alexander Tino Hager Mark Seemann Angelo Belchior Ken Bonny Simon Cropp agileworks-eu alternate text is missing from this package README image Zheyu Shen Vezel

Sponsor this project  

Learn more about GitHub Sponsors

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 196 1/29/2024
2.0.0-rc.6 86 1/29/2024
2.0.0-rc.5 46 1/27/2024
2.0.0-rc.3 439 7/10/2023
2.0.0-rc.2 82 7/10/2023
2.0.0-rc.1 74 7/7/2023
2.0.0-beta.4 68 7/6/2023
2.0.0-beta.3 92 11/19/2022
2.0.0-beta.2 92 11/18/2022
2.0.0-alpha 160 11/16/2022