generator-codedesignplus 0.1.0-beta.2 → 0.1.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/generators/microservice/core/appsettings.mjs +14 -3
  2. package/generators/microservice/core/utils.mjs +7 -7
  3. package/generators/microservice/templates/microservice/LICENSE.md +21 -0
  4. package/generators/microservice/templates/microservice/README.md +175 -0
  5. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/CodeDesignPlus.Net.Microservice.Application.csproj +4 -4
  6. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Order/Commands/AddProductToOrder/AddProductToOrderCommandHandler.cs +3 -4
  7. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Order/Commands/CancelOrder/CancelOrderCommandHandler.cs +5 -4
  8. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Order/Commands/CompleteOrder/CompleteOrderCommandHandler.cs +2 -2
  9. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Order/Commands/CreateOrder/CreateOrderCommandHandler.cs +4 -5
  10. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Order/Commands/RemoveProduct/RemoveProductCommandHandler.cs +2 -2
  11. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Order/Commands/UpdateQuantityProduct/UpdateQuantityProductCommandHandler.cs +3 -4
  12. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Order/DataTransferObjects/OrderDto.cs +4 -4
  13. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Order/Queries/FindOrderById/FindOrderByIdQueryHandler.cs +3 -6
  14. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Order/Queries/GetAllOrders/GetAllOrdersQueryHandler.cs +3 -6
  15. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Application/Usings.cs +1 -0
  16. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/CodeDesignPlus.Net.Microservice.Domain.csproj +2 -2
  17. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DataTransferObjects/AddProductToOrderParams.cs +1 -2
  18. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DataTransferObjects/CancelOrderParams.cs +2 -2
  19. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DataTransferObjects/CompleteOrderParams.cs +2 -2
  20. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DataTransferObjects/RemoveProductFromOrderParams.cs +1 -1
  21. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DataTransferObjects/UpdateQuantityProductParams.cs +1 -2
  22. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DomainEvents/OrderCancelledDomainEvent.cs +4 -4
  23. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DomainEvents/OrderCompletedDomainEvent.cs +4 -4
  24. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DomainEvents/OrderCreatedDomainEvent.cs +4 -4
  25. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DomainEvents/ProductAddedToOrderDomainEvent.cs +1 -1
  26. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DomainEvents/ProductQuantityUpdatedDomainEvent.cs +1 -1
  27. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/DomainEvents/ProductRemovedFromOrderDomainEvent.cs +1 -1
  28. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/OrderAggregate.cs +13 -15
  29. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/Repositories/IOrderRepository.cs +5 -9
  30. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Domain/Usings.cs +1 -0
  31. package/generators/microservice/templates/microservice/src/domain/CodeDesignPlus.Net.Microservice.Infrastructure/Repositories/OrderRepository.cs +29 -39
  32. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.AsyncWorker/CodeDesignPlus.Net.Microservice.AsyncWorker.csproj +8 -8
  33. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.AsyncWorker/Dockerfile +36 -0
  34. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.AsyncWorker/Program.cs +1 -1
  35. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.AsyncWorker/Properties/launchSettings.json +5 -5
  36. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.AsyncWorker/appsettings.Docker.json +25 -0
  37. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.AsyncWorker/appsettings.json +9 -45
  38. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.Rest/CodeDesignPlus.Net.Microservice.Rest.csproj +9 -8
  39. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.Rest/Dockerfile +7 -8
  40. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.Rest/Program.cs +6 -1
  41. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.Rest/Properties/launchSettings.json +3 -5
  42. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.Rest/appsettings.Docker.json +25 -0
  43. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.Rest/appsettings.json +12 -4
  44. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/CodeDesignPlus.Net.Microservice.gRpc.csproj +12 -10
  45. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/Core/Mapster/MapsterConfig.cs +10 -2
  46. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/Dockerfile +36 -0
  47. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/Program.cs +1 -3
  48. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/Properties/launchSettings.json +2 -11
  49. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/Protos/orders.proto +7 -7
  50. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/Services/OrderService.cs +1 -2
  51. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/appsettings.Docker.json +25 -0
  52. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/appsettings.json +7 -5
  53. package/generators/microservice/templates/microservice/tests/integration/CodeDesignPlus.Net.Microservice.AsyncWorker.Test/CodeDesignPlus.Net.Microservice.AsyncWorker.Test.csproj +5 -5
  54. package/generators/microservice/templates/microservice/tests/integration/CodeDesignPlus.Net.Microservice.Rest.Test/CodeDesignPlus.Net.Microservice.Rest.Test.csproj +6 -6
  55. package/generators/microservice/templates/microservice/tests/integration/CodeDesignPlus.Net.Microservice.Rest.Test/Controllers/OrderControllerTest.cs +28 -28
  56. package/generators/microservice/templates/microservice/tests/integration/CodeDesignPlus.Net.Microservice.Rest.Test/Usings.cs +1 -0
  57. package/generators/microservice/templates/microservice/tests/integration/CodeDesignPlus.Net.Microservice.gRpc.Test/CodeDesignPlus.Net.Microservice.gRpc.Test.csproj +11 -9
  58. package/generators/microservice/templates/microservice/tests/integration/CodeDesignPlus.Net.Microservice.gRpc.Test/Protos/orders.proto +8 -7
  59. package/generators/microservice/templates/microservice/tests/integration/CodeDesignPlus.Net.Microservice.gRpc.Test/Services/{OrdersServiceTest.cs → OrderServiceTest.cs} +13 -6
  60. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/CodeDesignPlus.Net.Microservice.Application.Test.csproj +4 -4
  61. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/Order/Commands/AddProductToOrder/AddProductToOrderCommandHandlerTest.cs +6 -6
  62. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/Order/Commands/CancelOrder/CancelOrderCommandHandlerTest.cs +6 -7
  63. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/Order/Commands/CompleteOrder/CompleteOrderCommandHandlerTest.cs +6 -6
  64. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/Order/Commands/CreateOrder/CreateOrderCommandHandlerTest.cs +11 -11
  65. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/Order/Commands/RemoveProduct/RemoveProductCommandHandlerTest.cs +7 -5
  66. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/Order/Commands/UpdateQuantityProduct/UpdateQuantityProductCommandHandlerTest.cs +6 -6
  67. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/Order/Queries/FindOrderById/FindOrderByIdQueryHandlerTest.cs +18 -6
  68. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/Order/Queries/GetAllOrders/GetAllOrdersQueryHandlerTest.cs +11 -7
  69. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Application.Test/Usings.cs +1 -0
  70. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.AsyncWorker.Test/CodeDesignPlus.Net.Microservice.AsyncWorker.Test.csproj +5 -5
  71. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.AsyncWorker.Test/Usings.cs +0 -1
  72. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Default.Test/CodeDesignPlus.Net.Microservice.Default.Test.csproj +6 -6
  73. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Domain.Test/CodeDesignPlus.Net.Microservice.Domain.Test.csproj +4 -4
  74. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Domain.Test/DomainEvents/OrderCancelledDomainEventTest.cs +3 -3
  75. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Domain.Test/OrderAggregateTest.cs +2 -2
  76. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Domain.Test/Usings.cs +2 -0
  77. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Infrastructure.Test/CodeDesignPlus.Net.Microservice.Infrastructure.Test.csproj +4 -4
  78. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Infrastructure.Test/Repositories/OrderRepositoryTest.cs +20 -91
  79. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Infrastructure.Test/Usings.cs +1 -0
  80. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.Rest.Test/CodeDesignPlus.Net.Microservice.Rest.Test.csproj +5 -5
  81. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.gRpc.Test/CodeDesignPlus.Net.Microservice.gRpc.Test.csproj +5 -5
  82. package/generators/microservice/templates/microservice/tests/unit/CodeDesignPlus.Net.Microservice.gRpc.Test/Services/OrderServiceTest.cs +2 -2
  83. package/generators/microservice/templates/microservice/tools/vault/config-vault.ps1 +2 -2
  84. package/generators/microservice/templates/microservice/tools/vault/config-vault.sh +1 -2
  85. package/package.json +1 -1
  86. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.AsyncWorker/appsettings.Development.json +0 -2
  87. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.Rest/CodeDesignPlus.Net.Microservice.Rest.csproj.user +0 -11
  88. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.Rest/appsettings.Development.json +0 -3
  89. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/CodeDesignPlus.Net.Microservice.gRpc.csproj.user +0 -9
  90. package/generators/microservice/templates/microservice/src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/appsettings.Development.json +0 -3
@@ -39,15 +39,16 @@ export default class AppSettingsGenerator {
39
39
  });
40
40
 
41
41
  try {
42
- this.updateConfigVault(path.join('tools', 'vault','config-vault.ps1'), options);
43
- this.updateConfigVault(path.join('tools', 'vault','config-vault.sh'), options);
42
+ this._updateConfigVault(path.join('tools', 'vault','config-vault.ps1'), options);
43
+ this._updateConfigVault(path.join('tools', 'vault','config-vault.sh'), options);
44
+ this._updateReadme(options);
44
45
  } catch (error) {
45
46
  console.log('The vault configuration could not be updated.');
46
47
  console.log(error);
47
48
  }
48
49
  }
49
50
 
50
- updateConfigVault(file, options) {
51
+ _updateConfigVault(file, options) {
51
52
  const configFile = this._generator.destinationPath(file);
52
53
 
53
54
  let config = this._generator.fs.read(configFile);
@@ -64,6 +65,16 @@ export default class AppSettingsGenerator {
64
65
  this._generator.fs.write(configFile, config);
65
66
  }
66
67
 
68
+ _updateReadme(options) {
69
+ const readmeFile = this._generator.destinationPath('README.md');
70
+
71
+ let readme = this._generator.fs.read(readmeFile);
72
+
73
+ readme = readme.replace(/\bms-archetype\b/g, options.appSettings.appName);
74
+
75
+ this._generator.fs.write(readmeFile, readme);
76
+ }
77
+
67
78
  getArguments() {
68
79
  this._generator.option('description', { type: String, alias: 'd', required: true, description: 'A detailed description of the microservice providing clear context about its purpose.' });
69
80
  this._generator.option('contact-name', { type: String, alias: 'cn', required: true, description: 'Name of the contact person responsible for the microservice.' });
@@ -49,14 +49,14 @@ export default class Utils {
49
49
 
50
50
  answers = {
51
51
  ...answers,
52
- organization: archetypeValues.organization,
53
- microservice: archetypeValues.microservice,
54
- description: archetypeValues.description,
55
- organization: archetypeValues.organization,
52
+ organization: archetypeValues?.organization ?? answers.organization,
53
+ microservice: archetypeValues?.microservice ?? answers.microservice,
54
+ description: archetypeValues?.description ?? answers.description,
55
+ organization: archetypeValues?.organization ?? answers.organization,
56
56
  aggregate: answers.aggregate ?? archetypeValues.aggregate,
57
- vault: archetypeValues.vault,
58
- contactName: archetypeValues.contactName,
59
- contactEmail: archetypeValues.contactEmail
57
+ vault: archetypeValues?.vault ?? answers.vault,
58
+ contactName: archetypeValues?.contactName ?? answers.contactName,
59
+ contactEmail: archetypeValues?.contactEmail ?? answers.contactEmail
60
60
  };
61
61
 
62
62
  const organization = this.toPascalCase(answers.organization);
@@ -0,0 +1,21 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+
3
+ Version 3, 29 June 2007
4
+
5
+ Copyright (C) 2023 CodeDesignPlus
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU Lesser General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+
19
+ As an additional permission under GNU LGPL version 3 section 7, you may distribute
20
+ non-source (e.g., minimized or compacted) forms of that code without the copy of the GNU LGPL,
21
+ but you must make the corresponding source code available under the GNU LGPL as provided above.
@@ -0,0 +1,175 @@
1
+ # CodeDesignPlus .NET 9 Microservice Template
2
+
3
+ A production-ready microservice template built with .NET 9, implementing Clean Architecture, DDD, and CQRS patterns. This template provides a robust foundation for building scalable and maintainable microservices.
4
+
5
+ ## 🚀 Key Features
6
+
7
+ - Clean Architecture implementation
8
+ - Domain-Driven Design (DDD) principles
9
+ - Command Query Responsibility Segregation (CQRS)
10
+ - Multiple entry points (REST API, gRPC, Worker)
11
+ - Distributed caching with Redis
12
+ - Message broker integration with RabbitMQ
13
+ - MongoDB database integration
14
+ - OAuth2/OpenID Connect security
15
+ - Swagger API documentation
16
+ - Application monitoring and tracing
17
+ - Docker containerization
18
+ - Unit and integration testing
19
+ - Load testing scripts
20
+
21
+ ## 🛠️ Technology Stack
22
+
23
+ - .NET 9
24
+ - MongoDB
25
+ - Redis
26
+ - RabbitMQ
27
+ - Vault
28
+ - Swagger/OpenAPI
29
+ - gRPC
30
+ - MediatR
31
+ - FluentValidation
32
+ - Mapster
33
+ - Docker
34
+
35
+ ## ⚙️ Prerequisites
36
+
37
+ - .NET 9 SDK
38
+ - Docker and Docker Compose
39
+ - MongoDB
40
+ - Redis
41
+ - RabbitMQ
42
+ - Vault (optional)
43
+
44
+ ## 🚀 Getting Started
45
+
46
+ The following instructions will help you set up the project on your local machine for development and testing purposes.
47
+
48
+ 1. Clone the repository:
49
+ ```bash
50
+ git clone <repository-url>
51
+ ```
52
+
53
+ 2. Run the MongoDB, Redis, and RabbitMQ services using Docker Compose. Clone this repository [CodeDesignPlus.Environment.Dev](https://github.com/codedesignplus/CodeDesignPlus.Environment.Dev) and run the following command:
54
+
55
+ ```bash
56
+ cd resources
57
+
58
+ docker-compose up -d
59
+ ```
60
+
61
+ 3. Run the script to config the vault:
62
+
63
+ ```bash
64
+ cd tools/vault
65
+
66
+ ./config-vault.sh
67
+ ```
68
+
69
+ 4. Build the solution:
70
+ ```bash
71
+ dotnet build
72
+ ```
73
+
74
+ 5. Run the desired entry point:
75
+
76
+ - For REST API:
77
+ ```bash
78
+ dotnet run --project src/entrypoints/CodeDesignPlus.Net.Microservice.Rest
79
+ ```
80
+
81
+ - For gRPC:
82
+ ```bash
83
+ dotnet run --project src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc
84
+ ```
85
+
86
+ - For Worker:
87
+ ```bash
88
+ dotnet run --project src/entrypoints/CodeDesignPlus.Net.Microservice.AsyncWorker
89
+ ```
90
+
91
+ ## 🧪 Testing
92
+ To run the unit and integration tests, execute the following command:
93
+
94
+ ```bash
95
+ dotnet test
96
+ ```
97
+
98
+ ## 📦 Update Packages
99
+ To update the NuGet packages, run the following script:
100
+
101
+ ```bash
102
+ cd tools/update-packages
103
+
104
+ ./update-packages.sh
105
+ ```
106
+
107
+ ## 📦 Upgrading .NET Version
108
+
109
+ To upgrade the .NET version, run the following script:
110
+
111
+ ```bash
112
+ cd tools/upgrade-dotnet
113
+
114
+ ./upgrade-dotnet.sh
115
+ ```
116
+
117
+ ## 🧪 SonarQube Analysis
118
+
119
+ To run the SonarQube analysis, follow the instructions in the sonarqube directory.
120
+
121
+ 1. Replace the SonarQube URL and token in the sonarqube.sh script to analyze with SonarQube locally.
122
+ 2. Run the script:
123
+
124
+ ```bash
125
+ cd tools/sonarqube
126
+
127
+ ./sonarqube.sh
128
+ ```
129
+
130
+ 🐳 Docker Support
131
+
132
+ To build and run the application using Docker, follow these steps:
133
+
134
+ 1. Build the Docker image using the Dockerfile in the REST API entry point:
135
+ ```bash
136
+ docker build -t ms-archetype-rest . -f src/entrypoints/CodeDesignPlus.Net.Microservice.Rest/Dockerfile
137
+
138
+ docker run -d -p 5000:5000 --network=backend -e ASPNETCORE_ENVIRONMENT=Docker --name ms-archetype-rest ms-archetype-rest
139
+ ```
140
+
141
+ 2. Build the Docker image using the Dockerfile in the gRPC entry point:
142
+ ```bash
143
+ docker build -t ms-archetype-grpc . -f src/entrypoints/CodeDesignPlus.Net.Microservice.gRpc/Dockerfile
144
+
145
+ docker run -d -p 5001:5001 --network=backend -e ASPNETCORE_ENVIRONMENT=Docker --name ms-archetype-grpc ms-archetype-grpc
146
+ ```
147
+
148
+ 3. Build the Docker image using the Dockerfile in the Worker entry point:
149
+ ```bash
150
+ docker build -t ms-archetype-worker . -f src/entrypoints/CodeDesignPlus.Net.Microservice.AsyncWorker/Dockerfile
151
+
152
+ docker run -d -p 5002:5002 --network=backend -e ASPNETCORE_ENVIRONMENT=Docker --name ms-archetype-worker ms-archetype-worker
153
+ ```
154
+
155
+ ## 📚 Documentation
156
+ 1. API documentation available at `/swagger`
157
+ 2. gRPC service definitions in Protos or `MapGrpcReflectionService` for reflection
158
+
159
+ ## 🤝 Contributing
160
+ Please read our Contributing Guide for details on our code of conduct and development process.
161
+
162
+ ## 📄 License
163
+ This project is licensed under the GNU Lesser General Public License v3.0 - see the LICENSE.md file for details.
164
+
165
+ ## 🔧 Tools
166
+ The repository includes several utility scripts in the tools directory:
167
+
168
+ - `convert-crlf-to-lf.sh`: Converts line endings
169
+ - `update-packages/`: Updates NuGet packages
170
+ - `upgrade-dotnet/`: Upgrades .NET version
171
+ - `vault/`: Vault configuration scripts
172
+ - `sonarqube/`: SonarQube analysis configuration
173
+
174
+ ## 📦 CodeDesignPlus Packages
175
+ This template use the `CodeDesignPlus.Net.Sdk` package to simplify the development process. For more information, visit the [Doc Site](https://codedesignplus.github.io/).
@@ -5,10 +5,10 @@
5
5
  <Nullable>enable</Nullable>
6
6
  </PropertyGroup>
7
7
  <ItemGroup>
8
- <PackageReference Include="CodeDesignPlus.Net.Generator" Version="0.5.0-beta.60" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
9
- <PackageReference Include="CodeDesignPlus.Net.Redis.Abstractions" Version="0.5.0-beta.60" />
10
- <PackageReference Include="CodeDesignPlus.Net.PubSub.Abstractions" Version="0.5.0-beta.60" />
11
- <PackageReference Include="CodeDesignPlus.Net.Cache.Abstractions" Version="0.5.0-beta.60" />
8
+ <PackageReference Include="CodeDesignPlus.Net.Generator" Version="0.5.0-beta.81" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
9
+ <PackageReference Include="CodeDesignPlus.Net.Redis.Abstractions" Version="0.5.0-beta.81" />
10
+ <PackageReference Include="CodeDesignPlus.Net.PubSub.Abstractions" Version="0.5.0-beta.81" />
11
+ <PackageReference Include="CodeDesignPlus.Net.Cache.Abstractions" Version="0.5.0-beta.81" />
12
12
  <PackageReference Include="Mapster" Version="7.4.0" />
13
13
  <PackageReference Include="Mapster.DependencyInjection" Version="1.0.1" />
14
14
  <PackageReference Include="MediatR" Version="12.4.1" />
@@ -4,16 +4,15 @@ public class AddProductToOrderCommandHandler(IOrderRepository orderRepository, I
4
4
  {
5
5
  public async Task Handle(AddProductToOrderCommand request, CancellationToken cancellationToken)
6
6
  {
7
- var order = await orderRepository.FindAsync(request.Id, cancellationToken);
7
+ var order = await orderRepository.FindAsync<OrderAggregate>(request.Id, user.Tenant, cancellationToken);
8
8
 
9
9
  ApplicationGuard.IsNull(order, Errors.OrderNotFound);
10
10
 
11
11
  order.AddProduct(request.IdProduct, request.Name, request.Description, request.Price, request.Quantity, user.IdUser);
12
12
 
13
- await orderRepository.AddProductToOrderAsync(new AddProductToOrderParams()
13
+ await orderRepository.AddProductToOrderAsync(order.Id, user.Tenant, new AddProductToOrderParams()
14
14
  {
15
- Id = order.Id,
16
- IdProduct = request.IdProduct,
15
+ Id = request.IdProduct,
17
16
  Name = request.Name,
18
17
  Description = request.Description,
19
18
  Price = request.Price,
@@ -4,20 +4,21 @@ public class CancelOrderCommandHandler(IOrderRepository orderRepository, IUserCo
4
4
  {
5
5
  public async Task Handle(CancelOrderCommand request, CancellationToken cancellationToken)
6
6
  {
7
- var order = await orderRepository.FindAsync(request.Id, cancellationToken);
7
+ var order = await orderRepository.FindAsync<OrderAggregate>(request.Id, user.Tenant, cancellationToken);
8
8
 
9
9
  ApplicationGuard.IsNull(order, Errors.OrderNotFound);
10
10
 
11
11
  order.CancelOrder(request.Reason, user.IdUser);
12
-
13
- await orderRepository.CancelOrderAsync(new CancelOrderParams() {
12
+
13
+ await orderRepository.CancelOrderAsync(new CancelOrderParams()
14
+ {
14
15
  Id = order.Id,
15
16
  OrderStatus = order.Status,
16
17
  Reason = order.ReasonForCancellation,
17
18
  CancelledAt = order.CancelledAt,
18
19
  UpdatedAt = order.UpdatedAt,
19
20
  UpdateBy = order.UpdatedBy
20
- },cancellationToken);
21
+ }, user.Tenant, cancellationToken);
21
22
 
22
23
  await pubsub.PublishAsync(order.GetAndClearEvents(), cancellationToken);
23
24
  }
@@ -4,7 +4,7 @@ public class CompleteOrderCommandHandler(IOrderRepository orderRepository, IUser
4
4
  {
5
5
  public async Task Handle(CompleteOrderCommand request, CancellationToken cancellationToken)
6
6
  {
7
- var order = await orderRepository.FindAsync(request.Id, cancellationToken);
7
+ var order = await orderRepository.FindAsync<OrderAggregate>(request.Id, user.Tenant, cancellationToken);
8
8
 
9
9
  ApplicationGuard.IsNull(order, Errors.OrderNotFound);
10
10
 
@@ -17,7 +17,7 @@ public class CompleteOrderCommandHandler(IOrderRepository orderRepository, IUser
17
17
  OrderStatus = order.Status,
18
18
  UpdatedAt = order.UpdatedAt,
19
19
  UpdateBy = order.UpdatedBy
20
- }, cancellationToken);
20
+ }, user.Tenant, cancellationToken);
21
21
 
22
22
  await pubsub.PublishAsync(order.GetAndClearEvents(), cancellationToken);
23
23
  }
@@ -6,18 +6,17 @@ public class CreateOrderCommandHandler(IOrderRepository orderRepository, IUserCo
6
6
  {
7
7
  public async Task Handle(CreateOrderCommand request, CancellationToken cancellationToken)
8
8
  {
9
- var order = await orderRepository.FindAsync(request.Id, cancellationToken);
10
-
11
- ApplicationGuard.IsNotNull(order, Errors.OrderAlreadyExists);
9
+ var exist = await orderRepository.ExistsAsync<OrderAggregate>(request.Id, user.Tenant, cancellationToken);
12
10
 
11
+ ApplicationGuard.IsTrue(exist, Errors.OrderAlreadyExists);
13
12
 
14
13
  var client = ClientValueObject.Create(request.Client.Id, request.Client.Name, request.Client.Document, request.Client.TypeDocument);
15
14
 
16
15
  var address = AddressValueObject.Create(request.Address.Country, request.Address.State, request.Address.City, request.Address.Address, request.Address.CodePostal);
17
16
 
18
- order = OrderAggregate.Create(request.Id, client, address, user.Tenant, user.IdUser);
17
+ var order = OrderAggregate.Create(request.Id, client, address, user.Tenant, user.IdUser);
19
18
 
20
- await orderRepository.CreateOrderAsync(order, cancellationToken);
19
+ await orderRepository.CreateAsync(order, cancellationToken);
21
20
 
22
21
  await pubsub.PublishAsync(order.GetAndClearEvents(), cancellationToken);
23
22
  }
@@ -4,7 +4,7 @@ public class RemoveProductCommandHandler(IOrderRepository orderRepository, IUser
4
4
  {
5
5
  public async Task Handle(RemoveProductCommand request, CancellationToken cancellationToken)
6
6
  {
7
- var order = await orderRepository.FindAsync(request.Id, cancellationToken);
7
+ var order = await orderRepository.FindAsync<OrderAggregate>(request.Id, user.Tenant, cancellationToken);
8
8
 
9
9
  ApplicationGuard.IsNull(order, Errors.OrderNotFound);
10
10
 
@@ -15,7 +15,7 @@ public class RemoveProductCommandHandler(IOrderRepository orderRepository, IUser
15
15
  IdProduct = request.ProductId,
16
16
  UpdatedAt = order.UpdatedAt,
17
17
  UpdateBy = user.IdUser
18
- }, cancellationToken);
18
+ }, user.Tenant, cancellationToken);
19
19
 
20
20
  await pubsub.PublishAsync(order.GetAndClearEvents(), cancellationToken);
21
21
  }
@@ -4,16 +4,15 @@ public class UpdateQuantityProductCommandHandler(IOrderRepository orderRepositor
4
4
  {
5
5
  public async Task Handle(UpdateQuantityProductCommand request, CancellationToken cancellationToken)
6
6
  {
7
- var order = await orderRepository.FindAsync(request.Id, cancellationToken);
7
+ var order = await orderRepository.FindAsync<OrderAggregate>(request.Id, user.Tenant, cancellationToken);
8
8
 
9
9
  ApplicationGuard.IsNull(order, Errors.OrderNotFound);
10
10
 
11
11
  order.UpdateProductQuantity(request.ProductId, request.Quantity, user.IdUser);
12
12
 
13
- await orderRepository.UpdateQuantityProductAsync(new UpdateQuantityProductParams()
13
+ await orderRepository.UpdateQuantityProductAsync(order.Id, user.Tenant, new UpdateQuantityProductParams()
14
14
  {
15
- Id = order.Id,
16
- ProductId = request.ProductId,
15
+ Id = request.ProductId,
17
16
  NewQuantity = request.Quantity,
18
17
  UpdatedAt = order.UpdatedAt,
19
18
  UpdateBy = user.IdUser
@@ -3,16 +3,16 @@
3
3
  public class OrderDto: IDtoBase
4
4
  {
5
5
  public Guid Id { get; set; }
6
- public long? CompletedAt { get; set; }
7
- public long? CancelledAt { get; set; }
6
+ public Instant? CompletedAt { get; set; }
7
+ public Instant? CancelledAt { get; set; }
8
8
  public ClientDto Client { get; set; } = default!;
9
9
  public AddressDto ShippingAddress { get; set; } = default!;
10
10
  public List<ProductDto> Products { get; set; } = [];
11
11
  public OrderStatus Status { get; set; }
12
12
  public string? ReasonForCancellation { get; set; }
13
- public long CreatedAt { get; set; }
13
+ public Instant CreatedAt { get; set; }
14
14
  public Guid CreatedBy { get; set; }
15
- public long UpdatedAt { get; set; }
15
+ public Instant? UpdatedAt { get; set; }
16
16
  public Guid UpdatedBy { get; set; }
17
17
  public bool IsActive { get; set; }
18
18
  }
@@ -2,19 +2,16 @@
2
2
 
3
3
  namespace CodeDesignPlus.Net.Microservice.Application.Order.Queries.FindOrderById;
4
4
 
5
- public class FindOrderByIdQueryHandler(IOrderRepository orderRepository, IMapper mapper, ICacheManager cacheManager) : IRequestHandler<FindOrderByIdQuery, OrderDto>
5
+ public class FindOrderByIdQueryHandler(IOrderRepository orderRepository, IMapper mapper, ICacheManager cacheManager, IUserContext user) : IRequestHandler<FindOrderByIdQuery, OrderDto>
6
6
  {
7
- private readonly IOrderRepository orderRepository = orderRepository;
8
- private readonly IMapper mapper = mapper;
9
-
10
7
  public async Task<OrderDto> Handle(FindOrderByIdQuery request, CancellationToken cancellationToken)
11
8
  {
12
9
  if(await cacheManager.ExistsAsync(request.Id.ToString()))
13
10
  return await cacheManager.GetAsync<OrderDto>(request.Id.ToString());
14
11
 
15
- var result = await this.orderRepository.FindAsync(request.Id, cancellationToken);
12
+ var result = await orderRepository.FindAsync<OrderAggregate>(request.Id, user.Tenant, cancellationToken);
16
13
 
17
- var order = this.mapper.Map<OrderDto>(result);
14
+ var order = mapper.Map<OrderDto>(result);
18
15
 
19
16
  await cacheManager.SetAsync(request.Id.ToString(), order);
20
17
 
@@ -1,17 +1,14 @@
1
1
  namespace CodeDesignPlus.Net.Microservice.Application.Order.Queries.GetAllOrders;
2
2
 
3
- public class GetAllOrdersQueryHandler(IOrderRepository orderRepository, IMapper mapper)
3
+ public class GetAllOrdersQueryHandler(IOrderRepository orderRepository, IMapper mapper, IUserContext user)
4
4
  : IRequestHandler<GetAllOrdersQuery, List<OrderDto>>
5
5
  {
6
6
 
7
- private readonly IOrderRepository orderRepository = orderRepository;
8
- private readonly IMapper mapper = mapper;
9
-
10
7
  public async Task<List<OrderDto>> Handle(GetAllOrdersQuery request, CancellationToken cancellationToken)
11
8
  {
12
- var result = await this.orderRepository.MatchingAsync<OrderAggregate>(request.Criteria, cancellationToken).ConfigureAwait(false);
9
+ var result = await orderRepository.MatchingAsync<OrderAggregate>(request.Criteria, user.Tenant, cancellationToken);
13
10
 
14
- var data = this.mapper.Map<List<OrderDto>>(result);
11
+ var data = mapper.Map<List<OrderDto>>(result);
15
12
 
16
13
  return data;
17
14
  }
@@ -9,6 +9,7 @@ global using MediatR;
9
9
  global using C = CodeDesignPlus.Net.Core.Abstractions.Models.Criteria;
10
10
  global using CodeDesignPlus.Net.Core.Abstractions;
11
11
  global using CodeDesignPlus.Net.Serializers;
12
+ global using NodaTime;
12
13
 
13
14
  global using CodeDesignPlus.Net.Microservice.Application.Order.DataTransferObjects;
14
15
  global using CodeDesignPlus.Net.Microservice.Domain;
@@ -5,7 +5,7 @@
5
5
  <Nullable>enable</Nullable>
6
6
  </PropertyGroup>
7
7
  <ItemGroup>
8
- <PackageReference Include="CodeDesignPlus.Net.Exceptions" Version="0.5.0-beta.60" />
9
- <PackageReference Include="CodeDesignPlus.Net.Mongo" Version="0.5.0-beta.60" />
8
+ <PackageReference Include="CodeDesignPlus.Net.Exceptions" Version="0.5.0-beta.81" />
9
+ <PackageReference Include="CodeDesignPlus.Net.Mongo" Version="0.5.0-beta.81" />
10
10
  </ItemGroup>
11
11
  </Project>
@@ -5,11 +5,10 @@ namespace CodeDesignPlus.Net.Microservice.Domain.DataTransferObjects;
5
5
  public class AddProductToOrderParams: IDtoBase
6
6
  {
7
7
  public required Guid Id { get; set; }
8
- public required Guid IdProduct { get; set; }
9
8
  public required string Name { get; set; }
10
9
  public required string Description { get; set; }
11
10
  public required long Price { get; set; }
12
11
  public required int Quantity { get; set; }
13
- public required long? UpdatedAt { get; set; }
12
+ public required Instant? UpdatedAt { get; set; }
14
13
  public required Guid? UpdateBy { get; set; }
15
14
  }
@@ -7,7 +7,7 @@ public class CancelOrderParams: IDtoBase
7
7
  public required Guid Id { get; set; }
8
8
  public required OrderStatus OrderStatus { get; set; }
9
9
  public required string? Reason { get; set; }
10
- public required long? CancelledAt { get; set; }
11
- public required long? UpdatedAt { get; set; }
10
+ public required Instant? CancelledAt { get; set; }
11
+ public required Instant? UpdatedAt { get; set; }
12
12
  public required Guid? UpdateBy { get; set; }
13
13
  }
@@ -5,8 +5,8 @@ namespace CodeDesignPlus.Net.Microservice.Domain.DataTransferObjects;
5
5
  public class CompleteOrderParams: IDtoBase
6
6
  {
7
7
  public required Guid Id { get; set; }
8
- public required long? CompletedAt { get; set; }
8
+ public required Instant? CompletedAt { get; set; }
9
9
  public required OrderStatus OrderStatus { get; set; }
10
- public required long? UpdatedAt { get; set; }
10
+ public required Instant? UpdatedAt { get; set; }
11
11
  public required Guid? UpdateBy { get; set; }
12
12
  }
@@ -6,6 +6,6 @@ public class RemoveProductFromOrderParams: IDtoBase
6
6
  {
7
7
  public required Guid Id { get; set; }
8
8
  public required Guid IdProduct { get; set; }
9
- public required long? UpdatedAt { get; set; }
9
+ public required Instant? UpdatedAt { get; set; }
10
10
  public required Guid? UpdateBy { get; set; }
11
11
  }
@@ -5,8 +5,7 @@ namespace CodeDesignPlus.Net.Microservice.Domain.DataTransferObjects;
5
5
  public class UpdateQuantityProductParams: IDtoBase
6
6
  {
7
7
  public required Guid Id { get; set; }
8
- public required Guid ProductId { get; set; }
9
8
  public required int NewQuantity { get; set; }
10
- public required long? UpdatedAt { get; set; }
9
+ public required Instant? UpdatedAt { get; set; }
11
10
  public required Guid? UpdateBy { get; set; }
12
11
  }
@@ -3,19 +3,19 @@
3
3
  [EventKey<OrderAggregate>(1, "OrderCancelled")]
4
4
  public class OrderCancelledDomainEvent(
5
5
  Guid aggregateId,
6
- long cancelledAt,
6
+ Instant cancelledAt,
7
7
  string reason,
8
8
  Guid? eventId = null,
9
- DateTime? occurredAt = null,
9
+ Instant? occurredAt = null,
10
10
  Dictionary<string, object>? metadata = null
11
11
  ) : DomainEvent(aggregateId, eventId, occurredAt, metadata)
12
12
  {
13
- public long CancelledAt { get; } = cancelledAt;
13
+ public Instant CancelledAt { get; } = cancelledAt;
14
14
  public string Reason { get; } = reason;
15
15
 
16
16
  public static OrderCancelledDomainEvent Create(Guid aggregateId, string reason)
17
17
  {
18
- return new OrderCancelledDomainEvent(aggregateId, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), reason);
18
+ return new OrderCancelledDomainEvent(aggregateId, SystemClock.Instance.GetCurrentInstant(), reason);
19
19
  }
20
20
  }
21
21
 
@@ -3,16 +3,16 @@
3
3
  [EventKey<OrderAggregate>(1, "OrderCompleted")]
4
4
  public class OrderCompletedDomainEvent(
5
5
  Guid aggregateId,
6
- long completedAt,
6
+ Instant completedAt,
7
7
  Guid? eventId = null,
8
- DateTime? occurredAt = null,
8
+ Instant? occurredAt = null,
9
9
  Dictionary<string, object>? metadata = null
10
10
  ) : DomainEvent(aggregateId, eventId, occurredAt, metadata)
11
11
  {
12
- public long CompletedAt { get; } = completedAt;
12
+ public Instant CompletedAt { get; } = completedAt;
13
13
 
14
14
  public static OrderCompletedDomainEvent Create(Guid aggregateId)
15
15
  {
16
- return new OrderCompletedDomainEvent(aggregateId, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
16
+ return new OrderCompletedDomainEvent(aggregateId, SystemClock.Instance.GetCurrentInstant());
17
17
  }
18
18
  }
@@ -8,18 +8,18 @@ public class OrderCreatedDomainEvent(
8
8
  OrderStatus orderStatus,
9
9
  ClientValueObject client,
10
10
  AddressValueObject shippingAddress,
11
- long createdAt,
11
+ Instant createdAt,
12
12
  Guid tenant,
13
13
  Guid createBy,
14
14
  Guid? eventId = null,
15
- DateTime? occurredAt = null,
15
+ Instant? occurredAt = null,
16
16
  Dictionary<string, object>? metadata = null
17
17
  ) : DomainEvent(aggregateId, eventId, occurredAt, metadata)
18
18
  {
19
19
  public ClientValueObject Client { get; } = client;
20
20
  public AddressValueObject ShippingAddress { get; } = shippingAddress;
21
21
  public OrderStatus OrderStatus { get; } = orderStatus;
22
- public long CreatedAt { get; } = createdAt;
22
+ public Instant CreatedAt { get; } = createdAt;
23
23
  public Guid Tenant { get; private set; } = tenant;
24
24
  public Guid CreateBy { get; private set; } = createBy;
25
25
 
@@ -35,7 +35,7 @@ public class OrderCreatedDomainEvent(
35
35
  OrderStatus.Created,
36
36
  client,
37
37
  shippingAddress,
38
- DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
38
+ SystemClock.Instance.GetCurrentInstant(),
39
39
  tenant,
40
40
  creaateBy
41
41
  );
@@ -6,7 +6,7 @@ public class ProductAddedToOrderDomainEvent(
6
6
  int quantity,
7
7
  ProductEntity product,
8
8
  Guid? eventId = null,
9
- DateTime? occurredAt = null,
9
+ Instant? occurredAt = null,
10
10
  Dictionary<string, object>? metadata = null
11
11
  ) : DomainEvent(aggregateId, eventId, occurredAt, metadata)
12
12
  {
@@ -6,7 +6,7 @@ public class ProductQuantityUpdatedDomainEvent(
6
6
  Guid productId,
7
7
  int newQuantity,
8
8
  Guid? eventId = null,
9
- DateTime? occurredAt = null,
9
+ Instant? occurredAt = null,
10
10
  Dictionary<string, object>? metadata = null
11
11
  ) : DomainEvent(aggregateId, eventId, occurredAt, metadata)
12
12
  {