Mango.Nop.Libraries/docs/CONVENTIONS.md

24 lines
1.6 KiB
Markdown

# Conventions
## Naming
- **`Mg` prefix** for all custom types: `MgEntityBase`, `MgOrderDto`, `MgDbTableBase`, `MgDalBase`, etc.
- **`I` + name** for interfaces: `IMgDalBase`, `IMgDbTableBase`, `IMgOrderDto`, `IMgLockService`.
- **`Dto` suffix** for DTOs wrapping nopCommerce entities: `MgOrderDto`, `MgProductDto`, `MgOrderItemDto`.
- **`DbTable` suffix** for repository classes: `MgDbTableBase`, `MgDtoDbTableBase`.
- **`Base` suffix** for abstract base classes: `MgEntityBase`, `ModelDtoBase`, `MgBackgroundServiceBase`.
## Patterns
- **DTO bidirectional mapping** — `ModelDtoBase<TMainEntity>` provides `CopyEntityValuesToDto(entity)` and `CreateMainEntity()`. Override both in concrete DTOs.
- **NopDependencies mirror** — entity classes in `NopDependencies/` use the **same namespace** as the original nopCommerce types. Do not change namespaces.
- **GenericAttribute typed access** — use `GenericAttributeExtensions.GetValueOrDefault<T>()` / `GetValueOrNull<T>()` instead of raw string parsing.
- **Repository base chain** — `MgDbTableBase<TEntity>``EntityRepository<TEntity>` (nopCommerce). Override virtual methods, don't replace the chain.
- **Timestamp interfaces** — entities implementing `ITimeStampCreated` / `ITimeStampUpdated` get automatic timestamp management in `MgDbTableBase`.
## Project Boundaries
- `Mango.Nop.Core` — NO nopCommerce runtime dependency. Only NopDependencies mirrors.
- `Mango.Nop.Data` — depends on nopCommerce data layer (`Nop.Core`, `Nop.Data`).
- `Mango.Nop.Services` — depends on full nopCommerce stack (includes `Nop.Services`, `Nop.Web.Framework`).