@ -17,7 +17,7 @@ public class IdentityUser : AggregateRoot<Guid>
}
````
Define the repository interface as below:
定义仓储接口, 如下所示:
````C#
public interface IIdentityUserRepository : IBasicRepository<IdentityUser,Guid>
@ -26,14 +26,14 @@ public interface IIdentityUserRepository : IBasicRepository<IdentityUser, Guid>
}
````
* **Do not** inherit the repository interface from the `IRepository<TEntity, TKey>` interface. Because it inherits the `IQueryable` and the repository should not expose `IQueryable` to the application.
* **Do** inherit the repository interface from `IBasicRepository<TEntity, TKey>` (as normally) or a lower-featured interface, like `IReadOnlyRepository<TEntity, TKey>` (if it's needed).
* **Do not** define repositories for entities those are **not aggregate roots**.
* **Do** create a **synchronous extension** method for each asynchronous repository method. Example:
* **推荐** 为仓储的每个异步方法创建一个 **同步扩展** 方法. 示例:
````C#
public static class IdentityUserRepositoryExtensions
@ -58,9 +58,9 @@ public static class IdentityUserRepositoryExtensions
}
````
This will allow synchronous code to use the repository methods easier.
对于同步方法而言, 这会让它们更方便的调用仓储方法.
* **Do** add an optional `bool includeDetails = true` parameter (default value is `true`) for every repository method which returns a **single entity**. Example:
This parameter will be implemented for ORMs to eager load sub collections of the entity.
该参数由ORM实现, 用来加载实体子集合.
* **Do** add an optional `bool includeDetails = false` parameter (default value is `false`) for every repository method which returns a **list of entities**. Example:
* **Do not** create composite classes to combine entities to get from repository with a single method call. Examples: *UserWithRoles*, *UserWithTokens*, *UserWithRolesAndTokens*. Instead, properly use `includeDetails` option to add all details of the entity when needed.
* **Avoid** to create projection classes for entities to get less property of an entity from the repository. Example: Avoid to create BasicUserView class to select a few properties needed for the use case needs. Instead, directly use the aggregate root class. However, there may be some exceptions for this rule, where:
* Performance is so critical for the use case and getting the whole aggregate root highly impacts the performance.