Egov.Integrations.MConnect.Events 10.0.5

Prefix Reserved
dotnet add package Egov.Integrations.MConnect.Events --version 10.0.5
                    
NuGet\Install-Package Egov.Integrations.MConnect.Events -Version 10.0.5
                    
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="Egov.Integrations.MConnect.Events" Version="10.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Egov.Integrations.MConnect.Events" Version="10.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Egov.Integrations.MConnect.Events" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Egov.Integrations.MConnect.Events --version 10.0.5
                    
#r "nuget: Egov.Integrations.MConnect.Events, 10.0.5"
                    
#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.
#:package Egov.Integrations.MConnect.Events@10.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Egov.Integrations.MConnect.Events&version=10.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Egov.Integrations.MConnect.Events&version=10.0.5
                    
Install as a Cake Tool

Egov.Integrations.MConnect.Events

NuGet Version License: MIT

This library facilitates the integration of .NET applications with MConnect Events, providing easy-to-use producers and consumers for CloudEvents. It simplifies the process of producing and consuming events by providing a fluent API, background services, and seamless integration with .NET dependency injection.


Table of Contents


Features

  • CloudEvents Support: Built on the CloudEvents specification (version 1.0).
  • Producer & Consumer: High-level abstractions for sending and receiving events.
  • Background Services: Automatic event consumption via hosted services.
  • Typed Handlers: Support for generic handlers with strongly-typed JSON data.
  • Flexible Configuration: Integration with IConfiguration and IServiceCollection.
  • Security: Built-in support for system certificates and mutual TLS (mTLS).

Prerequisites

  • .NET 10.0 or later
  • MConnect Events service access

Installation

Install the package via NuGet:

dotnet add package Egov.Integrations.MConnect.Events

Packages

  • Egov.Integrations.MConnect.Events: The main library containing producer, consumer, and handler abstractions.

Configuration

Add the necessary configuration to your appsettings.json:

{
  "MConnect": {
    "Producer": {
      "BaseAddress": "https://mconnect.example.com/",
      "Timeout": "00:01:40"
    },
    "Consumer": {
      "BaseAddress": "https://mconnect.example.com/",
      "ConsumeEvents": true,
      "ConsumeTest": true,
      "ConsumeDead": false
    }
  }
}

Usage

Registering Producer

Register the producer in your Program.cs:

using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

// Add MConnect Events producer
builder.Services.AddCloudEventsProducer(builder.Configuration.GetSection("MConnect:Producer"));

var app = builder.Build();

// Usage in a service
public class MyService(ICloudEventsProducer producer)
{
    public async Task SendEventAsync()
    {
        var cloudEvent = new CloudEvent
        {
            Id = Guid.NewGuid().ToString(),
            Source = new Uri("https://my-service.gov.md"),
            Type = "md.gov.egov.order.created",
            Data = new { OrderId = 123 }
        };
        await producer.ProduceAsync(cloudEvent);
    }
}

Registering Consumer and Handlers

To consume events, register handlers using the fluent builder:

builder.Services.AddCloudEventHandlers(builder.Configuration.GetSection("MConnect:Consumer"))
    .AddSingletonHandler<MySimpleHandler>("md.gov.egov.order.*")
    .AddScopedHandler<MyTypedHandler, OrderData>("md.gov.egov.payment.completed");

Implementing a Handler

Implement IHandleCloudEvents for generic handling or IHandleCloudEvents<TData> for typed data:

public class MySimpleHandler : IHandleCloudEvents
{
    public async Task HandleAsync(CloudEventConsumerContext context, CancellationToken cancellationToken)
    {
        var cloudEvent = context.Event;
        // Process event...
        
        await context.ConfirmAsync(cancellationToken);
    }
}

public record OrderData(int OrderId);

public class MyTypedHandler : IHandleCloudEvents<OrderData>
{
    public async Task HandleAsync(CloudEventConsumerContext context, OrderData data, CancellationToken cancellationToken)
    {
        // Process typed data...
        await context.ConfirmAsync(cancellationToken);
    }
}

Testing

The solution includes a test suite using xUnit.

Running the tests

dotnet test

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines on how to get started.


Code of Conduct

This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.


AI Assistance

This repository contains an AGENTS.md file with instructions and context for AI coding agents to assist in development, ensuring consistency in code style and project structure.


License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in 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
10.0.5 105 4/14/2026