{"id":22538426,"url":"https://github.com/shuttle/shuttle.core.mediator","last_synced_at":"2025-10-28T08:50:43.648Z","repository":{"id":66349378,"uuid":"190386168","full_name":"Shuttle/Shuttle.Core.Mediator","owner":"Shuttle","description":"Implementation of the mediator mechanism.","archived":false,"fork":false,"pushed_at":"2025-03-02T14:03:37.000Z","size":166,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-06T03:04:55.239Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Shuttle.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":"2019-06-05T11:58:19.000Z","updated_at":"2025-03-02T14:03:40.000Z","dependencies_parsed_at":"2024-10-25T20:40:57.991Z","dependency_job_id":"4647aa99-6cf3-47fa-a15c-9070df329c1e","html_url":"https://github.com/Shuttle/Shuttle.Core.Mediator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Shuttle/Shuttle.Core.Mediator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shuttle%2FShuttle.Core.Mediator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shuttle%2FShuttle.Core.Mediator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shuttle%2FShuttle.Core.Mediator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shuttle%2FShuttle.Core.Mediator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shuttle","download_url":"https://codeload.github.com/Shuttle/Shuttle.Core.Mediator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shuttle%2FShuttle.Core.Mediator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281410760,"owners_count":26496368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-12-07T11:12:01.095Z","updated_at":"2025-10-28T08:50:43.612Z","avatar_url":"https://github.com/Shuttle.png","language":"C#","readme":"# Shuttle.Core.Mediator\r\n\r\n```\r\nPM\u003e Install-Package Shuttle.Core.Mediator\r\n```\r\n\r\nThe Shuttle.Core.Mediator package provides a [mediator pattern](https://en.wikipedia.org/wiki/Mediator_pattern) implementation.\r\n\r\n## Configuration\r\n\r\nIn order to get all the relevant bits working you would need to register the `IMediator` dependency along with all the relevant `IParticipant` dependencies.\r\n\r\nYou can register the mediator using `IServiceCollection`:\r\n\r\n```c#\r\nservices.AddMediator(builder =\u003e\r\n{\r\n    builder.AddParticipants(assembly);\r\n    builder.AddParticipant\u003cParticipant\u003e();\r\n    builder.AddParticipant(participantType);\r\n    builder.AddParticipant\u003cMessage\u003e(participant);\r\n    builder.AddParticipant(async (IParticipantContext\u003cT\u003e context) =\u003e\r\n    {\r\n        await Task.CompletedTask.ConfigureAwait(false);\r\n    });\r\n```\r\n\r\n## IMediator\r\n\r\nThe core interface is the `IMediator` interface and the default implementation provided is the `Mediator` class.\r\n\r\nParticipants types are instatiated from the `IServiceProvider` instance.  This means that it depends on how you register the type as to the behaviour.\r\n\r\n```c#\r\nTask SendAsync(object message, CancellationToken cancellationToken = default);\r\n```\r\n\r\nThe `SendAsync` method will find all participants that implement the `IParticipant\u003cT\u003e` with the type `T` of the message type that you are sending.\r\n\r\n## Participant implementations\r\n\r\n```c#\r\npublic interface IParticipant\u003cin T\u003e\r\n{\r\n    Task ProcessMessageAsync(IParticipantContext\u003cT\u003e context);\r\n}\r\n```\r\n\r\nA participant would handle the message that is sent using the mediator.  There may be any number of participants that process the message. \r\n\r\n## Design philosophy\r\n\r\nThere are no *request/response* semantics and the design philosophy here is that the message encapsulates the state that is passed along in a *pipes \u0026 filters* approach.\r\n\r\nHowever, you may wish to make use of one of the existing utility classes:-\r\n\r\n### RequestMessage\\\u003cTRequest\\\u003e\r\n\r\nThe only expectation from a `RequestMessage\u003cTRequest\u003e` instance is either a success or failure (along with the failure message).\r\n\r\n### RequestResponseMessage\\\u003cTRequest, TResponse\\\u003e\r\n\r\nThe `RequestResponseMessage\u003cTRequest, TResponse\u003e` takes an initial `TRequest` object and after the mediator processing would expect that there be a `TResponse` provided using the `.WithResponse(TResponse)` method.  The same success/failure mechanism used in the `RequestMessage\u003cTRequest\u003e` class is also available on this class.\r\n\r\n## Considerations\r\n\r\nIf you have a rather predictable sequential workflow and you require something with faster execution then you may wish to consider the [Shuttle.Core.Pipelines](http://shuttle.github.io/shuttle-core/shuttle-core-pipelines) package.  \r\n\r\nPerforming a benchmark for your use-case would be able to indicate the more suitable option.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuttle%2Fshuttle.core.mediator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshuttle%2Fshuttle.core.mediator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuttle%2Fshuttle.core.mediator/lists"}