{"id":21097467,"url":"https://github.com/emerbrito/dataverse-client-messaging","last_synced_at":"2026-04-28T14:34:01.058Z","repository":{"id":78700032,"uuid":"605748154","full_name":"emerbrito/dataverse-client-messaging","owner":"emerbrito","description":"Azure functions service bus message handler.","archived":false,"fork":false,"pushed_at":"2023-02-24T14:35:42.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-01T14:37:15.800Z","etag":null,"topics":["azure-functions","common-data-service","dataverse","dataverse-serviceclient","dynamics","dynamics-365","dynamics-crm","powerapps","powerplatform","service-bus"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emerbrito.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-23T20:20:17.000Z","updated_at":"2025-03-03T18:46:57.000Z","dependencies_parsed_at":"2023-03-12T05:11:31.055Z","dependency_job_id":null,"html_url":"https://github.com/emerbrito/dataverse-client-messaging","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/emerbrito/dataverse-client-messaging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emerbrito%2Fdataverse-client-messaging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emerbrito%2Fdataverse-client-messaging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emerbrito%2Fdataverse-client-messaging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emerbrito%2Fdataverse-client-messaging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emerbrito","download_url":"https://codeload.github.com/emerbrito/dataverse-client-messaging/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emerbrito%2Fdataverse-client-messaging/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32385178,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T11:25:28.583Z","status":"ssl_error","status_checked_at":"2026-04-28T11:25:05.435Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-functions","common-data-service","dataverse","dataverse-serviceclient","dynamics","dynamics-365","dynamics-crm","powerapps","powerplatform","service-bus"],"created_at":"2024-11-19T22:48:22.262Z","updated_at":"2026-04-28T14:34:01.031Z","avatar_url":"https://github.com/emerbrito.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EmBrito.Dataverse.Extensions.Messaging\n\n\n[![Nuget](https://img.shields.io/nuget/v/EmBrito.Dataverse.Extensions.Messaging)](https://www.nuget.org/packages/EmBrito.Dataverse.Extensions.Messaging)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/emerbrito/dataverse-client-messaging/dotnet-build.yml)](https://github.com/emerbrito/dataverse-client-messaging/actions/workflows/dotnet-build.yml)\n\n# Message Dispatcher\n\nThe `MessageDispatcher\u003cTMessage\u003e` dispatches a message to one or more handlers based on a message filter. The main purpose of the dispatcher is to abstract message handling.\n\n\n``` mermaid\nflowchart TB        \n    B[Dispatcher] --\u003e C{Dispatch}\n    C --\u003e|match handler| D[fa:fa-check Handler]\n    C --\u003e|match handler| E[fa:fa-check Handler]\n    C -.-|mismatch| F[fa:fa-times Handler]\n```\n\n## Using The Message Dispatcher\n\nStart by creating a dispatcher, which could be by instantiating the generic `MessageDispatcher\u003cTMessage\u003e` or extending it. Then create message handlers to handle the messages. \n\nYou can also let your DI container take care of the the dispatcher and handlers initialization (see the Dependency Injection section for details).\n\n### Creating a dispatcher\n\nA generic dispatcher to push string messages down to one or more handlers:\n\n``` csharp\npublic class HandleServiceBusFunction\n{\n    MessageDispatcher\u003cstring\u003e _dispatcher;\n\n    public HandleServiceBusFunction(MessageDispatcher\u003cstring\u003e dispatcher)\n    {\n        _dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));\n    }\n}\n```\n\nThis example will provide the exact same functionality as the previous but will result in code that is more readable and easier to understand, by extending the `MessageDispatcher\u003cstring\u003e` and creating an specialized class:\n\n``` csharp\npublic class StringMessageDispatcher : MessageDispatcher\u003cstring\u003e\n{\n    public StringMessageDispatcher(IServiceProvider serviceProvider, ILogger\u003cMessageDispatcher\u003cstring\u003e\u003e logger) \n        : base(serviceProvider, logger)\n    {\n    }\n}\n\npublic class HandleServiceBusFunction\n{\n    StringMessageDispatcher _dispatcher;\n\n    public HandleServiceBusFunction(StringMessageDispatcher dispatcher)\n    {\n        _dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));\n    }\n}\n\n```\n\n### Creating Message Handlers\n\nImplement the `IMessageHandler\u003cTMessage\u003e` to create a message handler. See the Dependency Injection section to understand how handlers are registered with dispatchers.\n\n``` csharp\npublic class MyContactHandler : IMessageHandler\u003cstring\u003e\n{\n    public bool CanHandle(string message)\n    {\n        // this filter will determine whether the \"Handle\"\n        // method will be called.\n        return message.Contains(\"@\");\n    }\n\n    public Task Handle(string message, CancellationToken cancellationToken)\n    {\n        // do something with the message\n    }\n}\n```\n\nSince handlers will be instantiated by the DI container you can specify dependencies in the constructor.\n\n``` csharp\n    public class MyUpdateHandler : IMessageHandler\u003cstring\u003e\n    {\n        HttpClient _httpClient;\n\n        public MyUpdateHandler(HttpClient httpClient)\n        {\n            _httpClient = httpClient ?? throw new ArgumentNullException();\n        }\n\n        public bool CanHandle(string message)\n        {\n            throw new NotImplementedException();\n        }\n\n        public Task Handle(string message, CancellationToken cancellationToken)\n        {\n            throw new NotImplementedException();\n        }\n    }\n```\n\n# DataverseMessageDispatcher\n\nThe `DataverseMessageDispatcher` is an implementation of the message dispatcher meant to dipatch the dataverse `RemoteExecutionContext` (the message sent by the dataverse through the Azure service bus integration).\n\nYou should extend the `DataverseMessageHandler` abstract class to create your own handlers based on your application needs.\n\n# Dependency Injection\n\nRegistering the built in `DataverseMessageDispatcher`. This will also register all `DataverseMessageHandler` in the specified assembly.\n\n``` csharp\npublic override void Configure(IFunctionsHostBuilder builder)\n{\n    builder.Services.AddOptions();\n    builder.Services.AddLogging();\n    builder.Services.AddDataverseMessagetDispatcher(typeof(MyAzureFunction).Assembly)\n}\n```\n\nThe `AddMessagetDispatcher` extension method will allow you to register a dispatcher and specify the handlers associated with it.\n\nExample 1: Limiting the numbers of handlers associated with the built in.`DataverseMessageDispatcher`.\n\n``` csharp\npublic override void Configure(IFunctionsHostBuilder builder)\n{\n    builder.Services.AddOptions();\n    builder.Services.AddLogging();\n    builder.Services.AddMessagetDispatcher\u003cDataverseMessageDispatcher\u003e(options =\u003e \n    {\n        options.AddHandler\u003cContactUpdateHandler\u003e();\n        options.AddHandler\u003cAccountCreateHandler\u003e();\n    })\n}\n```\n\nExample 2: Registering a custom dispatcher and associated message handlers.\n\n``` csharp\npublic override void Configure(IFunctionsHostBuilder builder)\n{\n    builder.Services.AddOptions();\n    builder.Services.AddLogging();\n    .AddMessagetDispatcher\u003cStringMessageDispatcher\u003e(options =\u003e\n    {\n        options.AddHandler\u003cEmailAddressHandler\u003e();\n        options.AddHandler\u003cPhoneNumberHandler\u003e();\n    })\n}\n```\n\nExample 3: Registering a custom dispatcher, scanning assmebly and associating all handlers implemeting `IMessageHandler\u003cstring\u003e`.\n\n``` csharp\npublic override void Configure(IFunctionsHostBuilder builder)\n{\n    builder.Services.AddOptions();\n    builder.Services.AddLogging();\n    .AddMessagetDispatcher\u003cStringMessageDispatcher\u003e(options =\u003e\n    {\n        options.ScanHandlers\u003cIMessageHandler\u003cstring\u003e\u003e(new[] \n        { \n            typeof(MessageDispatcherTests).Assembly \n        });\n    })\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femerbrito%2Fdataverse-client-messaging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femerbrito%2Fdataverse-client-messaging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femerbrito%2Fdataverse-client-messaging/lists"}