├── .gitignore ├── CoreDrivenArchitecture.sln ├── LICENSE ├── README.md ├── src ├── CoreDrivenArchitecture.API │ ├── Controllers │ │ └── VehiclesController.cs │ ├── CoreDrivenArchitecture.API.csproj │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── appsettings.Development.json │ └── appsettings.json ├── CoreDrivenArchitecture.DTOs │ ├── CoreDrivenArchitecture.DTOs.csproj │ └── Vehicles │ │ ├── CreateVehicleRequest.cs │ │ └── VehicleDto.cs ├── CoreDrivenArchitecture.Data │ ├── CoreDrivenArchitecture.Data.csproj │ ├── DataDependencyInjection.cs │ ├── Entities │ │ └── VehicleEntity.cs │ └── Repositories │ │ └── DatabaseRepository.cs ├── CoreDrivenArchitecture.Notificator │ ├── CoreDrivenArchitecture.Notificator.csproj │ ├── Events │ │ ├── IEventNotificator.cs │ │ └── RabbitMQClient.cs │ └── NotificatorDependencyInjection.cs └── CoreDrivenArchitecture.UseCases │ ├── CoreDrivenArchitecture.UseCases.csproj │ ├── Mappers │ └── VehicleMapper.cs │ ├── UseCasesDependencyInjection.cs │ └── Vehicles │ ├── AddVehicle.cs │ ├── GetVehicle.cs │ └── VehiclesUseCases.cs └── tests └── CoreDrivenArchitecture.UnitTests ├── CoreDrivenArchitecture.UnitTests.csproj └── UseCases └── Vehicles └── AddVehicleTests.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | .idea -------------------------------------------------------------------------------- /CoreDrivenArchitecture.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreDrivenArchitecture.API", "src\CoreDrivenArchitecture.API\CoreDrivenArchitecture.API.csproj", "{4CDE098C-7248-468B-B1CD-C33C5CC895A6}" 4 | EndProject 5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreDrivenArchitecture.UseCases", "src\CoreDrivenArchitecture.UseCases\CoreDrivenArchitecture.UseCases.csproj", "{102EA913-8B29-4A44-98E5-67B58991D58D}" 6 | EndProject 7 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreDrivenArchitecture.Data", "src\CoreDrivenArchitecture.Data\CoreDrivenArchitecture.Data.csproj", "{C74D7F05-CCC3-4F82-A794-2AC1A67A67ED}" 8 | EndProject 9 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreDrivenArchitecture.DTOs", "src\CoreDrivenArchitecture.DTOs\CoreDrivenArchitecture.DTOs.csproj", "{44AC405F-A9E4-4A38-A672-B319E75B7A3E}" 10 | EndProject 11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreDrivenArchitecture.Notificator", "src\CoreDrivenArchitecture.Notificator\CoreDrivenArchitecture.Notificator.csproj", "{CB31DCD0-545D-4B48-B4EE-B361F8AE4A15}" 12 | EndProject 13 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{504535B9-AD90-4D31-B8A7-34C3CEE87231}" 14 | EndProject 15 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{BFEBE4FC-852D-45CB-A90D-7AE983F8BAC8}" 16 | EndProject 17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreDrivenArchitecture.UnitTests", "tests\CoreDrivenArchitecture.UnitTests\CoreDrivenArchitecture.UnitTests.csproj", "{99F53A71-F67E-40FE-B209-19D39F3DDC43}" 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Any CPU = Debug|Any CPU 22 | Release|Any CPU = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {4CDE098C-7248-468B-B1CD-C33C5CC895A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {4CDE098C-7248-468B-B1CD-C33C5CC895A6}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {4CDE098C-7248-468B-B1CD-C33C5CC895A6}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {4CDE098C-7248-468B-B1CD-C33C5CC895A6}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {102EA913-8B29-4A44-98E5-67B58991D58D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {102EA913-8B29-4A44-98E5-67B58991D58D}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {102EA913-8B29-4A44-98E5-67B58991D58D}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {102EA913-8B29-4A44-98E5-67B58991D58D}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {C74D7F05-CCC3-4F82-A794-2AC1A67A67ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {C74D7F05-CCC3-4F82-A794-2AC1A67A67ED}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {C74D7F05-CCC3-4F82-A794-2AC1A67A67ED}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {C74D7F05-CCC3-4F82-A794-2AC1A67A67ED}.Release|Any CPU.Build.0 = Release|Any CPU 37 | {44AC405F-A9E4-4A38-A672-B319E75B7A3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 38 | {44AC405F-A9E4-4A38-A672-B319E75B7A3E}.Debug|Any CPU.Build.0 = Debug|Any CPU 39 | {44AC405F-A9E4-4A38-A672-B319E75B7A3E}.Release|Any CPU.ActiveCfg = Release|Any CPU 40 | {44AC405F-A9E4-4A38-A672-B319E75B7A3E}.Release|Any CPU.Build.0 = Release|Any CPU 41 | {CB31DCD0-545D-4B48-B4EE-B361F8AE4A15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 42 | {CB31DCD0-545D-4B48-B4EE-B361F8AE4A15}.Debug|Any CPU.Build.0 = Debug|Any CPU 43 | {CB31DCD0-545D-4B48-B4EE-B361F8AE4A15}.Release|Any CPU.ActiveCfg = Release|Any CPU 44 | {CB31DCD0-545D-4B48-B4EE-B361F8AE4A15}.Release|Any CPU.Build.0 = Release|Any CPU 45 | {99F53A71-F67E-40FE-B209-19D39F3DDC43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {99F53A71-F67E-40FE-B209-19D39F3DDC43}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {99F53A71-F67E-40FE-B209-19D39F3DDC43}.Release|Any CPU.ActiveCfg = Release|Any CPU 48 | {99F53A71-F67E-40FE-B209-19D39F3DDC43}.Release|Any CPU.Build.0 = Release|Any CPU 49 | EndGlobalSection 50 | GlobalSection(NestedProjects) = preSolution 51 | {4CDE098C-7248-468B-B1CD-C33C5CC895A6} = {504535B9-AD90-4D31-B8A7-34C3CEE87231} 52 | {C74D7F05-CCC3-4F82-A794-2AC1A67A67ED} = {504535B9-AD90-4D31-B8A7-34C3CEE87231} 53 | {44AC405F-A9E4-4A38-A672-B319E75B7A3E} = {504535B9-AD90-4D31-B8A7-34C3CEE87231} 54 | {CB31DCD0-545D-4B48-B4EE-B361F8AE4A15} = {504535B9-AD90-4D31-B8A7-34C3CEE87231} 55 | {102EA913-8B29-4A44-98E5-67B58991D58D} = {504535B9-AD90-4D31-B8A7-34C3CEE87231} 56 | {99F53A71-F67E-40FE-B209-19D39F3DDC43} = {BFEBE4FC-852D-45CB-A90D-7AE983F8BAC8} 57 | EndGlobalSection 58 | EndGlobal 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Core-Driven Architecture: My Ideal Application Architecture 2 | 3 | This document is a translation of the original post in [My blog (in Spanish)](https://www.netmentor.es/entrada/core-driven-architecture). 4 | I'll explain what I consider the ideal architecture for an application. Unlike my previous, more objective posts, here I'll share my personal opinion and explain why I prefer this approach. 5 | 6 | ##### Table of contents 7 | - [1. What is Core-Driven Architecture?](#1-what-is-core-driven-architecture) 8 | - [2. Separation of Responsibilities in a Core-Driven Architecture](#2-separation-of-responsibilities-in-a-core-driven-architecture) 9 | - [2.1 Application Entry Point](#21-application-entry-point) 10 | - [2.2 Use Case Layer](#22-use-case-layer) 11 | - [2.3 External Elements](#23-external-elements) 12 | - [2.4 Dependency Injection](#24-dependency-injection) 13 | - [2.5 Best Practices in Core-Driven Architecture](#25-best-practices-in-core-driven-architecture) 14 | - [3. Tests within a Core-Driven Architecture](#3-tests-within-a-core-driven-architecture) 15 | 16 | 17 | ## 1. What is Core-Driven Architecture? 18 | 19 | I will be discussing within the context of a professional environment or large applications. 20 | If you just want to make a small script or a small functionality that does X, I wouldn't do it this way; 21 | for that, you just create a script. 22 | 23 | But let’s get into it. I worked with several application architectures like like MVC, Clean, Vertical Slice, or Hexagonal. 24 | While I don't strictly adhere to a predefined architecture, I mix a bit of everything to work in a way that is comfortable for me, which, in the end, is what matters. 25 | 26 | This architecture might resemble others by about 90%, but there are so many that it doesn’t make sense to argue about it. 27 | What matters isn't the name, which I made up while writing this post, but rather the concept. 28 | 29 | ## 2. Separation of Responsibilities in a Core-Driven Architecture 30 | 31 | What I strictly follow is the separation of responsibilities. 32 | 33 | This means that within each application, I will have different layers, and each layer has a clear responsibility. 34 | 35 | It’s a mix between Clean Architecture, Hexagonal, and Layered, because we have a layer where the business logic is the most important (Clean Architecture), 36 | we use dependencies through interfaces (ports and adapters from Hexagonal), 37 | and there’s the layer separation and inward direction as seen in Layered. 38 | 39 | For example, in an API, we might have the following: 40 | 41 | ![image core-driven architecture](https://www.netmentor.es/imagen/84d0d63e-95de-46e7-a88a-37b4d89fa29f.jpg "Core-Driven Architecture") 42 | 43 | If you are working with C#, you can use folders or projects within a solution. 44 | Personally, I don’t mind as long as they are separated and have a clear division. 45 | 46 | ### 2.1 Application Entry Point 47 | 48 | As we can see, we have an endpoint that only acts as a proxy between the call and the use case we are going to execute. 49 | The endpoint’s function is routing and checking authorization. It handles whatever is in the request pipeline, such as OpenAPI configuration; 50 | in summary, only elements related to being an API are present here. 51 | 52 | This means that if, instead of being an API, it’s a consumer of distributed architectures, the only change is that we 53 | won't have an endpoint launching the action, but rather a handler reading an event, 54 | verifying it hasn’t been processed, etc. 55 | 56 | ![image entry point core-driven architecture](https://www.netmentor.es/imagen/345a23ce-5fdb-4b74-8dea-5fe3d208f885.jpg "Entry Point Core-Driven Architecture") 57 | 58 | The same applies to the interface. If we use MVC, the interface may launch the call to the corresponding controller. 59 | What matters is that this layer is the **entry point from the outside to our application** and acts as such. 60 | 61 | 62 | ### 2.2 Use Case Layer 63 | 64 | The intermediate layer is the most important because it contains the business logic layer, 65 | which is what we really need to test. This layer will perform all necessary checks and actions required by our use case. 66 | 67 | ![image use case layer core-driven architecture](https://www.netmentor.es/imagen/dd3fa21b-3c23-4ce5-a02b-a13618e72187.jpg "Use Case Layer Core-Driven Architecture") 68 | 69 | For example, if we are creating clients in the database, we verify all the data, insert them, and as the final step, 70 | we publish an event indicating that an element has been created. All these actions happen within this use case. 71 | 72 | For me, it’s important that this layer follows the **Single Responsibility Principle**. This means that each use case will perform a single action. 73 | Performing an action doesn’t refer to just validating or only inserting into the database; 74 | it refers to all the business rules required for something to happen. 75 | 76 | This means that for creating a client, you will have one use case, and for updating a client, you will have a different one. 77 | In C#, this translates into several classes instead of one massive class doing many things. 78 | 79 | This implies that, by the way we work, the API will comply with **CQRS**, separating reads from writes within our application. 80 | 81 | Each use case contains everything needed to function. 82 | For example, if we are using the database, we inject it, whether it’s the DbContext or a repository if using the 83 | repository pattern or unit of work. If we are sending an event at the end of the process to notify that an 84 | element was created, we also inject the interface responsible for triggering these events: 85 | 86 | ```csharp 87 | public class AddVehicle(IDatabaseRepository databaseRepository, 88 | IEventNotificator eventNotificator) 89 | { 90 | public async Task> Execute(CreateVehicleRequest request) 91 | { 92 | VehicleEntity vehicleEntity = await databaseRepository.AddVehicle(request); 93 | var dto = vehicleEntity.ToDto(); 94 | await eventNotificator.Notify(dto); 95 | return dto; 96 | } 97 | } 98 | ``` 99 | 100 | In this part, I use the same logic as Hexagonal Architecture with ports and adapters. 101 | 102 | In this use case layer, many people who use **Clean Architecture** implement the mediator pattern. 103 | If you’ve read my post about Clean Architecture, you know my opinion on the mediator pattern: I personally don’t use it because it doesn’t add value, 104 | especially when used incorrectly (handlers calling other handlers). 105 | So, what I do is have one class per use case or action and then one class per “group” to encapsulate them: 106 | ```csharp 107 | public record class VehiclesUseCases( 108 | AddVehicle AddVehicle, 109 | GetVehicle GetVehicle); 110 | ``` 111 | 112 | Even though the code is more coupled, I don’t see this as a bad thing since it's a microservice and there’s no issue. 113 | 114 | Generally speaking, I don’t use interfaces in this layer, which means we inject concrete classes into the dependency container. 115 | The reason is simple: interfaces in this layer do not provide any value. 116 | 117 | ### 2.3 External Elements 118 | Finally, the last layer is where I define all the external elements of the application. 119 | Here is where you’ll find reasons to use `async/await` since we will be communicating with external elements of the application. 120 | 121 | ![image external elements core-driven architecture](https://www.netmentor.es/imagen/fd65e9c1-a5f9-46b9-9b68-64eb6dd2cf1f.jpg "External Elements Core-Driven Architecture") 122 | 123 | 124 | In my particular workflow, I usually divide this layer into different projects within a single solution to have a clear separation. 125 | For example, I create a project called Data for everything related to the database. Whether I use the repository pattern or the DbContext, 126 | it will be located in this project, along with the database entities. 127 | 128 | If I use RabbitMQ for event communication, all RabbitMQ configuration and implementation will be in that specific project. 129 | 130 | As you can imagine, all access to different parts of the infrastructure or external services goes here. 131 | You can use either projects or folders, depending on how much you have and your personal preference or your organization’s standards. 132 | 133 | ### 2.4 Dependency Injection 134 | This architecture heavily relies on Dependency Injection, as we will inject all elements into the upper layers. 135 | 136 | For example, I inject the use cases into the controller and the database into the use cases. So far, everything is normal, 137 | but what I also do is declare all the elements that need to be injected within the project where they are defined. 138 | 139 | This means that within my use case project, I have a static class with a single public method called `AddUseCases`, 140 | but I also have a private method for each group of elements to be injected. This is the result: 141 | 142 | ```csharp 143 | public static class UseCasesDependencyInjection 144 | { 145 | public static IServiceCollection AddUseCases(this IServiceCollection services) 146 | => services.AddVehicleUseCases(); 147 | 148 | private static IServiceCollection AddVehicleUseCases(this IServiceCollection services) 149 | => services.AddScoped() 150 | .AddScoped() 151 | .AddScoped(); 152 | } 153 | ``` 154 | 155 | In `Program.cs`, this is called like so: 156 | 157 | ```csharp 158 | builder.Services 159 | .AddUseCases() 160 | .AddData() 161 | .AddNotificator(); 162 | ```` 163 | 164 | In the upper layer (API), we simply invoke this `AddUseCases`. 165 | 166 | Something to consider here: this configuration is simplified to improve the speed and ease with which we work with dependencies. 167 | Five years ago, when I started with the web, I created a library on GitHub and NuGet that allows you to indicate in the dependency 168 | project which modules you will need, and it checks if they are already injected. If not, it fails. 169 | The idea is good and it works (at least up to .NET 5), but I don’t think it’s worth it. 170 | 171 | Although you could do something like this: 172 | ```csharp 173 | var serviceProvider = new ServiceCollection() 174 | .ApplyModule(UseCases.DiModule) 175 | .ApplyModule(Database.DiModule) 176 | .BuildServiceProvider(); 177 | ``` 178 | 179 | What I do now is evolve towards simplicity. 180 | 181 | 182 | ### 2.5 Best Practices in Core-Driven Architecture 183 | 184 | As a final point, I will include certain preferences I have regarding how I build applications. 185 | 186 | Personally, I have been using the **Result pattern** for more than five years, even though it has recently become trendy. 187 | The reason I like it is because it allows me to have an object that contains two states—success and error. 188 | Then, in the API, I can map it to a **ProblemDetails** with the correct HTTP status code. 189 | 190 | - [Link to my own Result pattern](https://github.com/ElectNewt/EjemploRop) 191 | 192 | 193 | Unless the application is very small, I always use **standard controllers**, not minimal APIs. 194 | This is because for creating APIs that are compatible with OpenAPI, it is much better. I will cover this more extensively in a future post. 195 | 196 | **Use cases will always return a DTO** that can be safely sent outside the application. 197 | Within use cases, you can use entities, but never return an entity from a use case. This is the difference between a DTO and an entity. 198 | Lastly, I keep my DTOs in a separate project, so I can create a NuGet package if needed. 199 | 200 | 201 | 202 | 203 | All APIs should not be Backend For Frontend (BFF), understanding BFF as an API that receives a request and returns all the necessary information. 204 | For example, let’s say we have a vehicle API where we create vehicle properties like brand, doors, color, etc. 205 | 206 | The number of vehicles in stock is part of the inventory service, not the vehicle API. Therefore, if the user interface wants to display the number of available vehicles along with their details, we have several options: 207 | 208 | 1. Call the inventory API from within the vehicle API to check how many are available. 209 | 2. Create a BFF application that will aggregate the information from both services (or use **GraphQL federated**). 210 | 3. Have the UI make both calls independently. 211 | 212 | ![img backend for frontend](https://www.netmentor.es/imagen/a9e5dd81-8d38-441a-92d4-e938337e31a8.jpg "Backend for Frontend") 213 | 214 | In my view, stock information does not belong to our vehicle API’s domain, so the first option should not be valid. 215 | Whether you choose option two or three depends on the user experience you want to offer. 216 | 217 | 218 | When we use **CQRS** to separate reads from writes, it doesn’t mean we are only querying the database. 219 | The separation is from the perspective of the consumer of the use case. 220 | If we call `GetVehicle`, we will return a vehicle; we will not make any modifications to the database. **It’s common sense**. 221 | 222 | 223 | ## 3. Tests within a Core-Driven Architecture 224 | 225 | You might be thinking that tests are not part of an application’s architecture or whatever you may believe. 226 | 227 | However, the truth is that tests are necessary, so I wanted to include a small section on this. Ideally, 228 | we should cover all types of tests and have everything tested, etc. This isn’t always realistic or possible. 229 | But, thanks to how our application is designed, it is very easy to test our use cases, which are the core of our application. 230 | 231 | As you may have noticed throughout this post, each use case has a single entry point, meaning that we will only have one method to test. 232 | This doesn’t mean we should write only one test. Instead, we should have one test for each possible outcome of the use case. 233 | If we are using exceptions for validation, we should validate those exceptions. If we are using `Result`, we must validate each possible result. 234 | 235 | Here’s an example of testing the `AddVehicle` use case: 236 | 237 | ```csharp 238 | public class AddVehicleTests 239 | { 240 | private class TestState 241 | { 242 | public Mock DatabaseRepository { get; set; } 243 | public AddVehicle Subject { get; set; } 244 | public Mock EventNotificator { get; set; } 245 | 246 | public TestState() 247 | { 248 | DatabaseRepository = new Mock(); 249 | EventNotificator = new Mock(); 250 | Subject = new AddVehicle(DatabaseRepository.Object, EventNotificator.Object); 251 | } 252 | } 253 | 254 | [Fact] 255 | public async Task WhenVehicleRequestHasCorrectData_thenInserted() 256 | { 257 | TestState state = new(); 258 | string make = "opel"; 259 | string name = "vehicle1"; 260 | int id = 1; 261 | state.DatabaseRepository.Setup(x => x 262 | .AddVehicle(It.IsAny())) 263 | .ReturnsAsync(new VehicleEntity() { Id = id, Make = make, Name = name }); 264 | 265 | 266 | var result = await state.Subject 267 | .Execute(new CreateVehicleRequest() { Make = make, Name = name }); 268 | 269 | Assert.True(result.Success); 270 | Assert.Equal(make, result.Value.Make); 271 | Assert.Equal(id, result.Value.Id); 272 | Assert.Equal(name, result.Value.Name); 273 | 274 | state.EventNotificator.Verify(a => 275 | a.Notify(result.Value), Times.Once); 276 | } 277 | } 278 | ``` 279 | 280 | While it’s important to test every possible outcome, the most important thing is to test the happy path, 281 | which is the path the code will follow when everything works as expected. 282 | 283 | As you can see, I use Moq as my mocking library, though there are other alternatives available. 284 | 285 | I also tend to create a class that acts as a “base” for the happy path and contains the dependencies that will be used. 286 | 287 | Each test then describes in its name what it does and what it validates. -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.API/Controllers/VehiclesController.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.DTOs.Vehicles; 2 | using CoreDrivenArchitecture.UseCases.Vehicles; 3 | using Microsoft.AspNetCore.Mvc; 4 | using ROP.APIExtensions; 5 | 6 | namespace CoreDrivenArchitecture.API.Controllers; 7 | 8 | [Route("api/[controller]")] 9 | [ApiController] 10 | public class VehiclesController(VehiclesUseCases vehicles) 11 | { 12 | [HttpGet("{id}")] 13 | public async Task Get(int id) 14 | => await vehicles.GetVehicle.Execute(id) 15 | .ToValueOrProblemDetails(); 16 | 17 | [HttpPost] 18 | public async Task Post(CreateVehicleRequest request) 19 | => await vehicles.AddVehicle.Execute(request) 20 | .ToValueOrProblemDetails(); 21 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.API/CoreDrivenArchitecture.API.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.API/Program.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.Data; 2 | using CoreDrivenArchitecture.Notificator; 3 | using CoreDrivenArchitecture.UseCases; 4 | 5 | var builder = WebApplication.CreateBuilder(args); 6 | 7 | // Add services to the container. 8 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 9 | builder.Services.AddEndpointsApiExplorer(); 10 | builder.Services.AddSwaggerGen(); 11 | builder.Services.AddControllers(); 12 | 13 | builder.Services 14 | .AddUseCases() 15 | .AddData() 16 | .AddNotificator(); 17 | 18 | 19 | var app = builder.Build(); 20 | 21 | // Configure the HTTP request pipeline. 22 | if (app.Environment.IsDevelopment()) 23 | { 24 | app.UseSwagger(); 25 | app.UseSwaggerUI(); 26 | } 27 | 28 | app.UseHttpsRedirection(); 29 | app.MapControllers(); 30 | 31 | 32 | app.Run(); -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:12878", 8 | "sslPort": 44378 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5122", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7186;http://localhost:5122", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.API/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.API/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.DTOs/CoreDrivenArchitecture.DTOs.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.DTOs/Vehicles/CreateVehicleRequest.cs: -------------------------------------------------------------------------------- 1 | namespace CoreDrivenArchitecture.DTOs.Vehicles; 2 | 3 | public class CreateVehicleRequest 4 | { 5 | public required string Name { get; set; } 6 | public required string Make { get; set; } 7 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.DTOs/Vehicles/VehicleDto.cs: -------------------------------------------------------------------------------- 1 | namespace CoreDrivenArchitecture.DTOs.Vehicles; 2 | 3 | public class VehicleDto 4 | { 5 | public int Id { get; set; } 6 | public required string Name { get; set; } 7 | public required string Make { get; set; } 8 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.Data/CoreDrivenArchitecture.Data.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.Data/DataDependencyInjection.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.Data.Repositories; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace CoreDrivenArchitecture.Data; 5 | 6 | public static class DataDependencyInjection 7 | { 8 | public static IServiceCollection AddData(this IServiceCollection services) 9 | => services.AddScoped(); 10 | 11 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.Data/Entities/VehicleEntity.cs: -------------------------------------------------------------------------------- 1 | namespace CoreDrivenArchitecture.Data.Entities; 2 | 3 | public class VehicleEntity 4 | { 5 | public int Id { get; set; } 6 | public required string Name { get; set; } 7 | public required string Make { get; set; } 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.Data/Repositories/DatabaseRepository.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.Data.Entities; 2 | using CoreDrivenArchitecture.DTOs.Vehicles; 3 | 4 | namespace CoreDrivenArchitecture.Data.Repositories; 5 | 6 | public interface IDatabaseRepository 7 | { 8 | Task AddVehicle(CreateVehicleRequest vehicle); 9 | Task GetVehicle(int id); 10 | } 11 | 12 | public class DatabaseRepository : IDatabaseRepository 13 | { 14 | public Task AddVehicle(CreateVehicleRequest vehicle) 15 | { 16 | throw new NotImplementedException(); 17 | } 18 | 19 | public Task GetVehicle(int id) 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.Notificator/CoreDrivenArchitecture.Notificator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.Notificator/Events/IEventNotificator.cs: -------------------------------------------------------------------------------- 1 | namespace CoreDrivenArchitecture.Notificator.Events; 2 | 3 | public interface IEventNotificator 4 | { 5 | Task Notify(T message); 6 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.Notificator/Events/RabbitMQClient.cs: -------------------------------------------------------------------------------- 1 | namespace CoreDrivenArchitecture.Notificator.Events; 2 | 3 | public class RabbitMQClient : IEventNotificator 4 | { 5 | public Task Notify(T message) 6 | { 7 | throw new NotImplementedException(); 8 | } 9 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.Notificator/NotificatorDependencyInjection.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.Notificator.Events; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace CoreDrivenArchitecture.Notificator; 5 | 6 | public static class NotificatorDependencyInjection 7 | { 8 | public static IServiceCollection AddNotificator(this IServiceCollection services) 9 | => services.AddScoped(); 10 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.UseCases/CoreDrivenArchitecture.UseCases.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.UseCases/Mappers/VehicleMapper.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.Data.Entities; 2 | using CoreDrivenArchitecture.DTOs.Vehicles; 3 | 4 | namespace CoreDrivenArchitecture.UseCases.Mappers; 5 | 6 | public static class VehicleMapper 7 | { 8 | public static VehicleDto ToDto(this VehicleEntity vehicleEntity) 9 | => new VehicleDto 10 | { 11 | Id = vehicleEntity.Id, 12 | Name = vehicleEntity.Name, 13 | Make = vehicleEntity.Make 14 | }; 15 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.UseCases/UseCasesDependencyInjection.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.UseCases.Vehicles; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace CoreDrivenArchitecture.UseCases; 5 | 6 | public static class UseCasesDependencyInjection 7 | { 8 | public static IServiceCollection AddUseCases(this IServiceCollection services) 9 | => services.AddVehicleUseCases(); 10 | 11 | private static IServiceCollection AddVehicleUseCases(this IServiceCollection services) 12 | => services.AddScoped() 13 | .AddScoped() 14 | .AddScoped(); 15 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.UseCases/Vehicles/AddVehicle.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.Data.Entities; 2 | using CoreDrivenArchitecture.Data.Repositories; 3 | using CoreDrivenArchitecture.DTOs.Vehicles; 4 | using CoreDrivenArchitecture.Notificator.Events; 5 | using CoreDrivenArchitecture.UseCases.Mappers; 6 | using ROP; 7 | 8 | namespace CoreDrivenArchitecture.UseCases.Vehicles; 9 | 10 | public class AddVehicle(IDatabaseRepository databaseRepository, 11 | IEventNotificator eventNotificator) 12 | { 13 | public async Task> Execute(CreateVehicleRequest request) 14 | { 15 | VehicleEntity vehicleEntity = await databaseRepository.AddVehicle(request); 16 | var dto = vehicleEntity.ToDto(); 17 | await eventNotificator.Notify(dto); 18 | return dto; 19 | } 20 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.UseCases/Vehicles/GetVehicle.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.Data.Entities; 2 | using CoreDrivenArchitecture.Data.Repositories; 3 | using CoreDrivenArchitecture.DTOs.Vehicles; 4 | using CoreDrivenArchitecture.UseCases.Mappers; 5 | using ROP; 6 | 7 | namespace CoreDrivenArchitecture.UseCases.Vehicles; 8 | 9 | public class GetVehicle (IDatabaseRepository databaseRepository) 10 | { 11 | public async Task> Execute(int id) 12 | { 13 | VehicleEntity vehicleEntity = await databaseRepository.GetVehicle(id); 14 | 15 | return vehicleEntity.ToDto(); 16 | } 17 | } -------------------------------------------------------------------------------- /src/CoreDrivenArchitecture.UseCases/Vehicles/VehiclesUseCases.cs: -------------------------------------------------------------------------------- 1 | namespace CoreDrivenArchitecture.UseCases.Vehicles; 2 | 3 | public record class VehiclesUseCases( 4 | AddVehicle AddVehicle, 5 | GetVehicle GetVehicle); -------------------------------------------------------------------------------- /tests/CoreDrivenArchitecture.UnitTests/CoreDrivenArchitecture.UnitTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | false 9 | true 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/CoreDrivenArchitecture.UnitTests/UseCases/Vehicles/AddVehicleTests.cs: -------------------------------------------------------------------------------- 1 | using CoreDrivenArchitecture.Data.Entities; 2 | using CoreDrivenArchitecture.Data.Repositories; 3 | using CoreDrivenArchitecture.DTOs.Vehicles; 4 | using CoreDrivenArchitecture.Notificator.Events; 5 | using CoreDrivenArchitecture.UseCases.Vehicles; 6 | using Moq; 7 | 8 | namespace CoreDrivenArchitecture.UnitTests.UseCases.Vehicles; 9 | 10 | public class AddVehicleTests 11 | { 12 | private class TestState 13 | { 14 | public Mock DatabaseRepository { get; set; } 15 | public AddVehicle Subject { get; set; } 16 | public Mock EventNotificator { get; set; } 17 | 18 | public TestState() 19 | { 20 | DatabaseRepository = new Mock(); 21 | EventNotificator = new Mock(); 22 | Subject = new AddVehicle(DatabaseRepository.Object, EventNotificator.Object); 23 | } 24 | } 25 | 26 | [Fact] 27 | public async Task WhenVehicleRequestHasCorrectData_thenInserted() 28 | { 29 | TestState state = new(); 30 | string make = "opel"; 31 | string name = "vehicle1"; 32 | int id = 1; 33 | state.DatabaseRepository.Setup(x => x 34 | .AddVehicle(It.IsAny())) 35 | .ReturnsAsync(new VehicleEntity() { Id = id, Make = make, Name = name }); 36 | 37 | 38 | var result = await state.Subject 39 | .Execute(new CreateVehicleRequest() { Make = make, Name = name }); 40 | 41 | Assert.True(result.Success); 42 | Assert.Equal(make, result.Value.Make); 43 | Assert.Equal(id, result.Value.Id); 44 | Assert.Equal(name, result.Value.Name); 45 | 46 | state.EventNotificator.Verify(a => 47 | a.Notify(result.Value), Times.Once); 48 | } 49 | } --------------------------------------------------------------------------------