├── .gitignore ├── LICENSE ├── README.md ├── assets └── IconNuget.png ├── samples ├── SampleApp │ ├── Ping.cs │ ├── PingHandler.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── SampleApp.csproj │ └── SampleApp.sln └── SampleModular │ ├── Modules │ ├── Cadastro │ │ ├── Cadastro.csproj │ │ ├── ClienteService.cs │ │ ├── Commands │ │ │ ├── CadastrarClienteCommand.cs │ │ │ └── ExcluirClienteCommand.cs │ │ ├── Handlers │ │ │ └── ClienteHandler.cs │ │ └── IClienteService.cs │ ├── Crm │ │ ├── Crm.csproj │ │ └── Handlers │ │ │ └── NotificadorHandler.cs │ └── Financeiro │ │ ├── Financeiro.csproj │ │ └── Handlers │ │ └── GestaoContaHandler.cs │ ├── SampleModular.sln │ ├── SharedKernel │ ├── Events │ │ ├── ClienteCadastradoEvent.cs │ │ └── ClienteExcluidoEvent.cs │ └── SharedKernel.csproj │ └── WebApi │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ └── WebApi.csproj └── src ├── NetDevPack.SimpleMediator.Core ├── Extensions │ └── ServiceCollectionExtensions.cs ├── Implementation │ └── Mediator.cs ├── Interfaces │ ├── IMediator.cs │ ├── INotification.cs │ ├── INotificationHandler.cs │ ├── IRequest.cs │ └── IRequestHandler.cs └── NetDevPack.SimpleMediator.Core.csproj └── NetDevPack.SimpleMediator.sln /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | # but not Directory.Build.rsp, as it configures directory-level build defaults 86 | !Directory.Build.rsp 87 | *.sbr 88 | *.tlb 89 | *.tli 90 | *.tlh 91 | *.tmp 92 | *.tmp_proj 93 | *_wpftmp.csproj 94 | *.log 95 | *.tlog 96 | *.vspscc 97 | *.vssscc 98 | .builds 99 | *.pidb 100 | *.svclog 101 | *.scc 102 | 103 | # Chutzpah Test files 104 | _Chutzpah* 105 | 106 | # Visual C++ cache files 107 | ipch/ 108 | *.aps 109 | *.ncb 110 | *.opendb 111 | *.opensdf 112 | *.sdf 113 | *.cachefile 114 | *.VC.db 115 | *.VC.VC.opendb 116 | 117 | # Visual Studio profiler 118 | *.psess 119 | *.vsp 120 | *.vspx 121 | *.sap 122 | 123 | # Visual Studio Trace Files 124 | *.e2e 125 | 126 | # TFS 2012 Local Workspace 127 | $tf/ 128 | 129 | # Guidance Automation Toolkit 130 | *.gpState 131 | 132 | # ReSharper is a .NET coding add-in 133 | _ReSharper*/ 134 | *.[Rr]e[Ss]harper 135 | *.DotSettings.user 136 | 137 | # TeamCity is a build add-in 138 | _TeamCity* 139 | 140 | # DotCover is a Code Coverage Tool 141 | *.dotCover 142 | 143 | # AxoCover is a Code Coverage Tool 144 | .axoCover/* 145 | !.axoCover/settings.json 146 | 147 | # Coverlet is a free, cross platform Code Coverage Tool 148 | coverage*.json 149 | coverage*.xml 150 | coverage*.info 151 | 152 | # Visual Studio code coverage results 153 | *.coverage 154 | *.coveragexml 155 | 156 | # NCrunch 157 | _NCrunch_* 158 | .*crunch*.local.xml 159 | nCrunchTemp_* 160 | 161 | # MightyMoose 162 | *.mm.* 163 | AutoTest.Net/ 164 | 165 | # Web workbench (sass) 166 | .sass-cache/ 167 | 168 | # Installshield output folder 169 | [Ee]xpress/ 170 | 171 | # DocProject is a documentation generator add-in 172 | DocProject/buildhelp/ 173 | DocProject/Help/*.HxT 174 | DocProject/Help/*.HxC 175 | DocProject/Help/*.hhc 176 | DocProject/Help/*.hhk 177 | DocProject/Help/*.hhp 178 | DocProject/Help/Html2 179 | DocProject/Help/html 180 | 181 | # Click-Once directory 182 | publish/ 183 | 184 | # Publish Web Output 185 | *.[Pp]ublish.xml 186 | *.azurePubxml 187 | # Note: Comment the next line if you want to checkin your web deploy settings, 188 | # but database connection strings (with potential passwords) will be unencrypted 189 | *.pubxml 190 | *.publishproj 191 | 192 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 193 | # checkin your Azure Web App publish settings, but sensitive information contained 194 | # in these scripts will be unencrypted 195 | PublishScripts/ 196 | 197 | # NuGet Packages 198 | *.nupkg 199 | # NuGet Symbol Packages 200 | *.snupkg 201 | # The packages folder can be ignored because of Package Restore 202 | **/[Pp]ackages/* 203 | # except build/, which is used as an MSBuild target. 204 | !**/[Pp]ackages/build/ 205 | # Uncomment if necessary however generally it will be regenerated when needed 206 | #!**/[Pp]ackages/repositories.config 207 | # NuGet v3's project.json files produces more ignorable files 208 | *.nuget.props 209 | *.nuget.targets 210 | 211 | # Microsoft Azure Build Output 212 | csx/ 213 | *.build.csdef 214 | 215 | # Microsoft Azure Emulator 216 | ecf/ 217 | rcf/ 218 | 219 | # Windows Store app package directories and files 220 | AppPackages/ 221 | BundleArtifacts/ 222 | Package.StoreAssociation.xml 223 | _pkginfo.txt 224 | *.appx 225 | *.appxbundle 226 | *.appxupload 227 | 228 | # Visual Studio cache files 229 | # files ending in .cache can be ignored 230 | *.[Cc]ache 231 | # but keep track of directories ending in .cache 232 | !?*.[Cc]ache/ 233 | 234 | # Others 235 | ClientBin/ 236 | ~$* 237 | *~ 238 | *.dbmdl 239 | *.dbproj.schemaview 240 | *.jfm 241 | *.pfx 242 | *.publishsettings 243 | orleans.codegen.cs 244 | 245 | # Including strong name files can present a security risk 246 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 247 | #*.snk 248 | 249 | # Since there are multiple workflows, uncomment next line to ignore bower_components 250 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 251 | #bower_components/ 252 | 253 | # RIA/Silverlight projects 254 | Generated_Code/ 255 | 256 | # Backup & report files from converting an old project file 257 | # to a newer Visual Studio version. Backup files are not needed, 258 | # because we have git ;-) 259 | _UpgradeReport_Files/ 260 | Backup*/ 261 | UpgradeLog*.XML 262 | UpgradeLog*.htm 263 | ServiceFabricBackup/ 264 | *.rptproj.bak 265 | 266 | # SQL Server files 267 | *.mdf 268 | *.ldf 269 | *.ndf 270 | 271 | # Business Intelligence projects 272 | *.rdl.data 273 | *.bim.layout 274 | *.bim_*.settings 275 | *.rptproj.rsuser 276 | *- [Bb]ackup.rdl 277 | *- [Bb]ackup ([0-9]).rdl 278 | *- [Bb]ackup ([0-9][0-9]).rdl 279 | 280 | # Microsoft Fakes 281 | FakesAssemblies/ 282 | 283 | # GhostDoc plugin setting file 284 | *.GhostDoc.xml 285 | 286 | # Node.js Tools for Visual Studio 287 | .ntvs_analysis.dat 288 | node_modules/ 289 | 290 | # Visual Studio 6 build log 291 | *.plg 292 | 293 | # Visual Studio 6 workspace options file 294 | *.opt 295 | 296 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 297 | *.vbw 298 | 299 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 300 | *.vbp 301 | 302 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 303 | *.dsw 304 | *.dsp 305 | 306 | # Visual Studio 6 technical files 307 | *.ncb 308 | *.aps 309 | 310 | # Visual Studio LightSwitch build output 311 | **/*.HTMLClient/GeneratedArtifacts 312 | **/*.DesktopClient/GeneratedArtifacts 313 | **/*.DesktopClient/ModelManifest.xml 314 | **/*.Server/GeneratedArtifacts 315 | **/*.Server/ModelManifest.xml 316 | _Pvt_Extensions 317 | 318 | # Paket dependency manager 319 | .paket/paket.exe 320 | paket-files/ 321 | 322 | # FAKE - F# Make 323 | .fake/ 324 | 325 | # CodeRush personal settings 326 | .cr/personal 327 | 328 | # Python Tools for Visual Studio (PTVS) 329 | __pycache__/ 330 | *.pyc 331 | 332 | # Cake - Uncomment if you are using it 333 | # tools/** 334 | # !tools/packages.config 335 | 336 | # Tabs Studio 337 | *.tss 338 | 339 | # Telerik's JustMock configuration file 340 | *.jmconfig 341 | 342 | # BizTalk build output 343 | *.btp.cs 344 | *.btm.cs 345 | *.odx.cs 346 | *.xsd.cs 347 | 348 | # OpenCover UI analysis results 349 | OpenCover/ 350 | 351 | # Azure Stream Analytics local run output 352 | ASALocalRun/ 353 | 354 | # MSBuild Binary and Structured Log 355 | *.binlog 356 | 357 | # NVidia Nsight GPU debugger configuration file 358 | *.nvuser 359 | 360 | # MFractors (Xamarin productivity tool) working folder 361 | .mfractor/ 362 | 363 | # Local History for Visual Studio 364 | .localhistory/ 365 | 366 | # Visual Studio History (VSHistory) files 367 | .vshistory/ 368 | 369 | # BeatPulse healthcheck temp database 370 | healthchecksdb 371 | 372 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 373 | MigrationBackup/ 374 | 375 | # Ionide (cross platform F# VS Code tools) working folder 376 | .ionide/ 377 | 378 | # Fody - auto-generated XML schema 379 | FodyWeavers.xsd 380 | 381 | # VS Code files for those working on multiple tools 382 | .vscode/* 383 | !.vscode/settings.json 384 | !.vscode/tasks.json 385 | !.vscode/launch.json 386 | !.vscode/extensions.json 387 | *.code-workspace 388 | 389 | # Local History for Visual Studio Code 390 | .history/ 391 | 392 | # Windows Installer files from build outputs 393 | *.cab 394 | *.msi 395 | *.msix 396 | *.msm 397 | *.msp 398 | 399 | # JetBrains Rider 400 | *.sln.iml 401 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 NetDevPack 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | .NET DevPack 2 | 3 | # SimpleMediator 4 | 5 | A lightweight and straightforward mediator implementation for .NET applications, facilitating in-process messaging with minimal setup. 6 | 7 | | Package | Version | Popularity | 8 | | ------- | ----- | ----- | 9 | | `NetDevPack.SimpleMediator` | [![NuGet](https://img.shields.io/nuget/v/NetDevPack.SimpleMediator.svg)](https://nuget.org/packages/NetDevPack.SimpleMediator) | [![Nuget](https://img.shields.io/nuget/dt/NetDevPack.SimpleMediator.svg)](https://nuget.org/packages/NetDevPack.SimpleMediator) | 10 | 11 | 12 | ## Give a Star! ⭐ 13 | 14 | If you found this project helpful or it assisted you in any way, please give it a star. It helps to support the project and the developers. 15 | 16 | ## Samples 17 | 18 | You can find complete example projects demonstrating how to use the SimpleMediator in the [`/samples`](./samples) folder. 19 | 20 | These include: 21 | 22 | - ✅ Basic usage with `Send` and `Publish` 23 | - ✅ Modular application structure 24 | - ✅ Manual and automatic registration of handlers 25 | 26 | Feel free to explore and run them to see how the mediator works in different scenarios. 27 | 28 | ## Getting Started 29 | 30 | ### Installation 31 | 32 | You can install the SimpleMediator package via NuGet Package Manager or the .NET CLI: 33 | 34 | ```bash 35 | dotnet add package NetDevPack.SimpleMediator 36 | ``` 37 | 38 | ### Using Contracts-Only Package 39 | 40 | To reference only the contracts for SimpleMediator, which includes: 41 | 42 | - `IRequest` (including generic variants) 43 | - Represents a command or query that expects a single response 44 | - `INotification` 45 | - Represents an event broadcast to multiple handlers (if any) 46 | 47 | ### Advanced Usage: Request + Notification 48 | 49 | This example demonstrates how to combine a `Request` (command/query) and a `Notification` (event) in a real-world use case. 50 | 51 | > ✅ This scenario uses only `Microsoft.Extensions.DependencyInjection.Abstractions` for DI registration — no framework-specific packages. 52 | 53 | --- 54 | 55 | #### 1. Define the Request and Notification 56 | 57 | ```csharp 58 | public class CreateCustomerCommand : IRequest 59 | { 60 | public string Name { get; set; } 61 | } 62 | 63 | public class CustomerCreatedEvent : INotification 64 | { 65 | public Guid CustomerId { get; } 66 | 67 | public CustomerCreatedEvent(Guid customerId) 68 | { 69 | CustomerId = customerId; 70 | } 71 | } 72 | ``` 73 | 74 | --- 75 | 76 | #### 2. Implement the Handlers 77 | 78 | ```csharp 79 | public class CreateCustomerHandler : IRequestHandler 80 | { 81 | private readonly IMediator _mediator; 82 | 83 | public CreateCustomerHandler(IMediator mediator) 84 | { 85 | _mediator = mediator; 86 | } 87 | 88 | public async Task Handle(CreateCustomerCommand request, CancellationToken cancellationToken) 89 | { 90 | var id = Guid.NewGuid(); 91 | 92 | // Simulate persistence... 93 | 94 | // Publish event 95 | await _mediator.Publish(new CustomerCreatedEvent(id), cancellationToken); 96 | 97 | return $"Customer '{request.Name}' created with ID {id}"; 98 | } 99 | } 100 | 101 | public class SendWelcomeEmailHandler : INotificationHandler 102 | { 103 | public Task Handle(CustomerCreatedEvent notification, CancellationToken cancellationToken) 104 | { 105 | Console.WriteLine($"Sending welcome email to customer {notification.CustomerId}"); 106 | return Task.CompletedTask; 107 | } 108 | } 109 | ``` 110 | 111 | --- 112 | 113 | #### 3. Register the Handlers (Dependency Injection) 114 | 115 | You can register everything manually if you want full control: 116 | 117 | ```csharp 118 | services.AddSingleton(); 119 | 120 | services.AddTransient, CreateCustomerHandler>(); 121 | services.AddTransient, SendWelcomeEmailHandler>(); 122 | ``` 123 | 124 | Or use assembly scanning with: 125 | 126 | ```csharp 127 | services.AddSimpleMediator(); 128 | ``` 129 | 130 | --- 131 | 132 | #### 4. Execute the Flow 133 | 134 | ```csharp 135 | public class CustomerAppService 136 | { 137 | private readonly IMediator _mediator; 138 | 139 | public CustomerAppService(IMediator mediator) 140 | { 141 | _mediator = mediator; 142 | } 143 | 144 | public async Task CreateCustomer(string name) 145 | { 146 | return await _mediator.Send(new CreateCustomerCommand { Name = name }); 147 | } 148 | } 149 | ``` 150 | 151 | --- 152 | 153 | When the `CreateCustomer` method is called: 154 | 155 | 1. `CreateCustomerHandler` handles the request 156 | 2. It creates and persists the customer (simulated) 157 | 3. It publishes a `CustomerCreatedEvent` 158 | 4. `SendWelcomeEmailHandler` handles the event 159 | 160 | This structure cleanly separates **commands** (which change state and return a result) from **notifications** (which communicate to the rest of the system that something happened). 161 | 162 | ## Features 163 | 164 | - **Lightweight**: Minimal dependencies and straightforward setup. 165 | - **In-Process Messaging**: Facilitates in-process communication between components. 166 | - **Handler Registration**: Automatically registers handlers from specified assemblies. 167 | 168 | ## Compatibility 169 | 170 | NetDevPack.SimpleMediator targets .NET Standard 2.1, and is compatible with .NET Core 3.1+, .NET 5+, .NET 6+, .NET 7+, .NET 8, and newer versions of the .NET runtime. 171 | 172 | ## About 173 | 174 | NetDevPack.SimpleMediator was developed by [Eduardo Pires](https://desenvolvedor.io) under the MIT license. 175 | -------------------------------------------------------------------------------- /assets/IconNuget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NetDevPack/SimpleMediator/507bf3e344120ac02272b8f4d9838044ea89af71/assets/IconNuget.png -------------------------------------------------------------------------------- /samples/SampleApp/Ping.cs: -------------------------------------------------------------------------------- 1 | using NetDevPack.SimpleMediator.Core.Interfaces; 2 | 3 | public class Ping : IRequest 4 | { 5 | public string Message { get; set; } = "Ping!"; 6 | } -------------------------------------------------------------------------------- /samples/SampleApp/PingHandler.cs: -------------------------------------------------------------------------------- 1 | using NetDevPack.SimpleMediator.Core.Interfaces; 2 | 3 | public class PingHandler : IRequestHandler 4 | { 5 | public Task Handle(Ping request, CancellationToken cancellationToken) 6 | { 7 | return Task.FromResult($"Pong: {request.Message}"); 8 | } 9 | } -------------------------------------------------------------------------------- /samples/SampleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using NetDevPack.SimpleMediator.Core.Extensions; 2 | using NetDevPack.SimpleMediator.Core.Interfaces; 3 | 4 | var builder = WebApplication.CreateBuilder(args); 5 | builder.Services.AddSimpleMediator(typeof(Program).Assembly); 6 | 7 | var app = builder.Build(); 8 | 9 | app.MapGet("/", async (IMediator mediator) => 10 | { 11 | var result = await mediator.Send(new Ping { Message = "Hello Mediator" }); 12 | return Results.Ok(result); 13 | }); 14 | 15 | app.Run(); -------------------------------------------------------------------------------- /samples/SampleApp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "SampleApp": { 4 | "commandName": "Project", 5 | "launchBrowser": true, 6 | "environmentVariables": { 7 | "ASPNETCORE_ENVIRONMENT": "Development" 8 | }, 9 | "applicationUrl": "https://localhost:61455;http://localhost:61456" 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /samples/SampleApp/SampleApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /samples/SampleApp/SampleApp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.13.35919.96 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApp", "SampleApp.csproj", "{0035CB67-ADC7-446D-9358-4B84B1E8C153}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project Reference", "Project Reference", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetDevPack.SimpleMediator.Core", "..\..\src\NetDevPack.SimpleMediator.Core\NetDevPack.SimpleMediator.Core.csproj", "{EFB444B7-6825-50E8-1CCC-A7D05BC852FC}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {0035CB67-ADC7-446D-9358-4B84B1E8C153}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {0035CB67-ADC7-446D-9358-4B84B1E8C153}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {0035CB67-ADC7-446D-9358-4B84B1E8C153}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {0035CB67-ADC7-446D-9358-4B84B1E8C153}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {EFB444B7-6825-50E8-1CCC-A7D05BC852FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {EFB444B7-6825-50E8-1CCC-A7D05BC852FC}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {EFB444B7-6825-50E8-1CCC-A7D05BC852FC}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {EFB444B7-6825-50E8-1CCC-A7D05BC852FC}.Release|Any CPU.Build.0 = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(NestedProjects) = preSolution 31 | {EFB444B7-6825-50E8-1CCC-A7D05BC852FC} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} 32 | EndGlobalSection 33 | GlobalSection(ExtensibilityGlobals) = postSolution 34 | SolutionGuid = {BFFAFD81-64E9-4E48-B6AD-52AB2CBF45D4} 35 | EndGlobalSection 36 | EndGlobal 37 | -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Cadastro/Cadastro.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | enable 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Cadastro/ClienteService.cs: -------------------------------------------------------------------------------- 1 | using Cadastro.Commands; 2 | using NetDevPack.SimpleMediator.Core.Interfaces; 3 | using System.Threading.Tasks; 4 | 5 | namespace Cadastro; 6 | 7 | public class ClienteService : IClienteService 8 | { 9 | private readonly IMediator _mediator; 10 | 11 | public ClienteService(IMediator mediator) 12 | { 13 | _mediator = mediator; 14 | } 15 | 16 | public async Task CadastrarCliente(CadastrarClienteCommand cliente) 17 | { 18 | var resultado = await _mediator.Send(new CadastrarClienteCommand {Id = cliente.Id, Nome = cliente.Nome }); 19 | return resultado; 20 | } 21 | 22 | public async Task ExcluirCliente(ExcluirClienteCommand cliente) 23 | { 24 | var resultado = await _mediator.Send(new ExcluirClienteCommand { Id = cliente.Id }); 25 | return resultado; 26 | } 27 | } -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Cadastro/Commands/CadastrarClienteCommand.cs: -------------------------------------------------------------------------------- 1 | using NetDevPack.SimpleMediator.Core.Interfaces; 2 | using System; 3 | 4 | namespace Cadastro.Commands; 5 | 6 | public class CadastrarClienteCommand : IRequest 7 | { 8 | public Guid Id { get; set; } 9 | public string Nome { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Cadastro/Commands/ExcluirClienteCommand.cs: -------------------------------------------------------------------------------- 1 | using NetDevPack.SimpleMediator.Core.Interfaces; 2 | using System; 3 | 4 | namespace Cadastro.Commands; 5 | 6 | public class ExcluirClienteCommand : IRequest 7 | { 8 | public Guid Id { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Cadastro/Handlers/ClienteHandler.cs: -------------------------------------------------------------------------------- 1 | using Cadastro.Commands; 2 | using NetDevPack.SimpleMediator.Core.Interfaces; 3 | using System.Threading.Tasks; 4 | using System.Threading; 5 | using System; 6 | 7 | namespace Cadastro.Handlers; 8 | 9 | public class ClienteHandler : 10 | IRequestHandler, 11 | IRequestHandler 12 | { 13 | private readonly IMediator _mediator; 14 | 15 | public ClienteHandler(IMediator mediator) 16 | { 17 | _mediator = mediator; 18 | } 19 | 20 | public async Task Handle(CadastrarClienteCommand request, CancellationToken cancellationToken) 21 | { 22 | // simula persistência (poderia usar um repositório aqui) 23 | request.Id = Guid.NewGuid(); 24 | 25 | // dispara evento após criação 26 | await _mediator.Publish(new ClienteCadastradoEvent(request.Id), cancellationToken); 27 | 28 | return $"Cliente {request.Nome} cadastrado com sucesso."; 29 | } 30 | 31 | public async Task Handle(ExcluirClienteCommand request, CancellationToken cancellationToken) 32 | { 33 | // dispara evento após criação 34 | await _mediator.Publish(new ClienteExcluidoEvent(request.Id), cancellationToken); 35 | 36 | return true; 37 | } 38 | } -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Cadastro/IClienteService.cs: -------------------------------------------------------------------------------- 1 | using Cadastro.Commands; 2 | using System.Threading.Tasks; 3 | 4 | namespace Cadastro 5 | { 6 | public interface IClienteService 7 | { 8 | Task CadastrarCliente(CadastrarClienteCommand cliente); 9 | Task ExcluirCliente(ExcluirClienteCommand cliente); 10 | } 11 | } -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Crm/Crm.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net8.0 4 | enable 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Crm/Handlers/NotificadorHandler.cs: -------------------------------------------------------------------------------- 1 | using NetDevPack.SimpleMediator.Core.Interfaces; 2 | using System; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace Crm.Handlers; 7 | 8 | public class NotificadorHandler : 9 | INotificationHandler, 10 | INotificationHandler 11 | { 12 | public Task Handle(ClienteCadastradoEvent notification, CancellationToken cancellationToken) 13 | { 14 | Console.WriteLine($"[CRM] Enviando e-mail de boas-vindas ao cliente {notification.ClienteId}"); 15 | return Task.CompletedTask; 16 | } 17 | 18 | public Task Handle(ClienteExcluidoEvent notification, CancellationToken cancellationToken) 19 | { 20 | Console.WriteLine($"[CRM] Enviando e-mail de despedidas ao cliente {notification.ClienteId}"); 21 | return Task.CompletedTask; 22 | } 23 | } -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Financeiro/Financeiro.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | enable 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/SampleModular/Modules/Financeiro/Handlers/GestaoContaHandler.cs: -------------------------------------------------------------------------------- 1 | using NetDevPack.SimpleMediator.Core.Interfaces; 2 | using System; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace Financeiro.Handlers; 7 | 8 | public class GestaoContaHandler : 9 | INotificationHandler, 10 | INotificationHandler 11 | { 12 | public Task Handle(ClienteCadastradoEvent notification, CancellationToken cancellationToken) 13 | { 14 | Console.WriteLine($"[Financeiro] Criando conta para cliente {notification.ClienteId}"); 15 | return Task.CompletedTask; 16 | } 17 | 18 | public Task Handle(ClienteExcluidoEvent notification, CancellationToken cancellationToken) 19 | { 20 | Console.WriteLine($"[Financeiro] Excluindo conta do cliente {notification.ClienteId}"); 21 | return Task.CompletedTask; 22 | } 23 | } -------------------------------------------------------------------------------- /samples/SampleModular/SampleModular.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.13.35919.96 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "WebApi\WebApi.csproj", "{41FA5442-7321-6176-C48B-B0AABCA09A7D}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Domain", "Domain", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cadastro", "Modules\Cadastro\Cadastro.csproj", "{93804936-16E9-D23F-3CF1-AF244FE9856F}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crm", "Modules\Crm\Crm.csproj", "{FE33E0B0-F476-75B7-FF47-FCA4908E9C14}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Financeiro", "Modules\Financeiro\Financeiro.csproj", "{51818623-018A-D5AD-D259-C0B306E58BFE}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedKernel", "SharedKernel\SharedKernel.csproj", "{C71DB168-5872-1C86-3B8B-5FDF83D4892C}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{F1320D1E-3342-4F4B-A827-121F3D8AF2E5}" 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|Any CPU = Debug|Any CPU 23 | Release|Any CPU = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {41FA5442-7321-6176-C48B-B0AABCA09A7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {41FA5442-7321-6176-C48B-B0AABCA09A7D}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {41FA5442-7321-6176-C48B-B0AABCA09A7D}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {41FA5442-7321-6176-C48B-B0AABCA09A7D}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {93804936-16E9-D23F-3CF1-AF244FE9856F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {93804936-16E9-D23F-3CF1-AF244FE9856F}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {93804936-16E9-D23F-3CF1-AF244FE9856F}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {93804936-16E9-D23F-3CF1-AF244FE9856F}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {FE33E0B0-F476-75B7-FF47-FCA4908E9C14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {FE33E0B0-F476-75B7-FF47-FCA4908E9C14}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {FE33E0B0-F476-75B7-FF47-FCA4908E9C14}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {FE33E0B0-F476-75B7-FF47-FCA4908E9C14}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {51818623-018A-D5AD-D259-C0B306E58BFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {51818623-018A-D5AD-D259-C0B306E58BFE}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {51818623-018A-D5AD-D259-C0B306E58BFE}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {51818623-018A-D5AD-D259-C0B306E58BFE}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {C71DB168-5872-1C86-3B8B-5FDF83D4892C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {C71DB168-5872-1C86-3B8B-5FDF83D4892C}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {C71DB168-5872-1C86-3B8B-5FDF83D4892C}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {C71DB168-5872-1C86-3B8B-5FDF83D4892C}.Release|Any CPU.Build.0 = Release|Any CPU 46 | EndGlobalSection 47 | GlobalSection(SolutionProperties) = preSolution 48 | HideSolutionNode = FALSE 49 | EndGlobalSection 50 | GlobalSection(NestedProjects) = preSolution 51 | {93804936-16E9-D23F-3CF1-AF244FE9856F} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} 52 | {FE33E0B0-F476-75B7-FF47-FCA4908E9C14} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} 53 | {51818623-018A-D5AD-D259-C0B306E58BFE} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} 54 | {C71DB168-5872-1C86-3B8B-5FDF83D4892C} = {F1320D1E-3342-4F4B-A827-121F3D8AF2E5} 55 | EndGlobalSection 56 | GlobalSection(ExtensibilityGlobals) = postSolution 57 | SolutionGuid = {DE2A29F1-BA6D-4834-8371-B0BDC4724822} 58 | EndGlobalSection 59 | EndGlobal 60 | -------------------------------------------------------------------------------- /samples/SampleModular/SharedKernel/Events/ClienteCadastradoEvent.cs: -------------------------------------------------------------------------------- 1 | using NetDevPack.SimpleMediator.Core.Interfaces; 2 | using System; 3 | 4 | public record ClienteCadastradoEvent(Guid ClienteId) : INotification; 5 | 6 | -------------------------------------------------------------------------------- /samples/SampleModular/SharedKernel/Events/ClienteExcluidoEvent.cs: -------------------------------------------------------------------------------- 1 | using NetDevPack.SimpleMediator.Core.Interfaces; 2 | using System; 3 | 4 | public record ClienteExcluidoEvent(Guid ClienteId) : INotification; 5 | 6 | -------------------------------------------------------------------------------- /samples/SampleModular/SharedKernel/SharedKernel.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | enable 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/SampleModular/WebApi/Program.cs: -------------------------------------------------------------------------------- 1 | using Cadastro; 2 | using Cadastro.Commands; 3 | using Cadastro.Handlers; 4 | using Crm.Handlers; 5 | using Financeiro.Handlers; 6 | using Microsoft.AspNetCore.Mvc; 7 | using NetDevPack.SimpleMediator.Core.Extensions; 8 | using NetDevPack.SimpleMediator.Core.Implementation; 9 | using NetDevPack.SimpleMediator.Core.Interfaces; 10 | 11 | var builder = WebApplication.CreateBuilder(args); 12 | var services = builder.Services; 13 | 14 | services.AddEndpointsApiExplorer(); 15 | services.AddSwaggerGen(); 16 | 17 | services.AddScoped(); 18 | 19 | // REGISTRO DO MEDIATOR 20 | 21 | // Mais performatico 22 | //builder.Services.AddSimpleMediator("Cadastro", "Crm", "Financeiro", "SharedKernel"); 23 | 24 | // Mais custoso 25 | builder.Services.AddSimpleMediator(); 26 | //builder.Services.AddSimpleMediator(AppDomain.CurrentDomain.GetAssemblies()); 27 | 28 | // Mais trabalhoso 29 | //services.AddSingleton(); 30 | //services.AddTransient, ClienteHandler>(); 31 | //services.AddTransient, ClienteHandler>(); 32 | //services.AddTransient, GestaoContaHandler>(); 33 | //services.AddTransient, NotificadorHandler>(); 34 | //services.AddTransient, GestaoContaHandler>(); 35 | //services.AddTransient, NotificadorHandler>(); 36 | 37 | var app = builder.Build(); 38 | 39 | if (app.Environment.IsDevelopment()) 40 | { 41 | app.UseSwagger(); 42 | app.UseSwaggerUI(); 43 | } 44 | 45 | app.MapPost("/cadastrar", async ([FromBody] CadastrarClienteCommand command, IClienteService service) => 46 | { 47 | var resultado = await service.CadastrarCliente(command); 48 | return Results.Ok(resultado); 49 | }).WithName("CadastrarCliente") 50 | .WithTags("Clientes"); 51 | 52 | app.MapPost("/excluir", async ([FromBody] ExcluirClienteCommand command, IClienteService service) => 53 | { 54 | var resultado = await service.ExcluirCliente(command); 55 | 56 | if (!resultado) 57 | return Results.BadRequest($"Problema ao excluir o cliente {command.Id}"); 58 | 59 | return Results.Ok(command.Id); 60 | 61 | }).WithName("ExcluirCliente") 62 | .WithTags("Clientes"); 63 | 64 | app.Run(); -------------------------------------------------------------------------------- /samples/SampleModular/WebApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "WebApi": { 4 | "commandName": "Project", 5 | "launchBrowser": true, 6 | "launchUrl": "swagger", 7 | "environmentVariables": { 8 | "ASPNETCORE_ENVIRONMENT": "Development" 9 | }, 10 | "applicationUrl": "https://localhost:61861;http://localhost:61862" 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /samples/SampleModular/WebApi/WebApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | enable 5 | enable 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/NetDevPack.SimpleMediator.Core/Extensions/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace NetDevPack.SimpleMediator 7 | { 8 | 9 | public static class ServiceCollectionExtensions 10 | { 11 | public static IServiceCollection AddSimpleMediator( 12 | this IServiceCollection services, 13 | params object[] args) 14 | { 15 | var assemblies = ResolveAssemblies(args); 16 | 17 | services.AddSingleton(); 18 | 19 | RegisterHandlers(services, assemblies, typeof(INotificationHandler<>)); 20 | RegisterHandlers(services, assemblies, typeof(IRequestHandler<,>)); 21 | 22 | return services; 23 | } 24 | 25 | private static Assembly[] ResolveAssemblies(object[] args) 26 | { 27 | // Return ALL 28 | if (args == null || args.Length == 0) 29 | { 30 | return AppDomain.CurrentDomain 31 | .GetAssemblies() 32 | .Where(a => !a.IsDynamic && !string.IsNullOrWhiteSpace(a.FullName)) 33 | .ToArray(); 34 | } 35 | 36 | // Return all informed (same behavior as above) 37 | if (args.All(a => a is Assembly)) 38 | return args.Cast().ToArray(); 39 | 40 | // Return filtered by namespace (most performatic) 41 | if (args.All(a => a is string)) 42 | { 43 | var prefixes = args.Cast().ToArray(); 44 | return AppDomain.CurrentDomain 45 | .GetAssemblies() 46 | .Where(a => 47 | !a.IsDynamic && 48 | !string.IsNullOrWhiteSpace(a.FullName) && 49 | prefixes.Any(p => a.FullName!.StartsWith(p))) 50 | .ToArray(); 51 | } 52 | 53 | throw new ArgumentException("Invalid parameters for AddSimpleMediator(). Use: no arguments, Assembly[], or prefix strings."); 54 | } 55 | 56 | 57 | private static void RegisterHandlers(IServiceCollection services, Assembly[] assemblies, Type handlerInterface) 58 | { 59 | var types = assemblies.SelectMany(a => a.GetTypes()) 60 | .Where(t => t.IsClass && !t.IsAbstract) 61 | .ToList(); 62 | 63 | foreach (var type in types) 64 | { 65 | var interfaces = type.GetInterfaces() 66 | .Where(i => 67 | i.IsGenericType && 68 | i.GetGenericTypeDefinition() == handlerInterface); 69 | 70 | foreach (var iface in interfaces) 71 | { 72 | services.AddTransient(iface, type); 73 | } 74 | } 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /src/NetDevPack.SimpleMediator.Core/Implementation/Mediator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Microsoft.Extensions.DependencyInjection; 5 | 6 | namespace NetDevPack.SimpleMediator 7 | { 8 | 9 | public class Mediator : IMediator 10 | { 11 | private readonly IServiceProvider _provider; 12 | 13 | public Mediator(IServiceProvider provider) 14 | { 15 | _provider = provider; 16 | } 17 | 18 | public async Task Send(IRequest request, CancellationToken cancellationToken = default) 19 | { 20 | var handlerType = typeof(IRequestHandler<,>).MakeGenericType(request.GetType(), typeof(TResponse)); 21 | var handler = _provider.GetService(handlerType); 22 | if (handler == null) 23 | throw new InvalidOperationException($"Handler not found for {request.GetType().Name}"); 24 | 25 | return await (Task)handlerType 26 | .GetMethod("Handle")! 27 | .Invoke(handler, new object[] { request, cancellationToken })!; 28 | } 29 | 30 | public async Task Publish(TNotification notification, CancellationToken cancellationToken = default) 31 | where TNotification : INotification 32 | { 33 | var handlerType = typeof(INotificationHandler<>).MakeGenericType(notification.GetType()); 34 | var handlers = _provider.GetServices(handlerType); 35 | 36 | foreach (var handler in handlers) 37 | { 38 | await (Task)handlerType 39 | .GetMethod("Handle")! 40 | .Invoke(handler, new object[] { notification, cancellationToken })!; 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/NetDevPack.SimpleMediator.Core/Interfaces/IMediator.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace NetDevPack.SimpleMediator 5 | { 6 | 7 | public interface IMediator 8 | { 9 | Task Send(IRequest request, CancellationToken cancellationToken = default); 10 | Task Publish(TNotification notification, CancellationToken cancellationToken = default) 11 | where TNotification : INotification; 12 | } 13 | } -------------------------------------------------------------------------------- /src/NetDevPack.SimpleMediator.Core/Interfaces/INotification.cs: -------------------------------------------------------------------------------- 1 | namespace NetDevPack.SimpleMediator 2 | { 3 | 4 | public interface INotification { } 5 | } -------------------------------------------------------------------------------- /src/NetDevPack.SimpleMediator.Core/Interfaces/INotificationHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace NetDevPack.SimpleMediator 5 | { 6 | 7 | public interface INotificationHandler 8 | where TNotification : INotification 9 | { 10 | Task Handle(TNotification notification, CancellationToken cancellationToken); 11 | } 12 | } -------------------------------------------------------------------------------- /src/NetDevPack.SimpleMediator.Core/Interfaces/IRequest.cs: -------------------------------------------------------------------------------- 1 | namespace NetDevPack.SimpleMediator 2 | { 3 | 4 | public interface IRequest { } 5 | } -------------------------------------------------------------------------------- /src/NetDevPack.SimpleMediator.Core/Interfaces/IRequestHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace NetDevPack.SimpleMediator 5 | { 6 | 7 | public interface IRequestHandler 8 | where TRequest : IRequest 9 | { 10 | Task Handle(TRequest request, CancellationToken cancellationToken); 11 | } 12 | } -------------------------------------------------------------------------------- /src/NetDevPack.SimpleMediator.Core/NetDevPack.SimpleMediator.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netstandard2.1 4 | enable 5 | false 6 | NetDevPack.SimpleMediator 7 | NetDevPack.SimpleMediator 8 | NetDevPack.SimpleMediator 9 | Eduardo Pires 10 | desenvolvedor.io 11 | Simple mediator implementation in .NET, In-process messaging with no dependencies. 12 | Simple mediator implementation in .NET, In-process messaging with no dependencies. 13 | https://github.com/EduardoPires/NetDevPack 14 | IconNuget.png 15 | https://github.com/NetDevPack/SimpleMediator 16 | Public 17 | MIT 18 | 1.2.0 19 | NetDevPack.SimpleMediator 20 | README.md 21 | Mediator, MediatR 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | True 31 | 32 | 33 | 34 | True 35 | \ 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/NetDevPack.SimpleMediator.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.13.35806.99 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetDevPack.SimpleMediator.Core", "NetDevPack.SimpleMediator.Core\NetDevPack.SimpleMediator.Core.csproj", "{CAB8015B-E7BB-1917-5123-90802AFA0891}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {CAB8015B-E7BB-1917-5123-90802AFA0891}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {CAB8015B-E7BB-1917-5123-90802AFA0891}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {CAB8015B-E7BB-1917-5123-90802AFA0891}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {CAB8015B-E7BB-1917-5123-90802AFA0891}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {A8F0F30E-9298-40B8-8155-49CCE220AAE1} 24 | EndGlobalSection 25 | EndGlobal 26 | --------------------------------------------------------------------------------