@@ -144,6 +144,14 @@ and equals and equality operators are implemented with value semantics.
144
144
Commands are DTOs (Data Transfer Objects), so they are also decorated with attributes
145
145
to allow them to be serializable with the BinarySerializer and the DataContractSerializer.
146
146
147
+ Command can be generated with base types, see ` defconventions ` for a description of
148
+ how to configure this.
149
+
150
+ Do note, however, that since Commands are contracts it is generally best to declare base
151
+ __ interfaces__ only so that the risk of breaking contracts by modifying a base is
152
+ minimal.
153
+
154
+
147
155
## Example
148
156
149
157
(defcommand ImportEmployee (int EmployeeNumber, string FirstName, string LastName, int? SourceId))
@@ -152,6 +160,27 @@ This generates a class with properties `EmployeeNumber`, `FirstName` and `LastNa
152
160
Nullable types are supported in properties with C# short syntax, i.e. "int?" denotes a nullable Int32.
153
161
154
162
163
+ ## Adding Base Classes or Interfaces to Domain Events
164
+
165
+ The code generator reads conventions from the optional ` defconventions ` declaration
166
+ at the top of the Diesel source file.
167
+
168
+ You can use this to add base types to the generated Commands.
169
+ For example, to have all Commands derive from the ` GreatApp.ICommand ` interface,
170
+ just add this declaration:
171
+
172
+ (defconventions :commands {:inherit [GreatApp.IDomainEvent]})
173
+
174
+ Note that since Commands are contracts it is generally best to
175
+ declare base __ interfaces__ only so that the risk of breaking contracts by modifying a base is
176
+ minimal.
177
+
178
+ See the section on defining conventions for a full description of ` defconventions ` .
179
+
180
+
181
+
182
+
183
+
155
184
# Defining Domain Events
156
185
157
186
(defdomainevent <typename> <properties>)
@@ -170,17 +199,23 @@ to allow them to be serializable with the BinarySerializer and the DataContractS
170
199
This generates a class with properties ` Id ` , ` EmployeeNumber ` , ` FirstName ` and ` LastName ` and ` SourceId ` .
171
200
172
201
173
- ## Adding Base Classes or Interfaces to Domain Events
202
+ ## Adding Base Classes or Interfaces to Domain Events
174
203
175
204
The code generator reads conventions from the optional ` defconventions ` declaration
176
205
at the top of the Diesel source file.
177
206
178
- You can use this to add base types to the generated Domain Events.
207
+ You can use this to add base types to the generated Domain Events.
179
208
For example, to have all Domain Events derive from the ` GreatApp.IDomainEvent ` interface,
180
209
just add this declaration:
181
210
182
211
(defconventions :domainevents {:inherit [GreatApp.IDomainEvent]})
183
212
213
+ Note that since Domain Events are contracts it is generally best to
214
+ declare base __ interfaces__ only so that the risk of breaking contracts by modifying a base is
215
+ minimal.
216
+
217
+ See the section on defining conventions for a full description of ` defconventions ` .
218
+
184
219
185
220
# Defining Data Transfer Objects (DTOs)
186
221
@@ -269,18 +304,37 @@ and `Employees.EmployeeImported`.
269
304
270
305
# Defining Conventions for Code-Generation
271
306
272
- (defconventions :domainevents {:inherit <list-of-base-types>})
307
+ (defconventions :domainevents {:inherit <list-of-base-types>}
308
+ :commands {:inherit <list-of-base-types>})
273
309
274
310
The code-generation conventions can be controlled through the ` defconventions ` declaration.
275
- It must be placed first in the source file.
276
- For now, it only controls the list of interfaces and base classes for the Domain Events.
311
+ For now, it only controls the list of interfaces and base classes for the Domain Events and Commands.
312
+
313
+ The declaration must be placed first in the source file. The ` :domainevents ` and ` :commands `
314
+ declarations inside are both optional and can be in any order, but they can not occur more than
315
+ once.
277
316
278
317
## Example
279
318
319
+ (defconventions :domainevents {:inherit [Test.Diesel.IDomainEvent]}
320
+ :commands {:inherit [Test.Diesel.ICommand]})
321
+
322
+ This causes the code generator to add the ` Test.Diesel.IDomainEvent ` interface
323
+ as a base on all Domain Events, and the ` Test.Diesel.ICommand ` interface to all Commands.
324
+
325
+
326
+ ## Example: Adding interfaces to Domain Events
327
+
280
328
(defconventions :domainevents {:inherit [Test.Diesel.IDomainEvent]})
281
329
282
330
This adds the ` Test.Diesel.IDomainEvent ` as a base on all generated Domain Events.
283
331
332
+ ## Example: Adding interfaces to Commands
333
+
334
+ (defconventions :commands {:inherit [Test.Diesel.ICommand]})
335
+
336
+ This adds the ` Test.Diesel.ICommand ` as a base on all generated Domain Events.
337
+
284
338
285
339
# Comments
286
340
0 commit comments