Browse Source

Add best practice for DTOs of modules.

pull/640/head
Halil ibrahim Kalkan 8 years ago
parent
commit
5e460dfe65
  1. 6
      docs/en/Best-Practices/Application-Services.md
  2. 3
      docs/en/Best-Practices/Data-Transfer-Objects.md

6
docs/en/Best-Practices/Application-Services.md

@ -26,6 +26,7 @@
Example: Example:
```c# ```c#
[Serializable]
public class IssueDto : FullAuditedEntityDto<Guid> public class IssueDto : FullAuditedEntityDto<Guid>
{ {
public string Title { get; set; } public string Title { get; set; }
@ -34,6 +35,7 @@ public class IssueDto : FullAuditedEntityDto<Guid>
public Collection<IssueLabelDto> Labels { get; set; } public Collection<IssueLabelDto> Labels { get; set; }
} }
[Serializable]
public class IssueLabelDto public class IssueLabelDto
{ {
public Guid IssueId { get; set; } public Guid IssueId { get; set; }
@ -54,6 +56,7 @@ public class IssueLabelDto
Example: Example:
````C# ````C#
[Serializable]
public class IssueWithDetailsDto : FullAuditedEntityDto<Guid> public class IssueWithDetailsDto : FullAuditedEntityDto<Guid>
{ {
public string Title { get; set; } public string Title { get; set; }
@ -62,12 +65,14 @@ public class IssueWithDetailsDto : FullAuditedEntityDto<Guid>
public Collection<LabelDto> Labels { get; set; } public Collection<LabelDto> Labels { get; set; }
} }
[Serializable]
public class MilestoneDto : EntityDto<Guid> public class MilestoneDto : EntityDto<Guid>
{ {
public string Name { get; set; } public string Name { get; set; }
public bool IsClosed { get; set; } public bool IsClosed { get; set; }
} }
[Serializable]
public class LabelDto : EntityDto<Guid> public class LabelDto : EntityDto<Guid>
{ {
public string Name { get; set; } public string Name { get; set; }
@ -129,6 +134,7 @@ Task<QuestionWithDetailsDto> CreateAsync(CreateQuestionDto questionDto);
The related **DTO**: The related **DTO**:
````C# ````C#
[Serializable]
public class CreateQuestionDto public class CreateQuestionDto
{ {
[Required] [Required]

3
docs/en/Best-Practices/Data-Transfer-Objects.md

@ -4,4 +4,5 @@
* **Do** inherit from the pre-built **base DTO classes** where possible and necessary (like `EntityDto<TKey>`, `CreationAuditedEntityDto<TKey>`, `AuditedEntityDto<TKey>`, `FullAuditedEntityDto<TKey>` and so on). * **Do** inherit from the pre-built **base DTO classes** where possible and necessary (like `EntityDto<TKey>`, `CreationAuditedEntityDto<TKey>`, `AuditedEntityDto<TKey>`, `FullAuditedEntityDto<TKey>` and so on).
* **Do** define DTO members with **public getter and setter**. * **Do** define DTO members with **public getter and setter**.
* **Do** use **data annotations** for **validation** on the properties of DTOs those are inputs of the service. * **Do** use **data annotations** for **validation** on the properties of DTOs those are inputs of the service.
* **Do** not add any **logic** into DTOs except implementing `IValidatableObject` when necessary. * **Do** not add any **logic** into DTOs except implementing `IValidatableObject` when necessary.
* **Do** mark all DTOs as **[Serializable]** since they are already serializable and developers may want to binary serialize them.
Loading…
Cancel
Save