diff --git a/.editorconfig b/.editorconfig index 82d0bab..7682014 100644 --- a/.editorconfig +++ b/.editorconfig @@ -45,7 +45,7 @@ insert_final_newline = true [*.cs] #### File Header Template #### -file_header_template = This Source Code Form is subject to the terms of the MIT License.\nIf a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.\nCopyright (C) Leszek Pomianowski and ReflectionEventing Contributors.\nAll Rights Reserved. +file_header_template = This Source Code Form is subject to the terms of the MIT License.\nIf a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.\nCopyright (C) Leszek Pomianowski and CommandQuerySegregation Contributors.\nAll Rights Reserved. #### .NET Coding Conventions #### diff --git a/.github/labeler.yml b/.github/labeler.yml index d7a3c8f..4921ffe 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -22,7 +22,7 @@ update: NuGet: - changed-files: - - any-glob-to-any-file: [ 'src/ReflectionEventing/**', 'src/Directory.Packages.props' ] + - any-glob-to-any-file: [ 'src/CommandQuerySegregation/**', 'src/Directory.Packages.props' ] dependencies: - changed-files: diff --git a/.github/workflows/reflection-events-cd-nuget.yaml b/.github/workflows/cqs-cd-nuget.yaml similarity index 73% rename from .github/workflows/reflection-events-cd-nuget.yaml rename to .github/workflows/cqs-cd-nuget.yaml index f677aba..63e07a3 100644 --- a/.github/workflows/reflection-events-cd-nuget.yaml +++ b/.github/workflows/cqs-cd-nuget.yaml @@ -1,4 +1,4 @@ -name: reflection-events-client-cd-nuget +name: cqs-cd-nuget on: push: @@ -26,10 +26,10 @@ jobs: run: dotnet restore - name: Build - run: dotnet build ReflectionEventing.sln --configuration Release --no-restore -p:SourceLinkEnabled=true + run: dotnet build CommandQuerySegregation.sln --configuration Release --no-restore -p:SourceLinkEnabled=true - name: Run tests - run: dotnet test ReflectionEventing.sln --configuration Release --no-restore --no-build --verbosity quiet + run: dotnet test CommandQuerySegregation.sln --configuration Release --no-restore --no-build --verbosity quiet - name: Publish the package to NuGet.org run: nuget push **\*.nupkg -NonInteractive -SkipDuplicate -Source 'https://api.nuget.org/v3/index.json' diff --git a/.github/workflows/reflection-events-labeler.yaml b/.github/workflows/cqs-labeler.yaml similarity index 88% rename from .github/workflows/reflection-events-labeler.yaml rename to .github/workflows/cqs-labeler.yaml index a5d7d98..d8030e1 100644 --- a/.github/workflows/reflection-events-labeler.yaml +++ b/.github/workflows/cqs-labeler.yaml @@ -1,4 +1,4 @@ -name: reflection-events-labeler +name: cqs-labeler on: - pull_request_target diff --git a/.github/workflows/reflection-events-pr-validator.yaml b/.github/workflows/cqs-pr-validator.yaml similarity index 72% rename from .github/workflows/reflection-events-pr-validator.yaml rename to .github/workflows/cqs-pr-validator.yaml index ed42d7a..c5adcef 100644 --- a/.github/workflows/reflection-events-pr-validator.yaml +++ b/.github/workflows/cqs-pr-validator.yaml @@ -1,4 +1,4 @@ -name: reflection-events-pr-validator +name: cqs-pr-validator on: pull_request: @@ -29,7 +29,7 @@ jobs: run: dotnet restore - name: Build - run: dotnet build ReflectionEventing.sln --configuration Release --no-restore + run: dotnet build CommandQuerySegregation.sln --configuration Release --no-restore - name: Run tests - run: dotnet test ReflectionEventing.sln --configuration Release --no-restore --no-build --verbosity quiet + run: dotnet test CommandQuerySegregation.sln --configuration Release --no-restore --no-build --verbosity quiet diff --git a/CommandQuerySegregation.sln b/CommandQuerySegregation.sln new file mode 100644 index 0000000..279ea29 --- /dev/null +++ b/CommandQuerySegregation.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommandQuerySegregation", "src\CommandQuerySegregation\CommandQuerySegregation.csproj", "{F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3D12BBC8-E962-4230-AA5F-C97BDCB7AB24}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets + Directory.Packages.props = Directory.Packages.props + nuget.config = nuget.config + README.md = README.md + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{7A58AE12-65AA-4E1B-B5DB-CBD2732D1AE7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B017BA78-67A5-4D0F-92A3-671B0D8A2911} + EndGlobalSection +EndGlobal diff --git a/Contributing.md b/Contributing.md index c29f6d7..8d2ce14 100644 --- a/Contributing.md +++ b/Contributing.md @@ -1,36 +1,36 @@ -# ✨ Contributing to the ReflectionEventing +# ✨ Contributing to the CommandQuerySegregation -Thank you for exhibiting interest in contributing to the ReflectionEventing. The team is delighted to welcome you onboard to our exciting and growing project. Any contribution or value added go a long way to enhance the project! +Thank you for exhibiting interest in contributing to the CommandQuerySegregation. The team is delighted to welcome you onboard to our exciting and growing project. Any contribution or value added go a long way to enhance the project! -In the next few steps, you will be able to see a glimpse of ways you can contribute to the ReflectionEventing. +In the next few steps, you will be able to see a glimpse of ways you can contribute to the CommandQuerySegregation. ## ❔ Questions -Due to the high volume of incoming issues please keep our GitHub issues for bug reports and feature requests. For general questions, there is a higher chance of getting your question answered on [StackOverflow](https://stackoverflow.com/questions/tagged/lepo-reflection-eventing) where questions should be tagged with the tag `lepo-reflection-eventing`. +Due to the high volume of incoming issues please keep our GitHub issues for bug reports and feature requests. For general questions, there is a higher chance of getting your question answered on [StackOverflow](https://stackoverflow.com/questions/tagged/lepo-cqs) where questions should be tagged with the tag `lepo-cqs`. ## 🐛 Fix a Bug -If you find any bug, you can help the community by [submitting an issue](https://github.com/lepoco/reflectioneventing/issues/new?labels=bug+:bug:&title=[Bug]). Once the issue is filed, feel free to start working on the PR and submit a PR. +If you find any bug, you can help the community by [submitting an issue](https://github.com/lepoco/cqs/issues/new?labels=bug+:bug:&title=[Bug]). Once the issue is filed, feel free to start working on the PR and submit a PR. ## 👌 Good First Issue -If this is your first time contributing to the ReflectionEventing (_WCT_) and do not have advanced level programming experience, we have got you covered 💥 WCT has a list of [good first issue](https://github.com/lepoco/reflectioneventing/labels/good%20first%20issue) that can be a great entryway to find and fix any issues that best fit your expertise or technical background. +If this is your first time contributing to the CommandQuerySegregation (_WCT_) and do not have advanced level programming experience, we have got you covered 💥 WCT has a list of [good first issue](https://github.com/lepoco/cqs/labels/good%20first%20issue) that can be a great entryway to find and fix any issues that best fit your expertise or technical background. ## 🙋 Help Wanted -WCT also has a list of issues that are labeled as [help wanted](https://github.com/lepoco/reflectioneventing/labels/help%20wanted). The level of complexity in the list can vary but if you have an advanced level of programming experience, feel free to jump in to solve these issues. +WCT also has a list of issues that are labeled as [help wanted](https://github.com/lepoco/cqs/labels/help%20wanted). The level of complexity in the list can vary but if you have an advanced level of programming experience, feel free to jump in to solve these issues. ## 📬 Add New Feature -* To contribute a new feature, fill out the [Feature Request Template](https://github.com/lepoco/reflectioneventing/issues/new?template=feature_request.md&labels=feature+request+:mailbox_with_mail:&title=[Feature]) and provide detailed information to express the proposal. +* To contribute a new feature, fill out the [Feature Request Template](https://github.com/lepoco/cqs/issues/new?template=feature_request.md&labels=feature+request+:mailbox_with_mail:&title=[Feature]) and provide detailed information to express the proposal. * Once the Feature Request is submitted, it will be open for discussion. * If it gets approved by the team, proceed to submit a PR of the proposed Feature. * If the PR contains an error-free code and the reviewer signs off, the PR will be merged. ## 🚀 Create, Submit or Review Pull Request -Anyone can create a Pull Request by forking the ReflectionEventing Repository. Here is how you can [Create a Pull Request from fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork). Once you fork the ReflectionEventing repo, it is essential to create all changes in the feature branch of your forked repository. If you have the changes in the forked feature branch, you can then create a Pull Request in the main ReflectionEventing. +Anyone can create a Pull Request by forking the CommandQuerySegregation Repository. Here is how you can [Create a Pull Request from fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork). Once you fork the CommandQuerySegregation repo, it is essential to create all changes in the feature branch of your forked repository. If you have the changes in the forked feature branch, you can then create a Pull Request in the main CommandQuerySegregation. ## 💙 Thank You -**Thank you so much for contributing to this amazing project. We hope you will continue to add value and find yourself as a highly reliable source to the ReflectionEventing.** +**Thank you so much for contributing to this amazing project. We hope you will continue to add value and find yourself as a highly reliable source to the CommandQuerySegregation.** diff --git a/Directory.Build.props b/Directory.Build.props index 22b9c07..fb7da87 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,21 +6,22 @@ - 3.0.1 + 1.0.0 + 1.0.0-preview.1 lepo.co lepo.co - ReflectionEventing - lepoco;events;eventing;reflection;client;toolkit;extensions;bus;eventbus;messages + CommandQuerySegregation + lepoco;commands;queries;bus;messages MIT true (c) lepo.co | Leszek Pomianowski and Contributors. All rights reserved. - https://github.com/lepoco/reflectioneventing - https://github.com/lepoco/reflectioneventing/releases + https://github.com/lepoco/cqs + https://github.com/lepoco/cqs/releases Icon.png - https://github.com/lepoco/reflectioneventing/main/build/nuget.png + https://github.com/lepoco/cqs/main/build/nuget.png diff --git a/LICENSE b/LICENSE index a5c757f..f979f83 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Leszek Pomianowski and ReflectionEventing Contributors. https://dev.lepo.co/ +Copyright (c) 2024 Leszek Pomianowski and CommandQuerySegregation Contributors. https://dev.lepo.co/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/LICENSE.md b/LICENSE.md index a5c757f..f979f83 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Leszek Pomianowski and ReflectionEventing Contributors. https://dev.lepo.co/ +Copyright (c) 2024 Leszek Pomianowski and CommandQuerySegregation Contributors. https://dev.lepo.co/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8c7a208..1fd4816 100644 --- a/README.md +++ b/README.md @@ -1,95 +1,40 @@ -# 🚎 ReflectionEventing +# 🚎 CommandQuerySegregation [Created with ❤ in Poland by lepo.co](https://dev.lepo.co/) -ReflectionEventing is a powerful tool for developers looking to create decoupled designs in WPF, WinForms, or CLI applications. By leveraging the power of Dependency Injection (DI) and eventing, ReflectionEventing promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications. +Elevate your application's command and query responsibilities. CommandQuerySegregation provides intuitive interfaces and classes for implementing Command Query Responsibility Segregation (CQRS) in .NET applications. It facilitates clear separation of command and query operations, promoting clean architecture and enhanced maintainability. -[![GitHub license](https://img.shields.io/github/license/lepoco/reflectioneventing)](https://github.com/lepoco/reflectioneventing/blob/master/LICENSE) [![Nuget](https://img.shields.io/nuget/v/ReflectionEventing)](https://www.nuget.org/packages/ReflectionEventing/) [![Nuget](https://img.shields.io/nuget/dt/ReflectionEventing?label=nuget)](https://www.nuget.org/packages/ReflectionEventing/) [![Sponsors](https://img.shields.io/github/sponsors/lepoco)](https://github.com/sponsors/lepoco) +[![GitHub license](https://img.shields.io/github/license/lepoco/cqs)](https://github.com/lepoco/cqs/blob/master/LICENSE) [![Nuget](https://img.shields.io/nuget/v/CommandQuerySegregation)](https://www.nuget.org/packages/CommandQuerySegregation/) [![Nuget](https://img.shields.io/nuget/dt/CommandQuerySegregation?label=nuget)](https://www.nuget.org/packages/CommandQuerySegregation/) [![Sponsors](https://img.shields.io/github/sponsors/lepoco)](https://github.com/sponsors/lepoco) ## 👀 What does this repo contain? -This repository houses the source code for the ReflectionEventing NuGet package. The package utilizes C# reflection to register services that can listen for and respond to local events. +This repository houses the source code for the CommandQuerySegregation NuGet package. ## Gettings started -ReflectionEventing is available as NuGet package on NuGet.org: -https://www.nuget.org/packages/ReflectionEventing -https://www.nuget.org/packages/ReflectionEventing.Autofac -https://www.nuget.org/packages/ReflectionEventing.Castle.Windsor -https://www.nuget.org/packages/ReflectionEventing.DependencyInjection -https://www.nuget.org/packages/ReflectionEventing.Ninject -https://www.nuget.org/packages/ReflectionEventing.Unity +CommandQuerySegregation is available as NuGet package on NuGet.org: +https://www.nuget.org/packages/CommandQuerySegregation You can add it to your project using .NET CLI: ```powershell -dotnet add package ReflectionEventing.DependencyInjection +dotnet add package CommandQuerySegregation ``` , or package manager console: ```powershell -NuGet\Install-Package ReflectionEventing.DependencyInjection +NuGet\Install-Package CommandQuerySegregation ``` -### 🛠️ How to Use ReflectionEventing - -#### 1. Register Consumers and the Event Bus - -In this step, we register our ViewModel as a singleton and add it as a consumer to the event bus. This allows the ViewModel to listen for events published on the bus. - -```csharp -IHost host = Host.CreateDefaultBuilder() - .ConfigureServices((context, services) => - { - services.AddSingleton(); - services.AddEventBus(e => - { - e.AddConsumer(); - }); - } - ) - .Build(); -``` - -#### 2. Publish Events - -Here, we create a background service that publishes an event on the event bus. This event could be anything - in this case, we're publishing a `BackgroundTicked` event. - -```csharp -public class MyBackgroundService(IEventBus eventBus) -{ - public void PublishEvent() - { - eventBus.Publish(new BackgroundTicked()); - } -} -``` - -#### 3. Listen for Events - -Finally, we implement the `IConsumer` interface in our ViewModel. This allows the ViewModel to consume `BackgroundTicked` events. When a `BackgroundTicked` event is published, the `ConsumeAsync` method is called, and we update the `CurrentTick` property. - -```csharp -public partial class MainWindowViewModel : ObservableObject, IConsumer -{ - [ObservableProperty] - private int _currentTick = 0; - - public Task ConsumeAsync(BackgroundTicked payload, CancellationToken cancellationToken) - { - CurrentTick = payload.Value; - - return Task.CompletedTask; - } -} -``` +### 🛠️ How to Use CommandQuerySegregation +tba ## Compilation To build the project, use Visual Studio 2022 and open the .sln file. Visual Studio -**ReflectionEventing** is an Open Source project. You are entitled to download and use the freely available Visual Studio Community Edition to build, run or develop for ReflectionEventing. As per the Visual Studio Community Edition license, this applies regardless of whether you are an individual or a corporate user. +**CommandQuerySegregation** is an Open Source project. You are entitled to download and use the freely available Visual Studio Community Edition to build, run or develop for CommandQuerySegregation. As per the Visual Studio Community Edition license, this applies regardless of whether you are an individual or a corporate user. ## Code of Conduct @@ -97,5 +42,5 @@ This project has adopted the code of conduct defined by the Contributor Covenant ## License -**ReflectionEventing** is free and open source software licensed under **MIT License**. You can use it in private and commercial projects. +**CommandQuerySegregation** is free and open source software licensed under **MIT License**. You can use it in private and commercial projects. Keep in mind that you must include a copy of the license in your project. diff --git a/ReflectionEventing.sln b/ReflectionEventing.sln deleted file mode 100644 index fa371f8..0000000 --- a/ReflectionEventing.sln +++ /dev/null @@ -1,117 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.9.34728.123 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing", "src\ReflectionEventing\ReflectionEventing.csproj", "{F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.Demo.Wpf", "src\ReflectionEventing.Demo.Wpf\ReflectionEventing.Demo.Wpf.csproj", "{898865CB-C39C-4E69-9FF8-E96AAD7FF0A4}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3D12BBC8-E962-4230-AA5F-C97BDCB7AB24}" - ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig - Directory.Build.props = Directory.Build.props - Directory.Build.targets = Directory.Build.targets - Directory.Packages.props = Directory.Packages.props - nuget.config = nuget.config - README.md = README.md - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.Autofac", "src\ReflectionEventing.Autofac\ReflectionEventing.Autofac.csproj", "{6023E50F-2B4D-4315-B85D-9E8A12746045}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.DependencyInjection", "src\ReflectionEventing.DependencyInjection\ReflectionEventing.DependencyInjection.csproj", "{09F0D6A2-3791-4173-A612-98E6EA92FCC4}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{7A58AE12-65AA-4E1B-B5DB-CBD2732D1AE7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.UnitTests", "tests\ReflectionEventing.UnitTests\ReflectionEventing.UnitTests.csproj", "{7F506A5A-1F70-49CB-B371-428DFA573451}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.Autofac.UnitTests", "tests\ReflectionEventing.Autofac.UnitTests\ReflectionEventing.Autofac.UnitTests.csproj", "{E5C7D945-F96C-4C05-9C12-4DB246E207CB}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.DependencyInjection.UnitTests", "tests\ReflectionEventing.DependencyInjection.UnitTests\ReflectionEventing.DependencyInjection.UnitTests.csproj", "{CF2E3E06-48A3-47F7-B152-E86F25C9A182}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.Ninject", "src\ReflectionEventing.Ninject\ReflectionEventing.Ninject.csproj", "{194CA822-C3D6-4FBC-989A-039A0B97F2A8}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.Ninject.UnitTests", "tests\ReflectionEventing.Ninject.UnitTests\ReflectionEventing.Ninject.UnitTests.csproj", "{A741FC02-03AE-4A34-AAA0-FBFBAB93377D}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.Unity", "src\ReflectionEventing.Unity\ReflectionEventing.Unity.csproj", "{EBE050AC-CE99-49E0-9836-361D9F0DB515}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReflectionEventing.Unity.UnitTests", "tests\ReflectionEventing.Unity.UnitTests\ReflectionEventing.Unity.UnitTests.csproj", "{772AA314-8522-4A95-A99B-E69A867704DC}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReflectionEventing.Castle.Windsor", "src\ReflectionEventing.Castle.Windsor\ReflectionEventing.Castle.Windsor.csproj", "{DEBBE7D1-7F8A-4013-9BA7-C721AB8A1E1B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReflectionEventing.Castle.Windsor.UnitTests", "tests\ReflectionEventing.Castle.Windsor.UnitTests\ReflectionEventing.Castle.Windsor.UnitTests.csproj", "{8D24CF24-984D-4500-B99E-711DFBF64A92}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F5FF47B8-A0CC-4F20-A848-AEEF51D4C2C7}.Release|Any CPU.Build.0 = Release|Any CPU - {898865CB-C39C-4E69-9FF8-E96AAD7FF0A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {898865CB-C39C-4E69-9FF8-E96AAD7FF0A4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {898865CB-C39C-4E69-9FF8-E96AAD7FF0A4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {898865CB-C39C-4E69-9FF8-E96AAD7FF0A4}.Release|Any CPU.Build.0 = Release|Any CPU - {6023E50F-2B4D-4315-B85D-9E8A12746045}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6023E50F-2B4D-4315-B85D-9E8A12746045}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6023E50F-2B4D-4315-B85D-9E8A12746045}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6023E50F-2B4D-4315-B85D-9E8A12746045}.Release|Any CPU.Build.0 = Release|Any CPU - {09F0D6A2-3791-4173-A612-98E6EA92FCC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {09F0D6A2-3791-4173-A612-98E6EA92FCC4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {09F0D6A2-3791-4173-A612-98E6EA92FCC4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {09F0D6A2-3791-4173-A612-98E6EA92FCC4}.Release|Any CPU.Build.0 = Release|Any CPU - {7F506A5A-1F70-49CB-B371-428DFA573451}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7F506A5A-1F70-49CB-B371-428DFA573451}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7F506A5A-1F70-49CB-B371-428DFA573451}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7F506A5A-1F70-49CB-B371-428DFA573451}.Release|Any CPU.Build.0 = Release|Any CPU - {E5C7D945-F96C-4C05-9C12-4DB246E207CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E5C7D945-F96C-4C05-9C12-4DB246E207CB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E5C7D945-F96C-4C05-9C12-4DB246E207CB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E5C7D945-F96C-4C05-9C12-4DB246E207CB}.Release|Any CPU.Build.0 = Release|Any CPU - {CF2E3E06-48A3-47F7-B152-E86F25C9A182}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CF2E3E06-48A3-47F7-B152-E86F25C9A182}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CF2E3E06-48A3-47F7-B152-E86F25C9A182}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CF2E3E06-48A3-47F7-B152-E86F25C9A182}.Release|Any CPU.Build.0 = Release|Any CPU - {194CA822-C3D6-4FBC-989A-039A0B97F2A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {194CA822-C3D6-4FBC-989A-039A0B97F2A8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {194CA822-C3D6-4FBC-989A-039A0B97F2A8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {194CA822-C3D6-4FBC-989A-039A0B97F2A8}.Release|Any CPU.Build.0 = Release|Any CPU - {A741FC02-03AE-4A34-AAA0-FBFBAB93377D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A741FC02-03AE-4A34-AAA0-FBFBAB93377D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A741FC02-03AE-4A34-AAA0-FBFBAB93377D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A741FC02-03AE-4A34-AAA0-FBFBAB93377D}.Release|Any CPU.Build.0 = Release|Any CPU - {EBE050AC-CE99-49E0-9836-361D9F0DB515}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EBE050AC-CE99-49E0-9836-361D9F0DB515}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EBE050AC-CE99-49E0-9836-361D9F0DB515}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EBE050AC-CE99-49E0-9836-361D9F0DB515}.Release|Any CPU.Build.0 = Release|Any CPU - {772AA314-8522-4A95-A99B-E69A867704DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {772AA314-8522-4A95-A99B-E69A867704DC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {772AA314-8522-4A95-A99B-E69A867704DC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {772AA314-8522-4A95-A99B-E69A867704DC}.Release|Any CPU.Build.0 = Release|Any CPU - {DEBBE7D1-7F8A-4013-9BA7-C721AB8A1E1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DEBBE7D1-7F8A-4013-9BA7-C721AB8A1E1B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DEBBE7D1-7F8A-4013-9BA7-C721AB8A1E1B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DEBBE7D1-7F8A-4013-9BA7-C721AB8A1E1B}.Release|Any CPU.Build.0 = Release|Any CPU - {8D24CF24-984D-4500-B99E-711DFBF64A92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8D24CF24-984D-4500-B99E-711DFBF64A92}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8D24CF24-984D-4500-B99E-711DFBF64A92}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8D24CF24-984D-4500-B99E-711DFBF64A92}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {7F506A5A-1F70-49CB-B371-428DFA573451} = {7A58AE12-65AA-4E1B-B5DB-CBD2732D1AE7} - {E5C7D945-F96C-4C05-9C12-4DB246E207CB} = {7A58AE12-65AA-4E1B-B5DB-CBD2732D1AE7} - {CF2E3E06-48A3-47F7-B152-E86F25C9A182} = {7A58AE12-65AA-4E1B-B5DB-CBD2732D1AE7} - {A741FC02-03AE-4A34-AAA0-FBFBAB93377D} = {7A58AE12-65AA-4E1B-B5DB-CBD2732D1AE7} - {772AA314-8522-4A95-A99B-E69A867704DC} = {7A58AE12-65AA-4E1B-B5DB-CBD2732D1AE7} - {8D24CF24-984D-4500-B99E-711DFBF64A92} = {7A58AE12-65AA-4E1B-B5DB-CBD2732D1AE7} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B017BA78-67A5-4D0F-92A3-671B0D8A2911} - EndGlobalSection -EndGlobal diff --git a/ThirdPartyNotices.txt b/ThirdPartyNotices.txt index 3164748..5127949 100644 --- a/ThirdPartyNotices.txt +++ b/ThirdPartyNotices.txt @@ -1,4 +1,4 @@ -ReflectionEventing +CommandQuerySegregation THIRD-PARTY SOFTWARE NOTICES AND INFORMATION Do Not Translate or Localize diff --git a/build/nuget.png b/build/nuget.png index 7c66e73..111f86d 100644 Binary files a/build/nuget.png and b/build/nuget.png differ diff --git a/src/ReflectionEventing/ReflectionEventing.csproj b/src/CommandQuerySegregation/CommandQuerySegregation.csproj similarity index 76% rename from src/ReflectionEventing/ReflectionEventing.csproj rename to src/CommandQuerySegregation/CommandQuerySegregation.csproj index 3a3b1be..ba981a3 100644 --- a/src/ReflectionEventing/ReflectionEventing.csproj +++ b/src/CommandQuerySegregation/CommandQuerySegregation.csproj @@ -1,12 +1,13 @@ - ReflectionEventing + CommandQuerySegregation netstandard2.0;netstandard2.1;net462;net6.0;net8.0 true true true - By leveraging the power of Dependency Injection (DI) and eventing, ReflectionEventing promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications. + About + Elevate your application's command and query responsibilities. CommandQuerySegregation provides intuitive interfaces and classes for implementing Command Query Responsibility Segregation (CQRS) in .NET applications. It facilitates clear separation of command and query operations, promoting clean architecture and enhanced maintainability. diff --git a/src/CommandQuerySegregation/ICommandBus.cs b/src/CommandQuerySegregation/ICommandBus.cs new file mode 100644 index 0000000..30b7d17 --- /dev/null +++ b/src/CommandQuerySegregation/ICommandBus.cs @@ -0,0 +1,29 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and CommandQuerySegregation Contributors. +// All Rights Reserved. + +using System.Threading; +using System.Threading.Tasks; + +namespace CommandQuerySegregation; + +/// +/// Defines a contract for a command bus in a Command Query Responsibility Segregation (CQRS) pattern. +/// +/// +/// A command bus is responsible for dispatching commands to their appropriate handlers. +/// +public interface ICommandBus +{ + /// + /// Executes the given command asynchronously. + /// + /// The type of the command to execute. + /// The type of the result that the command returns. + /// The command to execute. + /// A cancellation token that can be used to cancel the work. + /// A task that represents the asynchronous operation. + Task ExecuteAsync(TCommand command, CancellationToken cancellationToken) + where TCommand : class; +} diff --git a/src/CommandQuerySegregation/IQueryBus.cs b/src/CommandQuerySegregation/IQueryBus.cs new file mode 100644 index 0000000..05c447a --- /dev/null +++ b/src/CommandQuerySegregation/IQueryBus.cs @@ -0,0 +1,29 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and CommandQuerySegregation Contributors. +// All Rights Reserved. + +using System.Threading; +using System.Threading.Tasks; + +namespace CommandQuerySegregation; + +/// +/// Defines a contract for a query bus in a Command Query Responsibility Segregation (CQRS) pattern. +/// +/// +/// A query bus is responsible for dispatching queries to their appropriate handlers. +/// +public interface IQueryBus +{ + /// + /// Executes the given query asynchronously. + /// + /// The type of the query to execute. + /// The type of the result that the query returns. + /// The query to execute. + /// A cancellation token that can be used to cancel the work. + /// A task that represents the asynchronous operation. + Task ExecuteAsync(TQuery query, CancellationToken cancellationToken) + where TQuery : class; +} diff --git a/src/ReflectionEventing.Autofac/AutofacConsumerProvider.cs b/src/ReflectionEventing.Autofac/AutofacConsumerProvider.cs deleted file mode 100644 index c416972..0000000 --- a/src/ReflectionEventing.Autofac/AutofacConsumerProvider.cs +++ /dev/null @@ -1,25 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Autofac; - -namespace ReflectionEventing.Autofac; - -/// -/// Provides event consumers for Autofac. -/// -public class AutofacConsumerProvider(ILifetimeScope lifetimeScope) : IConsumerProvider -{ - /// - public IEnumerable GetConsumers(Type consumerType) - { - if (consumerType is null) - { - throw new ArgumentNullException(nameof(consumerType)); - } - - return new List { lifetimeScope.Resolve(consumerType) }; - } -} diff --git a/src/ReflectionEventing.Autofac/AutofacEventBusBuilder.cs b/src/ReflectionEventing.Autofac/AutofacEventBusBuilder.cs deleted file mode 100644 index b50ccc2..0000000 --- a/src/ReflectionEventing.Autofac/AutofacEventBusBuilder.cs +++ /dev/null @@ -1,13 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Autofac; - -namespace ReflectionEventing.Autofac; - -/// -/// Represents a builder for configuring the event bus with Autofac. -/// -public class AutofacEventBusBuilder(ContainerBuilder builder) : EventBusBuilder; diff --git a/src/ReflectionEventing.Autofac/ContainerBuilderExtensions.cs b/src/ReflectionEventing.Autofac/ContainerBuilderExtensions.cs deleted file mode 100644 index 8867a5c..0000000 --- a/src/ReflectionEventing.Autofac/ContainerBuilderExtensions.cs +++ /dev/null @@ -1,48 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Autofac; - -namespace ReflectionEventing.Autofac; - -/// -/// Provides extension methods for the class. -/// -public static class ContainerBuilderExtensions -{ - /// - /// Adds the event bus and its related services to the specified Autofac container builder. - /// - /// The to add the event bus to. - /// A delegate that configures the . - /// The same container builder so that multiple calls can be chained. - /// - /// This method adds a singleton service of type that uses a with the consumers from the event bus builder. - /// It also adds a scoped service of type that uses the class. - /// - public static ContainerBuilder AddEventBus( - this ContainerBuilder builder, - Action configure - ) - { - AutofacEventBusBuilder autofacBuilder = new(builder); - - configure(autofacBuilder); - - _ = builder - .RegisterInstance(autofacBuilder.BuildTypesProvider()) - .As() - .SingleInstance(); - - _ = builder - .RegisterType() - .As() - .InstancePerLifetimeScope(); - - _ = builder.RegisterType().As().InstancePerLifetimeScope(); - - return builder; - } -} diff --git a/src/ReflectionEventing.Autofac/GlobalUsings.cs b/src/ReflectionEventing.Autofac/GlobalUsings.cs deleted file mode 100644 index 0012f8a..0000000 --- a/src/ReflectionEventing.Autofac/GlobalUsings.cs +++ /dev/null @@ -1,7 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; diff --git a/src/ReflectionEventing.Autofac/ReflectionEventing.Autofac.csproj b/src/ReflectionEventing.Autofac/ReflectionEventing.Autofac.csproj deleted file mode 100644 index 111e9f8..0000000 --- a/src/ReflectionEventing.Autofac/ReflectionEventing.Autofac.csproj +++ /dev/null @@ -1,44 +0,0 @@ - - - - ReflectionEventing.Autofac - netstandard2.0;netstandard2.1;net462;net6.0;net8.0 - true - true - true - $(CommonTags);autofac;module - Autofac Container module with ReflectionEventing, which promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications. - - - - true - true - Speed - - - - - - System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute; - System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute; - System.Diagnostics.CodeAnalysis.MemberNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; - System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute; - System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute; - System.Runtime.CompilerServices.CallerArgumentExpressionAttribute; - System.Runtime.CompilerServices.IsExternalInit; - System.Runtime.CompilerServices.SkipLocalsInitAttribute; - - - - - - - - - - - - diff --git a/src/ReflectionEventing.Castle.Windsor/EventBusInstaller.cs b/src/ReflectionEventing.Castle.Windsor/EventBusInstaller.cs deleted file mode 100644 index e42c97b..0000000 --- a/src/ReflectionEventing.Castle.Windsor/EventBusInstaller.cs +++ /dev/null @@ -1,45 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Castle.MicroKernel.Registration; -using Castle.MicroKernel.SubSystems.Configuration; -using Castle.Windsor; - -namespace ReflectionEventing.Castle.Windsor; - -/// -/// Represents a Castle Windsor installer for configuring the event bus and its related services. -/// -public class EventBusInstaller(Action configure) : IWindsorInstaller -{ - /// - /// Adds the event bus and its related services to the specified Windsor container. - /// - /// The to add the event bus to. - /// The for the container. - public void Install(IWindsorContainer container, IConfigurationStore store) - { - WindsorEventBusBuilder builder = new(container); - - if (!container.Kernel.HasComponent(typeof(IWindsorContainer))) - { - _ = container.Register(Component.For().Instance(container)); - } - - configure(builder); - - _ = container.Register( - Component - .For() - .Instance(builder.BuildTypesProvider()) - .LifestyleScoped(), - Component - .For() - .ImplementedBy() - .LifestyleScoped(), - Component.For().ImplementedBy().LifestyleTransient() - ); - } -} diff --git a/src/ReflectionEventing.Castle.Windsor/GlobalUsings.cs b/src/ReflectionEventing.Castle.Windsor/GlobalUsings.cs deleted file mode 100644 index 0012f8a..0000000 --- a/src/ReflectionEventing.Castle.Windsor/GlobalUsings.cs +++ /dev/null @@ -1,7 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; diff --git a/src/ReflectionEventing.Castle.Windsor/ReflectionEventing.Castle.Windsor.csproj b/src/ReflectionEventing.Castle.Windsor/ReflectionEventing.Castle.Windsor.csproj deleted file mode 100644 index 8b71ecd..0000000 --- a/src/ReflectionEventing.Castle.Windsor/ReflectionEventing.Castle.Windsor.csproj +++ /dev/null @@ -1,44 +0,0 @@ - - - - ReflectionEventing.Castle.Windsor - netstandard2.0;netstandard2.1;net462;net6.0;net8.0 - true - true - true - $(CommonTags);castle;windsor;installer - Castle Windsor installer with ReflectionEventing, which promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications. - - - - true - true - Speed - - - - - - System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute; - System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute; - System.Diagnostics.CodeAnalysis.MemberNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; - System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute; - System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute; - System.Runtime.CompilerServices.CallerArgumentExpressionAttribute; - System.Runtime.CompilerServices.IsExternalInit; - System.Runtime.CompilerServices.SkipLocalsInitAttribute; - - - - - - - - - - - - diff --git a/src/ReflectionEventing.Castle.Windsor/WindsorConsumerProvider.cs b/src/ReflectionEventing.Castle.Windsor/WindsorConsumerProvider.cs deleted file mode 100644 index b8b3ed7..0000000 --- a/src/ReflectionEventing.Castle.Windsor/WindsorConsumerProvider.cs +++ /dev/null @@ -1,25 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Castle.Windsor; - -namespace ReflectionEventing.Castle.Windsor; - -/// -/// Represents a provider for retrieving event consumers from Castle Windsor's IoC container. -/// -public class WindsorConsumerProvider(IWindsorContainer container) : IConsumerProvider -{ - /// - public IEnumerable GetConsumers(Type consumerType) - { - if (consumerType is null) - { - throw new ArgumentNullException(nameof(consumerType)); - } - - return container.ResolveAll(consumerType) as object[] ?? []; - } -} diff --git a/src/ReflectionEventing.Castle.Windsor/WindsorEventBusBuilder.cs b/src/ReflectionEventing.Castle.Windsor/WindsorEventBusBuilder.cs deleted file mode 100644 index 8f8a23f..0000000 --- a/src/ReflectionEventing.Castle.Windsor/WindsorEventBusBuilder.cs +++ /dev/null @@ -1,33 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using System.Diagnostics.CodeAnalysis; -using Castle.Windsor; - -namespace ReflectionEventing.Castle.Windsor; - -/// -/// Represents a builder for configuring the event bus with Castle Windsor's IoC container. -/// -public class WindsorEventBusBuilder(IWindsorContainer container) : EventBusBuilder -{ - /// - public override EventBusBuilder AddConsumer( -#if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] -#endif - Type consumerType - ) - { - if (!container.Kernel.HasComponent(consumerType)) - { - throw new InvalidOperationException( - "Event consumer must be registered in the container." - ); - } - - return base.AddConsumer(consumerType); - } -} diff --git a/src/ReflectionEventing.Demo.Wpf/App.xaml b/src/ReflectionEventing.Demo.Wpf/App.xaml deleted file mode 100644 index 2ddc5e4..0000000 --- a/src/ReflectionEventing.Demo.Wpf/App.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/src/ReflectionEventing.Demo.Wpf/App.xaml.cs b/src/ReflectionEventing.Demo.Wpf/App.xaml.cs deleted file mode 100644 index d097e22..0000000 --- a/src/ReflectionEventing.Demo.Wpf/App.xaml.cs +++ /dev/null @@ -1,60 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using ReflectionEventing.Demo.Wpf.Services; -using ReflectionEventing.Demo.Wpf.ViewModels; -using ReflectionEventing.DependencyInjection; - -namespace ReflectionEventing.Demo.Wpf; - -/// -/// Interaction logic for App.xaml -/// -public partial class App : Application -{ - private static readonly IHost Host = Microsoft - .Extensions.Hosting.Host.CreateDefaultBuilder() - .ConfigureAppConfiguration(c => - { - _ = c.SetBasePath(Directory.GetCurrentDirectory()); - _ = c.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); - }) - .ConfigureServices( - (context, services) => - { - _ = services.AddHostedService(); - _ = services.AddHostedService(); - - _ = services.AddSingleton(); - _ = services.AddSingleton(); - - _ = services.AddEventBus(e => - { - e.Options.UseEventPolymorphism = true; - - _ = e.AddAllConsumers(Assembly.GetExecutingAssembly()); - }); - } - ) - .Build(); - - /// - /// Occurs when the application is loading. - /// - private async void OnStartup(object sender, StartupEventArgs e) - { - await Host.StartAsync(); - } - - /// - /// Occurs when the application is closing. - /// - private async void OnExit(object sender, ExitEventArgs e) - { - await Host.StopAsync(); - - Host.Dispose(); - } -} diff --git a/src/ReflectionEventing.Demo.Wpf/AssemblyInfo.cs b/src/ReflectionEventing.Demo.Wpf/AssemblyInfo.cs deleted file mode 100644 index 8eae719..0000000 --- a/src/ReflectionEventing.Demo.Wpf/AssemblyInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] diff --git a/src/ReflectionEventing.Demo.Wpf/Events/BackgroundTicked.cs b/src/ReflectionEventing.Demo.Wpf/Events/BackgroundTicked.cs deleted file mode 100644 index 826322f..0000000 --- a/src/ReflectionEventing.Demo.Wpf/Events/BackgroundTicked.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing.Demo.Wpf.Events; - -public sealed record BackgroundTicked(int Value) : ITickedEvent; diff --git a/src/ReflectionEventing.Demo.Wpf/Events/ITickedEvent.cs b/src/ReflectionEventing.Demo.Wpf/Events/ITickedEvent.cs deleted file mode 100644 index ca2b463..0000000 --- a/src/ReflectionEventing.Demo.Wpf/Events/ITickedEvent.cs +++ /dev/null @@ -1,11 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing.Demo.Wpf.Events; - -public interface ITickedEvent -{ - int Value { get; } -} diff --git a/src/ReflectionEventing.Demo.Wpf/Events/OtherEvent.cs b/src/ReflectionEventing.Demo.Wpf/Events/OtherEvent.cs deleted file mode 100644 index 6f9ff20..0000000 --- a/src/ReflectionEventing.Demo.Wpf/Events/OtherEvent.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing.Demo.Wpf.Events; - -public class OtherEvent; diff --git a/src/ReflectionEventing.Demo.Wpf/GlobalUsings.cs b/src/ReflectionEventing.Demo.Wpf/GlobalUsings.cs deleted file mode 100644 index e0f6c55..0000000 --- a/src/ReflectionEventing.Demo.Wpf/GlobalUsings.cs +++ /dev/null @@ -1,17 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.IO; -global using System.Linq; -global using System.Reflection; -global using System.Threading; -global using System.Threading.Tasks; -global using System.Windows; -global using CommunityToolkit.Mvvm.ComponentModel; -global using Microsoft.Extensions.Configuration; -global using Microsoft.Extensions.DependencyInjection; -global using Microsoft.Extensions.Hosting; -global using Microsoft.Extensions.Logging; diff --git a/src/ReflectionEventing.Demo.Wpf/MainWindow.xaml b/src/ReflectionEventing.Demo.Wpf/MainWindow.xaml deleted file mode 100644 index d5599dd..0000000 --- a/src/ReflectionEventing.Demo.Wpf/MainWindow.xaml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - diff --git a/src/ReflectionEventing.Demo.Wpf/MainWindow.xaml.cs b/src/ReflectionEventing.Demo.Wpf/MainWindow.xaml.cs deleted file mode 100644 index 37be13c..0000000 --- a/src/ReflectionEventing.Demo.Wpf/MainWindow.xaml.cs +++ /dev/null @@ -1,21 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using ReflectionEventing.Demo.Wpf.ViewModels; - -namespace ReflectionEventing.Demo.Wpf; - -public partial class MainWindow -{ - public MainWindowViewModel ViewModel { get; } - - public MainWindow(MainWindowViewModel viewModel) - { - ViewModel = viewModel; - DataContext = this; - - InitializeComponent(); - } -} diff --git a/src/ReflectionEventing.Demo.Wpf/ReflectionEventing.Demo.Wpf.csproj b/src/ReflectionEventing.Demo.Wpf/ReflectionEventing.Demo.Wpf.csproj deleted file mode 100644 index 0b5cbf2..0000000 --- a/src/ReflectionEventing.Demo.Wpf/ReflectionEventing.Demo.Wpf.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - WinExe - net8.0-windows - true - false - - - - - - - - - - - - - - Always - - - - diff --git a/src/ReflectionEventing.Demo.Wpf/Services/ApplicationHostService.cs b/src/ReflectionEventing.Demo.Wpf/Services/ApplicationHostService.cs deleted file mode 100644 index 5fcd808..0000000 --- a/src/ReflectionEventing.Demo.Wpf/Services/ApplicationHostService.cs +++ /dev/null @@ -1,41 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing.Demo.Wpf.Services; - -internal sealed class ApplicationHostService(IServiceProvider serviceProvider) : IHostedService -{ - /// - /// Triggered when the application host is ready to start the service. - /// - /// Indicates that the start process has been aborted. - public async Task StartAsync(CancellationToken cancellationToken) - { - await HandleActivationAsync(); - } - - /// - /// Triggered when the application host is performing a graceful shutdown. - /// - /// Indicates that the shutdown process should no longer be graceful. - public Task StopAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - - /// - /// Creates main window during activation. - /// - private async Task HandleActivationAsync() - { - if (!Application.Current.Windows.OfType().Any()) - { - MainWindow mainWindow = serviceProvider.GetRequiredService(); - mainWindow!.Show(); - } - - await Task.CompletedTask; - } -} diff --git a/src/ReflectionEventing.Demo.Wpf/Services/BackgroundTickService.cs b/src/ReflectionEventing.Demo.Wpf/Services/BackgroundTickService.cs deleted file mode 100644 index 4bfe253..0000000 --- a/src/ReflectionEventing.Demo.Wpf/Services/BackgroundTickService.cs +++ /dev/null @@ -1,45 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using ReflectionEventing.Demo.Wpf.Events; - -namespace ReflectionEventing.Demo.Wpf.Services; - -internal sealed class BackgroundTickService(IEventBus eventBus) : IHostedService -{ - private const int TickRateInMilliseconds = 100; - - /// - public Task StartAsync(CancellationToken cancellationToken) - { - _ = Task.Run(() => TickInBackground(cancellationToken), cancellationToken) - .ConfigureAwait(false); - - return Task.CompletedTask; - } - - /// - public Task StopAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - - private async Task TickInBackground(CancellationToken cancellationToken) - { - await eventBus.PublishAsync(new OtherEvent(), cancellationToken); - - Random random = new(); - - while (!cancellationToken.IsCancellationRequested) - { - await eventBus.PublishAsync( - new BackgroundTicked(random.Next(10, 1001)), - cancellationToken - ); - - await Task.Delay(TickRateInMilliseconds, cancellationToken); - } - } -} diff --git a/src/ReflectionEventing.Demo.Wpf/ViewModels/MainWindowViewModel.cs b/src/ReflectionEventing.Demo.Wpf/ViewModels/MainWindowViewModel.cs deleted file mode 100644 index 83fd8d6..0000000 --- a/src/ReflectionEventing.Demo.Wpf/ViewModels/MainWindowViewModel.cs +++ /dev/null @@ -1,39 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using ReflectionEventing.Demo.Wpf.Events; - -namespace ReflectionEventing.Demo.Wpf.ViewModels; - -public partial class MainWindowViewModel(ILogger logger) - : ViewModel, - IConsumer, - IConsumer -{ - [ObservableProperty] - private int _currentTick; - - /// - public async Task ConsumeAsync(ITickedEvent payload, CancellationToken cancellationToken) - { - int tickValue = payload.Value; - - await DispatchAsync( - () => - { - CurrentTick = tickValue; - }, - cancellationToken - ); - } - - /// - public async Task ConsumeAsync(OtherEvent payload, CancellationToken cancellationToken) - { - logger.LogInformation("Received {Event} event.", nameof(OtherEvent)); - - await Task.CompletedTask; - } -} diff --git a/src/ReflectionEventing.Demo.Wpf/ViewModels/ViewModel.cs b/src/ReflectionEventing.Demo.Wpf/ViewModels/ViewModel.cs deleted file mode 100644 index c403426..0000000 --- a/src/ReflectionEventing.Demo.Wpf/ViewModels/ViewModel.cs +++ /dev/null @@ -1,31 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing.Demo.Wpf.ViewModels; - -/// -/// Represents an abstract ViewModel base class that provides functionality for dispatching actions on the UI thread. -/// -/// -/// This class extends the ObservableObject class to provide property change notification. -/// -public abstract class ViewModel : ObservableObject -{ - /// - /// Dispatches the specified action on the UI thread. - /// - /// The action to be dispatched. - /// A cancellation token that can be used to cancel the operation. - /// A task that represents the asynchronous operation. - protected static async Task DispatchAsync(Action action, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return; - } - - await Application.Current.Dispatcher.InvokeAsync(action); - } -} diff --git a/src/ReflectionEventing.Demo.Wpf/appsettings.json b/src/ReflectionEventing.Demo.Wpf/appsettings.json deleted file mode 100644 index 094870d..0000000 --- a/src/ReflectionEventing.Demo.Wpf/appsettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Warning" - }, - "Console": { - "IncludeScopes": true - } - } -} \ No newline at end of file diff --git a/src/ReflectionEventing.DependencyInjection/DependencyInjectionConsumerProvider.cs b/src/ReflectionEventing.DependencyInjection/DependencyInjectionConsumerProvider.cs deleted file mode 100644 index e89d4d0..0000000 --- a/src/ReflectionEventing.DependencyInjection/DependencyInjectionConsumerProvider.cs +++ /dev/null @@ -1,24 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing.DependencyInjection; - -/// -/// Represents a provider for retrieving event consumers from .NET Core's built-in dependency injection container. -/// -public class DependencyInjectionConsumerProvider(IServiceProvider serviceProvider) - : IConsumerProvider -{ - /// - public IEnumerable GetConsumers(Type consumerType) - { - if (consumerType is null) - { - throw new ArgumentNullException(nameof(consumerType)); - } - - return serviceProvider.GetServices(consumerType); - } -} diff --git a/src/ReflectionEventing.DependencyInjection/DependencyInjectionEventBusBuilder.cs b/src/ReflectionEventing.DependencyInjection/DependencyInjectionEventBusBuilder.cs deleted file mode 100644 index 84fd2a1..0000000 --- a/src/ReflectionEventing.DependencyInjection/DependencyInjectionEventBusBuilder.cs +++ /dev/null @@ -1,34 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using System.Diagnostics.CodeAnalysis; - -namespace ReflectionEventing.DependencyInjection; - -/// -/// Represents a builder for configuring the event bus with .NET Core's built-in dependency injection. -/// -public class DependencyInjectionEventBusBuilder(IServiceCollection services) : EventBusBuilder -{ - /// - public override EventBusBuilder AddConsumer( -#if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] -#endif - Type consumerType - ) - { - ServiceDescriptor? descriptor = services.FirstOrDefault(d => d.ServiceType == consumerType); - - if (descriptor is null) - { - throw new InvalidOperationException( - "Event consumer must be registered in the service collection." - ); - } - - return base.AddConsumer(consumerType); - } -} diff --git a/src/ReflectionEventing.DependencyInjection/GlobalUsings.cs b/src/ReflectionEventing.DependencyInjection/GlobalUsings.cs deleted file mode 100644 index b52d80b..0000000 --- a/src/ReflectionEventing.DependencyInjection/GlobalUsings.cs +++ /dev/null @@ -1,9 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; -global using System.Linq; -global using Microsoft.Extensions.DependencyInjection; diff --git a/src/ReflectionEventing.DependencyInjection/ReflectionEventing.DependencyInjection.csproj b/src/ReflectionEventing.DependencyInjection/ReflectionEventing.DependencyInjection.csproj deleted file mode 100644 index f6fae58..0000000 --- a/src/ReflectionEventing.DependencyInjection/ReflectionEventing.DependencyInjection.csproj +++ /dev/null @@ -1,44 +0,0 @@ - - - - ReflectionEventing.DependencyInjection - netstandard2.0;netstandard2.1;net462;net6.0;net8.0 - true - true - true - $(CommonTags);microsoft;dependency;injection;services;extensions - Micosoft Dependency Injection service extensions with ReflectionEventing, which promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications. - - - - true - true - Speed - - - - - - System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute; - System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute; - System.Diagnostics.CodeAnalysis.MemberNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; - System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute; - System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute; - System.Runtime.CompilerServices.CallerArgumentExpressionAttribute; - System.Runtime.CompilerServices.IsExternalInit; - System.Runtime.CompilerServices.SkipLocalsInitAttribute; - - - - - - - - - - - - diff --git a/src/ReflectionEventing.DependencyInjection/ServiceCollectionExtensions.cs b/src/ReflectionEventing.DependencyInjection/ServiceCollectionExtensions.cs deleted file mode 100644 index 2bc2b28..0000000 --- a/src/ReflectionEventing.DependencyInjection/ServiceCollectionExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing.DependencyInjection; - -/// -/// Provides extension methods for the interface. -/// -public static class ServiceCollectionExtensions -{ - /// - /// Adds the event bus and its related services to the specified services collection. - /// - /// The to add the event bus to. - /// A delegate that configures the . - /// The same service collection so that multiple calls can be chained. - /// - /// This method adds a singleton service of type that uses a with the consumers from the event bus builder. - /// It also adds a scoped service of type that uses the class. - /// - public static IServiceCollection AddEventBus( - this IServiceCollection services, - Action configure - ) - { - DependencyInjectionEventBusBuilder builder = new(services); - - configure(builder); - - _ = services.AddSingleton(builder.BuildTypesProvider()); - _ = services.AddScoped(); - _ = services.AddScoped(); - - return services; - } -} diff --git a/src/ReflectionEventing.Ninject/EventBusModule.cs b/src/ReflectionEventing.Ninject/EventBusModule.cs deleted file mode 100644 index 9495330..0000000 --- a/src/ReflectionEventing.Ninject/EventBusModule.cs +++ /dev/null @@ -1,37 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Ninject.Modules; - -namespace ReflectionEventing.Ninject; - -/// -/// Represents a Ninject module for configuring the event bus. -/// -public class EventBusModule(Action configure) : NinjectModule -{ - /// - /// Loads the module into the kernel. - /// - public override void Load() - { - if (Kernel is null) - { - throw new InvalidOperationException("The kernel is not set."); - } - - NinjectEventBusBuilder builder = new(Kernel); - - configure(builder); - - _ = Bind() - .ToConstant(builder.BuildTypesProvider()) - .InSingletonScope(); - - _ = Bind().To().InTransientScope(); - - _ = Bind().To().InTransientScope(); - } -} diff --git a/src/ReflectionEventing.Ninject/GlobalUsings.cs b/src/ReflectionEventing.Ninject/GlobalUsings.cs deleted file mode 100644 index 65109da..0000000 --- a/src/ReflectionEventing.Ninject/GlobalUsings.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; -global using System.Linq; diff --git a/src/ReflectionEventing.Ninject/NinjectConsumerProvider.cs b/src/ReflectionEventing.Ninject/NinjectConsumerProvider.cs deleted file mode 100644 index 44b2349..0000000 --- a/src/ReflectionEventing.Ninject/NinjectConsumerProvider.cs +++ /dev/null @@ -1,25 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Ninject; - -namespace ReflectionEventing.Ninject; - -/// -/// Provides event consumers for Ninject. -/// -public class NinjectConsumerProvider(IKernel kernel) : IConsumerProvider -{ - /// - public IEnumerable GetConsumers(Type consumerType) - { - if (consumerType is null) - { - throw new ArgumentNullException(nameof(consumerType)); - } - - return kernel.GetAll(consumerType); - } -} diff --git a/src/ReflectionEventing.Ninject/NinjectEventBusBuilder.cs b/src/ReflectionEventing.Ninject/NinjectEventBusBuilder.cs deleted file mode 100644 index b369317..0000000 --- a/src/ReflectionEventing.Ninject/NinjectEventBusBuilder.cs +++ /dev/null @@ -1,25 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Ninject; - -namespace ReflectionEventing.Ninject; - -/// -/// Represents a builder for configuring the event bus with Ninject. -/// -public class NinjectEventBusBuilder(IKernel kernel) : EventBusBuilder -{ - /// - public override EventBusBuilder AddConsumer(Type consumerType) - { - if (!kernel.GetBindings(consumerType).Any()) - { - throw new InvalidOperationException("Event consumer must be registered in the kernel."); - } - - return base.AddConsumer(consumerType); - } -} diff --git a/src/ReflectionEventing.Ninject/ReflectionEventing.Ninject.csproj b/src/ReflectionEventing.Ninject/ReflectionEventing.Ninject.csproj deleted file mode 100644 index 5b18ce2..0000000 --- a/src/ReflectionEventing.Ninject/ReflectionEventing.Ninject.csproj +++ /dev/null @@ -1,37 +0,0 @@ - - - - ReflectionEventing.Ninject - net462;net472;net481 - true - true - true - Ninject module with ReflectionEventing, which promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications. - - - - - - System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute; - System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute; - System.Diagnostics.CodeAnalysis.MemberNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; - System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute; - System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute; - System.Runtime.CompilerServices.CallerArgumentExpressionAttribute; - System.Runtime.CompilerServices.IsExternalInit; - System.Runtime.CompilerServices.SkipLocalsInitAttribute; - - - - - - - - - - - - diff --git a/src/ReflectionEventing.Unity/GlobalUsings.cs b/src/ReflectionEventing.Unity/GlobalUsings.cs deleted file mode 100644 index 65109da..0000000 --- a/src/ReflectionEventing.Unity/GlobalUsings.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; -global using System.Linq; diff --git a/src/ReflectionEventing.Unity/ReflectionEventing.Unity.csproj b/src/ReflectionEventing.Unity/ReflectionEventing.Unity.csproj deleted file mode 100644 index dbe03fc..0000000 --- a/src/ReflectionEventing.Unity/ReflectionEventing.Unity.csproj +++ /dev/null @@ -1,44 +0,0 @@ - - - - ReflectionEventing.Unity - netstandard2.0;netstandard2.1;net462;net6.0;net8.0 - true - true - true - $(CommonTags);unity;container - Unity container extensions with ReflectionEventing, which promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications. - - - - true - true - Speed - - - - - - System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute; - System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute; - System.Diagnostics.CodeAnalysis.MemberNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute; - System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; - System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute; - System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute; - System.Runtime.CompilerServices.CallerArgumentExpressionAttribute; - System.Runtime.CompilerServices.IsExternalInit; - System.Runtime.CompilerServices.SkipLocalsInitAttribute; - - - - - - - - - - - - diff --git a/src/ReflectionEventing.Unity/UnityConsumerProvider.cs b/src/ReflectionEventing.Unity/UnityConsumerProvider.cs deleted file mode 100644 index 67b450b..0000000 --- a/src/ReflectionEventing.Unity/UnityConsumerProvider.cs +++ /dev/null @@ -1,25 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Unity; - -namespace ReflectionEventing.Unity; - -/// -/// Provides event consumers for Unity. -/// -public class UnityConsumerProvider(IUnityContainer container) : IConsumerProvider -{ - /// - public IEnumerable GetConsumers(Type consumerType) - { - if (consumerType is null) - { - throw new ArgumentNullException(nameof(consumerType)); - } - - return container.ResolveAll(consumerType); - } -} diff --git a/src/ReflectionEventing.Unity/UnityContainerExtensions.cs b/src/ReflectionEventing.Unity/UnityContainerExtensions.cs deleted file mode 100644 index b205a3b..0000000 --- a/src/ReflectionEventing.Unity/UnityContainerExtensions.cs +++ /dev/null @@ -1,48 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Unity; -using Unity.Lifetime; - -namespace ReflectionEventing.Unity; - -/// -/// Provides extension methods for the interface. -/// -public static class UnityContainerExtensions -{ - /// - /// Adds the event bus and its related services to the specified Unity container. - /// - /// The to add the event bus to. - /// A delegate that configures the . - /// The same Unity container so that multiple calls can be chained. - /// - /// This method adds a singleton service of type that uses a with the consumers from the event bus builder. - /// It also adds a scoped service of type that uses the class. - /// - public static IUnityContainer AddEventBus( - this IUnityContainer container, - Action configure - ) - { - UnityEventBusBuilder builder = new(container); - - configure(builder); - - _ = container.RegisterInstance( - builder.BuildTypesProvider(), - new ContainerControlledLifetimeManager() - ); - - _ = container.RegisterType( - new HierarchicalLifetimeManager() - ); - - _ = container.RegisterType(new HierarchicalLifetimeManager()); - - return container; - } -} diff --git a/src/ReflectionEventing.Unity/UnityEventBusBuilder.cs b/src/ReflectionEventing.Unity/UnityEventBusBuilder.cs deleted file mode 100644 index e52347b..0000000 --- a/src/ReflectionEventing.Unity/UnityEventBusBuilder.cs +++ /dev/null @@ -1,13 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Unity; - -namespace ReflectionEventing.Unity; - -/// -/// Represents a builder for configuring the event bus with Unity. -/// -public class UnityEventBusBuilder(IUnityContainer container) : EventBusBuilder; diff --git a/src/ReflectionEventing/ConsumerTypesProviderExtensions.cs b/src/ReflectionEventing/ConsumerTypesProviderExtensions.cs deleted file mode 100644 index 9c29ffb..0000000 --- a/src/ReflectionEventing/ConsumerTypesProviderExtensions.cs +++ /dev/null @@ -1,22 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Provides extension methods for the class. -/// -public static class ConsumerTypesProviderExtensions -{ - /// - /// Gets the consumers for the specified event type. - /// - /// The type of the event to get the consumers for. - /// A collection of consumer types that can handle the specified event type. - public static IEnumerable GetConsumerTypes(this IConsumerTypesProvider provider) - { - return provider.GetConsumerTypes(typeof(TEvent)); - } -} diff --git a/src/ReflectionEventing/EventBus.cs b/src/ReflectionEventing/EventBus.cs deleted file mode 100644 index a12dc17..0000000 --- a/src/ReflectionEventing/EventBus.cs +++ /dev/null @@ -1,42 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Represents a class that provides event publishing capabilities. -/// -/// -/// This class uses a service provider to get required services and a consumer provider to get consumers for a specific event type. -/// -public class EventBus( - IConsumerProvider consumerProviders, - IConsumerTypesProvider consumerTypesProvider -) : IEventBus -{ - /// - public async Task PublishAsync(TEvent eventItem, CancellationToken cancellationToken) - where TEvent : class - { - if (eventItem is null) - { - throw new ArgumentNullException(nameof(eventItem)); - } - - Type eventType = typeof(TEvent); - List tasks = []; - IEnumerable consumerTypes = consumerTypesProvider.GetConsumerTypes(eventType); - - foreach (Type consumerType in consumerTypes) - { - foreach (object consumer in consumerProviders.GetConsumers(consumerType)) - { - tasks.Add(((IConsumer)consumer).ConsumeAsync(eventItem, cancellationToken)); - } - } - - await Task.WhenAll(tasks).ConfigureAwait(false); - } -} diff --git a/src/ReflectionEventing/EventBusBuilder.cs b/src/ReflectionEventing/EventBusBuilder.cs deleted file mode 100644 index 0dedff2..0000000 --- a/src/ReflectionEventing/EventBusBuilder.cs +++ /dev/null @@ -1,80 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Represents a class that builds an event bus with a specific set of classConsumers. -/// -/// -/// This class uses a dictionary of classConsumers where the key is the consumer type and the value is a collection of event types that the consumer can handle. -/// -public class EventBusBuilder -{ - private readonly IDictionary> classConsumers = - new Dictionary>(); - - /// - /// Gets or sets a value indicating whether the event bus should use event polymorphism. - /// If set to true, the event bus will deliver events to classConsumers that handle the event type or any of its base types. - /// If set to false, the event bus will only deliver events to classConsumers that handle the exact event type. - /// The default value is false. - /// - public EventBusBuilderOptions Options { get; } = new(); - - /// - /// Builds and returns an instance of based on the current configuration. - /// - /// - /// An instance of . If is set to true, - /// it returns an instance of , otherwise it returns an instance of . - /// - public IConsumerTypesProvider BuildTypesProvider() - { - return Options.UseEventPolymorphism - ? new HashedPolymorphicConsumerTypesProvider(classConsumers) - : new HashedConsumerTypesProvider(classConsumers); - } - - /// - /// Adds a consumer to the builder. - /// - /// The type of the consumer to add. - /// - /// This method checks if the consumer is registered in the service collection and if it is not transient. - /// It then gets the interfaces of the consumer that are generic and have a generic type definition of . - /// For each of these interfaces, it gets the generic argument and adds it to the classConsumers dictionary. - /// - public virtual EventBusBuilder AddConsumer( -#if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] -#endif - Type consumerType - ) - { - if (consumerType is null) - { - throw new ArgumentNullException(nameof(consumerType)); - } - - IEnumerable consumerInterfaces = consumerType - .GetInterfaces() - .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IConsumer<>)); - - foreach (Type consumerInterface in consumerInterfaces) - { - Type consumedEventType = consumerInterface.GetGenericArguments()[0]; - - if (!classConsumers.ContainsKey(consumerType)) - { - classConsumers[consumerType] = new HashSet(); - } - - _ = ((HashSet)classConsumers[consumerType]).Add(consumedEventType); - } - - return this; - } -} diff --git a/src/ReflectionEventing/EventBusBuilderExtensions.cs b/src/ReflectionEventing/EventBusBuilderExtensions.cs deleted file mode 100644 index 653dd37..0000000 --- a/src/ReflectionEventing/EventBusBuilderExtensions.cs +++ /dev/null @@ -1,89 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Provides extension methods for the class. -/// -public static class EventBusBuilderExtensions -{ - /// - /// Adds a consumer to the event bus builder. - /// - /// The type of the consumer to add. - /// The event bus builder to add the consumer to. - /// The event bus builder with the consumer added. - public static EventBusBuilder AddConsumer< -#if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] -#endif - TConsumer - >(this EventBusBuilder builder) - { - builder.AddConsumer(typeof(TConsumer)); - - return builder; - } - - /// - /// Adds all consumers from the specified assemblies to the event bus builder. - /// - /// The event bus builder to add the consumers to. - /// The assemblies to add the consumers from. - /// The event bus builder with the consumers added. - [RequiresUnreferencedCode("Calls System.Reflection.Assembly.GetTypes()")] - public static EventBusBuilder AddAllConsumers( - this EventBusBuilder builder, - params Assembly[] assemblies - ) - { - foreach (Assembly assembly in assemblies) - { - IEnumerable consumers = ExtractConsumersFromAssembly(assembly); - - RegisterAllConsumers(builder, consumers); - } - - return builder; - } - - [RequiresUnreferencedCode("Calls System.Reflection.Assembly.GetTypes()")] - private static IEnumerable ExtractConsumersFromAssembly(Assembly assembly) - { - Type[] types = assembly.GetTypes(); - - foreach (Type type in types) - { - Type[] typeInterfaces = type.GetInterfaces(); - - if (type.IsAbstract || !type.IsClass) - { - continue; - } - - foreach (Type typeInterface in typeInterfaces) - { - if (!typeInterface.IsGenericType) - { - continue; - } - - if (typeInterface.GetGenericTypeDefinition() == typeof(IConsumer<>)) - { - yield return type; - } - } - } - } - - private static void RegisterAllConsumers(EventBusBuilder builder, IEnumerable consumers) - { - foreach (Type consumerType in consumers) - { - builder.AddConsumer(consumerType); - } - } -} diff --git a/src/ReflectionEventing/EventBusBuilderOptions.cs b/src/ReflectionEventing/EventBusBuilderOptions.cs deleted file mode 100644 index 58aa90f..0000000 --- a/src/ReflectionEventing/EventBusBuilderOptions.cs +++ /dev/null @@ -1,21 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Represents configuration options for the class. -/// These options control the behavior of the event bus built by the . -/// -public class EventBusBuilderOptions -{ - /// - /// Gets or sets a value indicating whether the event bus should use event polymorphism. - /// If set to true, the event bus will deliver events to consumers that handle the event type or any of its base types. - /// If set to false, the event bus will only deliver events to consumers that handle the exact event type. - /// The default value is false. - /// - public bool UseEventPolymorphism { get; set; } = false; -} diff --git a/src/ReflectionEventing/EventBusExtensions.cs b/src/ReflectionEventing/EventBusExtensions.cs deleted file mode 100644 index a2678c4..0000000 --- a/src/ReflectionEventing/EventBusExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Provides extension methods for the . -/// -public static class EventBusExtensions -{ - /// - /// Publishes the specified event synchronously. - /// - /// The type of the event to publish. - /// The event bus to extend. - /// The event to publish. - [Obsolete($"May cause deadlock on UI threads, use {nameof(IEventBus.PublishAsync)} instead.")] - public static void Publish(this IEventBus eventBus, TEvent eventItem) - where TEvent : class - { - using CancellationTokenSource cancellationSource = new(); - - Task.Run( - () => - { - // ReSharper disable once AccessToDisposedClosure - eventBus - .PublishAsync(eventItem, cancellationSource.Token) - .ConfigureAwait(false) - .GetAwaiter() - .GetResult(); - }, - cancellationSource.Token - ) - .GetAwaiter() - .GetResult(); - } -} diff --git a/src/ReflectionEventing/GlobalUsings.cs b/src/ReflectionEventing/GlobalUsings.cs deleted file mode 100644 index b59a06c..0000000 --- a/src/ReflectionEventing/GlobalUsings.cs +++ /dev/null @@ -1,12 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; -global using System.Diagnostics.CodeAnalysis; -global using System.Linq; -global using System.Reflection; -global using System.Threading; -global using System.Threading.Tasks; diff --git a/src/ReflectionEventing/HashedConsumerTypesProvider.cs b/src/ReflectionEventing/HashedConsumerTypesProvider.cs deleted file mode 100644 index 2211168..0000000 --- a/src/ReflectionEventing/HashedConsumerTypesProvider.cs +++ /dev/null @@ -1,34 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Provides a mechanism for retrieving types of event consumers based on a specific event type. -/// -/// -/// This class uses a dictionary of consumers where the key is the consumer type and the value is a collection of event types that the consumer can handle. -/// -public class HashedConsumerTypesProvider(IDictionary> consumers) - : IConsumerTypesProvider -{ - /// - public IEnumerable GetConsumerTypes(Type eventType) - { - // ReSharper disable once LoopCanBeConvertedToQuery - foreach (KeyValuePair> consumer in consumers) - { - foreach (Type consumedEventType in consumer.Value) - { - if (consumedEventType == eventType) - { - yield return consumer.Key; - - break; - } - } - } - } -} diff --git a/src/ReflectionEventing/HashedPolymorphicConsumerTypesProvider.cs b/src/ReflectionEventing/HashedPolymorphicConsumerTypesProvider.cs deleted file mode 100644 index c9cf449..0000000 --- a/src/ReflectionEventing/HashedPolymorphicConsumerTypesProvider.cs +++ /dev/null @@ -1,61 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Provides a mechanism for retrieving types of event consumers based on a specific event type. -/// -/// -/// This class uses a dictionary of consumers where the key is the consumer type and the value is a collection of event types that the consumer can handle. -/// -public class HashedPolymorphicConsumerTypesProvider(IDictionary> consumers) - : IConsumerTypesProvider -{ - /// - public IEnumerable GetConsumerTypes(Type eventType) - { - foreach (KeyValuePair> consumer in consumers) - { - bool consumerHasRelatedType = false; - - foreach (Type consumedEventType in consumer.Value) - { - if (consumedEventType == eventType) - { - yield return consumer.Key; - - break; - } - - if (AreTypesRelated(consumedEventType, eventType)) - { - consumerHasRelatedType = true; - } - } - - if (!consumerHasRelatedType) - { - continue; - } - - if (consumer.Value is HashSet consumersHashSet) - { - _ = consumersHashSet.Add(eventType); - } - else if (consumer.Value is ICollection consumersCollection) - { - consumersCollection.Add(eventType); - } - - yield return consumer.Key; - } - } - - private static bool AreTypesRelated(Type type1, Type type2) - { - return type1.IsAssignableFrom(type2); - } -} diff --git a/src/ReflectionEventing/IConsumer.cs b/src/ReflectionEventing/IConsumer.cs deleted file mode 100644 index e554bbe..0000000 --- a/src/ReflectionEventing/IConsumer.cs +++ /dev/null @@ -1,24 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Defines a contract for a consumer that can handle a specific event type. -/// -/// The type of the event that the consumer can handle. -/// -/// Implementations of this interface are expected to provide a mechanism to consume a specific event type asynchronously. -/// -public interface IConsumer -{ - /// - /// Consumes the specified event asynchronously. - /// - /// The event to consume. - /// A cancellation token that can be used to cancel the operation. - /// A task that represents the asynchronous operation. - Task ConsumeAsync(TEvent payload, CancellationToken cancellationToken); -} diff --git a/src/ReflectionEventing/IConsumerProvider.cs b/src/ReflectionEventing/IConsumerProvider.cs deleted file mode 100644 index 37fdbcb..0000000 --- a/src/ReflectionEventing/IConsumerProvider.cs +++ /dev/null @@ -1,29 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Defines a provider for retrieving types of event consumers. -/// -/// -/// An implementation of this interface should be able to provide all types that are consumers of a specific event type. -/// The consumers are not necessarily instances, but rather the types that can be used to create instances of consumers. -/// -public interface IConsumerProvider -{ - /// - /// Gets the consumers objects for the specified event type. - /// - /// The type of the event that the consumers handle. - /// An enumerable of 's that are consumers of the specified event type. - /// - /// - /// Type consumerType = typeof(MyEvent); - /// IEnumerable<object> consumerTypes = consumerProvider.GetConsumers(consumerType); - /// - /// - IEnumerable GetConsumers(Type consumerType); -} diff --git a/src/ReflectionEventing/IConsumerTypesProvider.cs b/src/ReflectionEventing/IConsumerTypesProvider.cs deleted file mode 100644 index 304b3ce..0000000 --- a/src/ReflectionEventing/IConsumerTypesProvider.cs +++ /dev/null @@ -1,21 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Defines a contract for a provider that can supply consumers for a specific event type. -/// -/// -/// Implementations of this interface are expected to provide a mechanism to retrieve consumers that can handle a specific event type. -/// -public interface IConsumerTypesProvider -{ - /// - /// Gets the consumer types for the specified event type. - /// - /// A collection of consumer types that can handle the specified event type. - IEnumerable GetConsumerTypes(Type eventType); -} diff --git a/src/ReflectionEventing/IEventBus.cs b/src/ReflectionEventing/IEventBus.cs deleted file mode 100644 index 2dea8e3..0000000 --- a/src/ReflectionEventing/IEventBus.cs +++ /dev/null @@ -1,26 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing; - -/// -/// Provides event publishing capabilities. -/// -public interface IEventBus -{ - /// - /// Publishes the specified event asynchronously. - /// - /// The type of the event to publish. - /// The event to publish. - /// A cancellation token that can be used to cancel the operation. - /// A task that represents the asynchronous operation. - /// - /// This method gets the consumers for the specified event type from the consumer provider and then uses the service provider to get the required service for each consumer. - /// Each consumer is then used to consume the event asynchronously. - /// - Task PublishAsync(TEvent eventItem, CancellationToken cancellationToken) - where TEvent : class; -} diff --git a/tests/.gitkeep b/tests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/ReflectionEventing.Autofac.UnitTests/AutofacConsumerProviderTests.cs b/tests/ReflectionEventing.Autofac.UnitTests/AutofacConsumerProviderTests.cs deleted file mode 100644 index 2c338bc..0000000 --- a/tests/ReflectionEventing.Autofac.UnitTests/AutofacConsumerProviderTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Autofac; - -namespace ReflectionEventing.Autofac.UnitTests; - -public sealed class AutofacConsumerProviderTests -{ - [Fact] - public void GetConsumerTypes_ShouldThrowExceptionWhenConsumerTypeIsNull() - { - ILifetimeScope lifetimeScope = Substitute.For(); - AutofacConsumerProvider consumerProvider = new AutofacConsumerProvider(lifetimeScope); - - Action act = () => consumerProvider.GetConsumers(null!); - - _ = act.Should() - .Throw() - .WithMessage("Value cannot be null. (Parameter 'consumerType')"); - } - - [Fact] - public void GetConsumerTypes_ShouldReturnResolvedConsumerType() - { - TestConsumer testInstance = new(); - - ContainerBuilder builder = new ContainerBuilder(); - _ = builder.RegisterInstance(testInstance).As().SingleInstance(); - IContainer container = builder.Build(); - ILifetimeScope scope = container.BeginLifetimeScope(); - - AutofacConsumerProvider consumerProvider = new AutofacConsumerProvider(scope); - - IEnumerable actualConsumers = consumerProvider.GetConsumers(typeof(TestConsumer)); - - _ = actualConsumers.First().Should().Be(testInstance); - } - - public sealed record TestEvent; - - public sealed class TestConsumer : IConsumer - { - public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } -} diff --git a/tests/ReflectionEventing.Autofac.UnitTests/ContainerBuilderExtensionsTests.cs b/tests/ReflectionEventing.Autofac.UnitTests/ContainerBuilderExtensionsTests.cs deleted file mode 100644 index 04b408b..0000000 --- a/tests/ReflectionEventing.Autofac.UnitTests/ContainerBuilderExtensionsTests.cs +++ /dev/null @@ -1,48 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Autofac; - -namespace ReflectionEventing.Autofac.UnitTests; - -public sealed class ContainerBuilderExtensionsTests -{ - [Fact] - public void AddEventBus_RegistersServicesAndAddsConsumer() - { - ContainerBuilder builder = new ContainerBuilder(); - - _ = builder.RegisterType().AsSelf(); - _ = builder.AddEventBus(eventBusBuilder => - { - _ = eventBusBuilder.AddConsumer(); - }); - - IContainer container = builder.Build(); - - IConsumerTypesProvider consumerTypesProvider = container.Resolve(); - _ = consumerTypesProvider.Should().NotBeNull(); - _ = consumerTypesProvider.Should().BeOfType(); - - IConsumerProvider consumerProvider = container.Resolve(); - _ = consumerProvider.Should().NotBeNull(); - _ = consumerProvider.Should().BeOfType(); - - IEventBus eventBus = container.Resolve(); - _ = eventBus.Should().NotBeNull(); - _ = eventBus.Should().BeOfType(); - - IEnumerable consumers = consumerTypesProvider.GetConsumerTypes(); - _ = consumers.Should().ContainSingle().Which.Should().Be(typeof(TestConsumer)); - } - - public class TestConsumer : IConsumer - { - public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } - - public sealed record TestEvent; -} diff --git a/tests/ReflectionEventing.Autofac.UnitTests/GlobalUsings.cs b/tests/ReflectionEventing.Autofac.UnitTests/GlobalUsings.cs deleted file mode 100644 index e49f51b..0000000 --- a/tests/ReflectionEventing.Autofac.UnitTests/GlobalUsings.cs +++ /dev/null @@ -1,13 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; -global using System.Linq; -global using System.Threading; -global using System.Threading.Tasks; -global using FluentAssertions; -global using NSubstitute; -global using Xunit; diff --git a/tests/ReflectionEventing.Autofac.UnitTests/ReflectionEventing.Autofac.UnitTests.csproj b/tests/ReflectionEventing.Autofac.UnitTests/ReflectionEventing.Autofac.UnitTests.csproj deleted file mode 100644 index 9366fbc..0000000 --- a/tests/ReflectionEventing.Autofac.UnitTests/ReflectionEventing.Autofac.UnitTests.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - false - true - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - diff --git a/tests/ReflectionEventing.Castle.Windsor.UnitTests/EventBusInstallerTests.cs b/tests/ReflectionEventing.Castle.Windsor.UnitTests/EventBusInstallerTests.cs deleted file mode 100644 index 6ff0f77..0000000 --- a/tests/ReflectionEventing.Castle.Windsor.UnitTests/EventBusInstallerTests.cs +++ /dev/null @@ -1,55 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Castle.MicroKernel.Lifestyle; -using Castle.MicroKernel.Registration; -using Castle.Windsor; - -namespace ReflectionEventing.Castle.Windsor.UnitTests; - -public sealed class EventBusInstallerTests -{ - [Fact] - public void Install_RegistersServicesAndAddsConsumer() - { - IWindsorContainer container = new WindsorContainer(); - - _ = container.Register(Component.For().LifestyleScoped()); - - EventBusInstaller installer = - new(builder => - { - _ = builder.AddConsumer(); - }); - - installer.Install(container, null!); - - using IDisposable scope = container.BeginScope(); - - IConsumerTypesProvider consumerTypesProvider = container.Resolve(); - _ = consumerTypesProvider.Should().NotBeNull(); - _ = consumerTypesProvider.Should().BeOfType(); - - IConsumerProvider consumerProvider = container.Resolve(); - _ = consumerProvider.Should().NotBeNull(); - _ = consumerProvider.Should().BeOfType(); - - IEventBus eventBus = container.Resolve(); - _ = eventBus.Should().NotBeNull(); - _ = eventBus.Should().BeOfType(); - - IEnumerable consumers = consumerTypesProvider.GetConsumerTypes(); - - _ = consumers.First().Should().Be(typeof(TestConsumer)); - } - - public class TestConsumer : IConsumer - { - public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } - - public sealed record TestEvent; -} diff --git a/tests/ReflectionEventing.Castle.Windsor.UnitTests/EventBusTests.cs b/tests/ReflectionEventing.Castle.Windsor.UnitTests/EventBusTests.cs deleted file mode 100644 index 8ad3c10..0000000 --- a/tests/ReflectionEventing.Castle.Windsor.UnitTests/EventBusTests.cs +++ /dev/null @@ -1,59 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Castle.MicroKernel.Lifestyle; -using Castle.MicroKernel.Registration; -using Castle.Windsor; - -namespace ReflectionEventing.Castle.Windsor.UnitTests; - -public sealed class EventBusTests : IDisposable -{ - private readonly IWindsorContainer _container; - - public EventBusTests() - { - _container = new WindsorContainer(); - _ = _container.Register(Component.For().LifestyleScoped()); - - EventBusInstaller installer = - new(builder => - { - _ = builder.AddConsumer(); - }); - - installer.Install(_container, null!); - } - - [Fact] - public async Task PublishAsync_ShouldCallConsumeAsyncOnAllConsumers() - { - using IDisposable scope = _container.BeginScope(); - IEventBus eventBus = _container.Resolve(); - - await eventBus.PublishAsync(new TestEvent(), CancellationToken.None); - - _ = _container.Resolve().ReceivedEvents.Should().Be(1); - } - - public void Dispose() - { - _container.Dispose(); - } - - public class TestConsumer : IConsumer - { - public int ReceivedEvents { get; private set; } = 0; - - public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken) - { - ReceivedEvents++; - - return Task.CompletedTask; - } - } - - public sealed record TestEvent; -} diff --git a/tests/ReflectionEventing.Castle.Windsor.UnitTests/GlobalUsings.cs b/tests/ReflectionEventing.Castle.Windsor.UnitTests/GlobalUsings.cs deleted file mode 100644 index 47b5797..0000000 --- a/tests/ReflectionEventing.Castle.Windsor.UnitTests/GlobalUsings.cs +++ /dev/null @@ -1,12 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; -global using System.Linq; -global using System.Threading; -global using System.Threading.Tasks; -global using FluentAssertions; -global using Xunit; diff --git a/tests/ReflectionEventing.Castle.Windsor.UnitTests/ReflectionEventing.Castle.Windsor.UnitTests.csproj b/tests/ReflectionEventing.Castle.Windsor.UnitTests/ReflectionEventing.Castle.Windsor.UnitTests.csproj deleted file mode 100644 index 4134d20..0000000 --- a/tests/ReflectionEventing.Castle.Windsor.UnitTests/ReflectionEventing.Castle.Windsor.UnitTests.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - false - true - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - diff --git a/tests/ReflectionEventing.DependencyInjection.UnitTests/DependencyInjectionConsumerProviderTests.cs b/tests/ReflectionEventing.DependencyInjection.UnitTests/DependencyInjectionConsumerProviderTests.cs deleted file mode 100644 index 1e453c3..0000000 --- a/tests/ReflectionEventing.DependencyInjection.UnitTests/DependencyInjectionConsumerProviderTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Microsoft.Extensions.DependencyInjection; - -namespace ReflectionEventing.DependencyInjection.UnitTests; - -public sealed class DependencyInjectionConsumerProviderTests -{ - [Fact] - public void GetConsumerTypes_ShouldThrowExceptionWhenConsumerTypeIsNull() - { - IServiceProvider serviceProvider = Substitute.For(); - DependencyInjectionConsumerProvider consumerProvider = new(serviceProvider); - - Action act = () => consumerProvider.GetConsumers(null!); - - _ = act.Should() - .Throw() - .WithMessage("Value cannot be null. (Parameter 'consumerType')"); - } - - [Fact] - public void GetConsumerTypes_ShouldReturnServicesOfConsumerType() - { - IServiceCollection services = new ServiceCollection(); - _ = services.AddSingleton(); - _ = services.AddSingleton(); - DependencyInjectionConsumerProvider consumerProvider = new(services.BuildServiceProvider()); - - IEnumerable actualConsumers = consumerProvider.GetConsumers(typeof(TestConsumer)); - - _ = actualConsumers.Should().HaveCount(2); - } - - public record TestEvent; - - public class TestConsumer : IConsumer - { - public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } -} diff --git a/tests/ReflectionEventing.DependencyInjection.UnitTests/DependencyInjectionEventBusBuilderTests.cs b/tests/ReflectionEventing.DependencyInjection.UnitTests/DependencyInjectionEventBusBuilderTests.cs deleted file mode 100644 index 8bc0497..0000000 --- a/tests/ReflectionEventing.DependencyInjection.UnitTests/DependencyInjectionEventBusBuilderTests.cs +++ /dev/null @@ -1,50 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Microsoft.Extensions.DependencyInjection; - -namespace ReflectionEventing.DependencyInjection.UnitTests; - -public sealed class DependencyInjectionEventBusBuilderTests -{ - [Fact] - public void AddConsumer_ShouldThrowExceptionWhenConsumerNotRegistered() - { - IServiceCollection services = new ServiceCollection(); - DependencyInjectionEventBusBuilder eventBusBuilder = new(services); - - Action act = () => eventBusBuilder.AddConsumer(typeof(TestConsumer)); - - _ = act.Should() - .Throw() - .WithMessage("Event consumer must be registered in the service collection."); - } - - [Fact] - public void AddConsumer_ShouldAddConsumerToDictionaryWhenRegistered() - { - IServiceCollection services = new ServiceCollection(); - _ = services.AddSingleton(); - DependencyInjectionEventBusBuilder eventBusBuilder = new(services); - - eventBusBuilder.AddConsumer(typeof(TestConsumer)); - - IConsumerTypesProvider consumerTypesProvider = eventBusBuilder.BuildTypesProvider(); - _ = consumerTypesProvider - .GetConsumerTypes(typeof(TestEvent)) - .Should() - .Contain(typeof(TestConsumer)); - } - - public interface ITestEvent; - - public record TestEvent : ITestEvent; - - public class TestConsumer : IConsumer - { - public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } -} diff --git a/tests/ReflectionEventing.DependencyInjection.UnitTests/GlobalUsings.cs b/tests/ReflectionEventing.DependencyInjection.UnitTests/GlobalUsings.cs deleted file mode 100644 index e49f51b..0000000 --- a/tests/ReflectionEventing.DependencyInjection.UnitTests/GlobalUsings.cs +++ /dev/null @@ -1,13 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; -global using System.Linq; -global using System.Threading; -global using System.Threading.Tasks; -global using FluentAssertions; -global using NSubstitute; -global using Xunit; diff --git a/tests/ReflectionEventing.DependencyInjection.UnitTests/ReflectionEventing.DependencyInjection.UnitTests.csproj b/tests/ReflectionEventing.DependencyInjection.UnitTests/ReflectionEventing.DependencyInjection.UnitTests.csproj deleted file mode 100644 index 84dbe6b..0000000 --- a/tests/ReflectionEventing.DependencyInjection.UnitTests/ReflectionEventing.DependencyInjection.UnitTests.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - net8.0 - false - true - - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - diff --git a/tests/ReflectionEventing.DependencyInjection.UnitTests/ServiceCollectionExtensionsTests.cs b/tests/ReflectionEventing.DependencyInjection.UnitTests/ServiceCollectionExtensionsTests.cs deleted file mode 100644 index d57f7a4..0000000 --- a/tests/ReflectionEventing.DependencyInjection.UnitTests/ServiceCollectionExtensionsTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Microsoft.Extensions.DependencyInjection; - -namespace ReflectionEventing.DependencyInjection.UnitTests; - -public sealed class ServiceCollectionExtensionsTests -{ - [Fact] - public void AddEventBus_RegistersServicesAndAddsConsumer() - { - ServiceCollection services = new ServiceCollection(); - - _ = services.AddScoped(); - _ = services.AddEventBus(builder => - { - _ = builder.AddConsumer(); - }); - - ServiceProvider serviceProvider = services.BuildServiceProvider(); - - IConsumerTypesProvider? consumerTypesProvider = - serviceProvider.GetService(); - _ = consumerTypesProvider.Should().NotBeNull(); - _ = consumerTypesProvider.Should().BeOfType(); - - IConsumerProvider? consumerProvider = serviceProvider.GetService(); - _ = consumerProvider.Should().NotBeNull(); - _ = consumerProvider.Should().BeOfType(); - - IEventBus? eventBus = serviceProvider.GetService(); - _ = eventBus.Should().NotBeNull(); - _ = eventBus.Should().BeOfType(); - - IEnumerable consumers = consumerTypesProvider!.GetConsumerTypes(); - _ = consumers.First().Should().Be(typeof(TestConsumer)); - } - - public class TestConsumer : IConsumer - { - public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } - - public sealed record TestEvent; -} diff --git a/tests/ReflectionEventing.Ninject.UnitTests/EventBusModuleTests.cs b/tests/ReflectionEventing.Ninject.UnitTests/EventBusModuleTests.cs deleted file mode 100644 index 1ceaf52..0000000 --- a/tests/ReflectionEventing.Ninject.UnitTests/EventBusModuleTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using Ninject; - -namespace ReflectionEventing.Ninject.UnitTests; - -public sealed class EventBusModuleTests -{ - [Fact] - public void Load_RegistersServicesAndAddsConsumer() - { - IKernel kernel = new StandardKernel(); - - _ = kernel.Bind().ToSelf().InTransientScope(); - - kernel.Load( - new EventBusModule(builder => - { - _ = builder.AddConsumer(); - }) - ); - - IConsumerTypesProvider? consumerTypesProvider = kernel.Get(); - _ = consumerTypesProvider.Should().NotBeNull(); - _ = consumerTypesProvider.Should().BeOfType(); - - IConsumerProvider? consumerProvider = kernel.Get(); - _ = consumerProvider.Should().NotBeNull(); - _ = consumerProvider.Should().BeOfType(); - - IEventBus? eventBus = kernel.Get(); - _ = eventBus.Should().NotBeNull(); - _ = eventBus.Should().BeOfType(); - - IEnumerable consumers = consumerTypesProvider!.GetConsumerTypes(); - _ = consumers.First().Should().Be(typeof(TestConsumer)); - } - - public class TestConsumer : IConsumer - { - public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } - - public sealed record TestEvent; -} diff --git a/tests/ReflectionEventing.Ninject.UnitTests/GlobalUsings.cs b/tests/ReflectionEventing.Ninject.UnitTests/GlobalUsings.cs deleted file mode 100644 index 47b5797..0000000 --- a/tests/ReflectionEventing.Ninject.UnitTests/GlobalUsings.cs +++ /dev/null @@ -1,12 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; -global using System.Linq; -global using System.Threading; -global using System.Threading.Tasks; -global using FluentAssertions; -global using Xunit; diff --git a/tests/ReflectionEventing.Ninject.UnitTests/ReflectionEventing.Ninject.UnitTests.csproj b/tests/ReflectionEventing.Ninject.UnitTests/ReflectionEventing.Ninject.UnitTests.csproj deleted file mode 100644 index 77b1c39..0000000 --- a/tests/ReflectionEventing.Ninject.UnitTests/ReflectionEventing.Ninject.UnitTests.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - false - true - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - diff --git a/tests/ReflectionEventing.UnitTests/EventBusBuilderTests.cs b/tests/ReflectionEventing.UnitTests/EventBusBuilderTests.cs deleted file mode 100644 index 45342bd..0000000 --- a/tests/ReflectionEventing.UnitTests/EventBusBuilderTests.cs +++ /dev/null @@ -1,106 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using FluentAssertions.Collections; - -namespace ReflectionEventing.UnitTests; - -public sealed class EventBusBuilderTests -{ - [Fact] - public void AddConsumer_ShouldAddConsumerToDictionary() - { - Type consumerType = typeof(MySampleConsumer); - - EventBusBuilder eventBusBuilder = new(); - eventBusBuilder.AddConsumer(consumerType); - - IConsumerTypesProvider typesProvider = eventBusBuilder.BuildTypesProvider(); - _ = typesProvider.GetConsumerTypes(typeof(ITestEvent)).Should().Contain(consumerType); - _ = typesProvider.GetConsumerTypes(typeof(IBaseEvent)).Should().Contain(consumerType); - } - - [Fact] - public void AddConsumer_ShouldNotReturnConsumersTypes_WithoutPolymorphismEnabled() - { - Type consumerType = typeof(MySampleConsumer); - - EventBusBuilder eventBusBuilder = new(); - eventBusBuilder.AddConsumer(consumerType); - - IConsumerTypesProvider typesProvider = eventBusBuilder.BuildTypesProvider(); - GenericCollectionAssertions? consumers = typesProvider - .GetConsumerTypes(typeof(TestEvent)) - .Should(); - consumers.HaveCount(0); - } - - [Fact] - public void AddConsumer_ShouldReturnConsumersTypes_WhenPolymorphismEnabled() - { - Type consumerType = typeof(MySampleConsumer); - - EventBusBuilder eventBusBuilder = new(); - eventBusBuilder.Options.UseEventPolymorphism = true; - eventBusBuilder.AddConsumer(consumerType); - - IConsumerTypesProvider typesProvider = eventBusBuilder.BuildTypesProvider(); - - GenericCollectionAssertions? consumers = typesProvider - .GetConsumerTypes(typeof(TestEvent)) - .Should(); - consumers.HaveCount(1).And.Contain(consumerType); - } - - [Fact] - public void AddConsumer_ShouldReturnMultipleConsumersTypes_WhenPolymorphismEnabled() - { - Type primaryConsumerType = typeof(MySampleConsumer); - Type secondaryConsumerType = typeof(MySecondarySampleConsumer); - - EventBusBuilder eventBusBuilder = new(); - eventBusBuilder.Options.UseEventPolymorphism = true; - eventBusBuilder.AddConsumer(primaryConsumerType); - eventBusBuilder.AddConsumer(secondaryConsumerType); - - IConsumerTypesProvider typesProvider = eventBusBuilder.BuildTypesProvider(); - - GenericCollectionAssertions? consumers = typesProvider - .GetConsumerTypes(typeof(IBaseEvent)) - .Should(); - consumers.HaveCount(2).And.Contain(primaryConsumerType).And.Contain(secondaryConsumerType); - } - - public interface IBaseEvent; - - public interface ITestEvent; - - public sealed record TestEvent : ITestEvent, IBaseEvent; - - public sealed record SecondaryEvent : IBaseEvent; - - public sealed record MySampleConsumer : IConsumer, IConsumer - { - public Task ConsumeAsync(ITestEvent payload, CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - - /// - public Task ConsumeAsync(IBaseEvent payload, CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - } - - public sealed record MySecondarySampleConsumer : IConsumer - { - /// - public Task ConsumeAsync(IBaseEvent payload, CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - } -} diff --git a/tests/ReflectionEventing.UnitTests/EventBusTests.cs b/tests/ReflectionEventing.UnitTests/EventBusTests.cs deleted file mode 100644 index f73b84b..0000000 --- a/tests/ReflectionEventing.UnitTests/EventBusTests.cs +++ /dev/null @@ -1,54 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing.UnitTests; - -public sealed class EventBusTests -{ - private readonly IConsumerProvider _consumerProvider; - private readonly IConsumerTypesProvider _consumerTypesProvider; - private readonly EventBus _eventBus; - - public EventBusTests() - { - _consumerProvider = Substitute.For(); - _consumerTypesProvider = Substitute.For(); - _eventBus = new EventBus(_consumerProvider, _consumerTypesProvider); - } - - [Fact] - public async Task PublishAsync_ShouldCallConsumeAsyncOnAllConsumers() - { - TestEvent testEvent = new(); - Type consumerType = typeof(IConsumer); - IConsumer consumer = Substitute.For>(); - - _ = _consumerTypesProvider.GetConsumerTypes().Returns([consumerType]); - _ = _consumerProvider.GetConsumers(consumerType).Returns([consumer]); - - await _eventBus.PublishAsync(testEvent, CancellationToken.None); - - await consumer.Received().ConsumeAsync(testEvent, Arg.Any()); - } - - [Fact] -#pragma warning disable CS0618 // Type or member is obsolete - public async Task Publish_ShouldCallPublishAsync() - { - TestEvent testEvent = new(); - Type consumerType = typeof(IConsumer); - IConsumer consumer = Substitute.For>(); - - _ = _consumerTypesProvider.GetConsumerTypes().Returns([consumerType]); - _ = _consumerProvider.GetConsumers(consumerType).Returns([consumer]); - - _eventBus.Publish(testEvent); - - await consumer.Received().ConsumeAsync(testEvent, Arg.Any()); - } -#pragma warning restore CS0618 // Type or member is obsolete - - public sealed record TestEvent; -} diff --git a/tests/ReflectionEventing.UnitTests/GlobalUsings.cs b/tests/ReflectionEventing.UnitTests/GlobalUsings.cs deleted file mode 100644 index 1ea6c8b..0000000 --- a/tests/ReflectionEventing.UnitTests/GlobalUsings.cs +++ /dev/null @@ -1,12 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System; -global using System.Collections.Generic; -global using System.Threading; -global using System.Threading.Tasks; -global using FluentAssertions; -global using NSubstitute; -global using Xunit; diff --git a/tests/ReflectionEventing.UnitTests/HashedConsumerTypesProviderTests.cs b/tests/ReflectionEventing.UnitTests/HashedConsumerTypesProviderTests.cs deleted file mode 100644 index ad0fee6..0000000 --- a/tests/ReflectionEventing.UnitTests/HashedConsumerTypesProviderTests.cs +++ /dev/null @@ -1,55 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -namespace ReflectionEventing.UnitTests; - -public sealed class HashedConsumerTypesProviderTests -{ - [Fact] - public void GetConsumerTypes_ShouldReturnCollectionOfConsumers() - { - HashedConsumerTypesProvider testEvent = - new( - new Dictionary> - { - { typeof(PrimarySampleConsumer), [typeof(PrimaryTestEvent)] }, - { typeof(SecondarySampleConsumer), [typeof(PrimaryTestEvent)] }, - { typeof(TertiarySampleConsumer), [typeof(SecondaryTestEvent)] } - } - ); - - IEnumerable consumers = testEvent.GetConsumerTypes(); - - _ = consumers - .Should() - .HaveCount(2) - .And.Contain(typeof(PrimarySampleConsumer)) - .And.Contain(typeof(SecondarySampleConsumer)); - } - - private interface ITestEvent; - - private sealed record PrimaryTestEvent : ITestEvent; - - private sealed record SecondaryTestEvent : ITestEvent; - - private sealed record PrimarySampleConsumer : IConsumer - { - public Task ConsumeAsync(PrimaryTestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } - - private sealed record SecondarySampleConsumer : IConsumer - { - public Task ConsumeAsync(PrimaryTestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } - - private sealed record TertiarySampleConsumer : IConsumer - { - public Task ConsumeAsync(SecondaryTestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } -} diff --git a/tests/ReflectionEventing.UnitTests/ReflectionEventing.UnitTests.csproj b/tests/ReflectionEventing.UnitTests/ReflectionEventing.UnitTests.csproj deleted file mode 100644 index fe99c83..0000000 --- a/tests/ReflectionEventing.UnitTests/ReflectionEventing.UnitTests.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - false - true - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - diff --git a/tests/ReflectionEventing.Unity.UnitTests/GlobalUsings.cs b/tests/ReflectionEventing.Unity.UnitTests/GlobalUsings.cs deleted file mode 100644 index 25c353c..0000000 --- a/tests/ReflectionEventing.Unity.UnitTests/GlobalUsings.cs +++ /dev/null @@ -1,11 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -global using System.Collections.Generic; -global using System.Linq; -global using System.Threading; -global using System.Threading.Tasks; -global using FluentAssertions; -global using Xunit; diff --git a/tests/ReflectionEventing.Unity.UnitTests/ReflectionEventing.Unity.UnitTests.csproj b/tests/ReflectionEventing.Unity.UnitTests/ReflectionEventing.Unity.UnitTests.csproj deleted file mode 100644 index e18d1e1..0000000 --- a/tests/ReflectionEventing.Unity.UnitTests/ReflectionEventing.Unity.UnitTests.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - net8.0 - false - true - - - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - diff --git a/tests/ReflectionEventing.Unity.UnitTests/UnityContainerExtensionsTests.cs b/tests/ReflectionEventing.Unity.UnitTests/UnityContainerExtensionsTests.cs deleted file mode 100644 index 67afaa0..0000000 --- a/tests/ReflectionEventing.Unity.UnitTests/UnityContainerExtensionsTests.cs +++ /dev/null @@ -1,48 +0,0 @@ -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. -// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors. -// All Rights Reserved. - -using System; -using Unity; -using Unity.Lifetime; - -namespace ReflectionEventing.Unity.UnitTests; - -public sealed class UnityContainerExtensionsTests -{ - [Fact] - public void AddEventBus_RegistersServicesAndAddsConsumer() - { - UnityContainer container = new UnityContainer(); - - _ = container.RegisterType(new HierarchicalLifetimeManager()); - _ = container.AddEventBus(builder => - { - _ = builder.AddConsumer(); - }); - - IConsumerTypesProvider? consumerTypesProvider = container.Resolve(); - _ = consumerTypesProvider.Should().NotBeNull(); - _ = consumerTypesProvider.Should().BeOfType(); - - IConsumerProvider? consumerProvider = container.Resolve(); - _ = consumerProvider.Should().NotBeNull(); - _ = consumerProvider.Should().BeOfType(); - - IEventBus? eventBus = container.Resolve(); - _ = eventBus.Should().NotBeNull(); - _ = eventBus.Should().BeOfType(); - - IEnumerable consumers = consumerTypesProvider!.GetConsumerTypes(); - _ = consumers.First().Should().Be(typeof(TestConsumer)); - } - - public class TestConsumer : IConsumer - { - public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken) => - Task.CompletedTask; - } - - public sealed record TestEvent; -}