Browse Source

Creating module development best practices document.

pull/272/head
Halil İbrahim Kalkan 9 years ago
parent
commit
bcb8f59e40
  1. 54
      docs/Module-Development-Best-Practices.md
  2. 2
      src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

54
docs/Module-Development-Best-Practices.md

@ -0,0 +1,54 @@
## Module Development
### Introduction
This document describes the best practices for who want to develop modules that satisfies the following specifications:
* Develop the module that applies the **Domain Driven Design** patterns & best practices.
* Develop the module as DBMS and **ORM independent**.
* Develop the module that can be used as a remote service / **microservice** as well as can be integrated to a **monolithic** application.
### Data Access Layer
The module should be completely independent of any DBMS and and ORM.
- **Do not** use `IQueryable<TEntity>` features in the application code (domain, application... layers) except the data access layer.
- **Do** create separated packages (projects/assemblies/libraries) for each ORM integration (like *Company.Module.EntityFrameworkCore* and *Company.Module.MongoDB*).
- **Do** always use the specifically created repository interface (like `IIdentityUserRepository`) from the application code (as developed specified below). **Do not** use generic repository interfaces (like `IRepository<IdentityUser, Guid>`).
#### Repositories
* **Do** define a repository interface (and create its corresponding implementations) for each aggregate root.
For the example aggregate root:
````C#
public class IdentityUser : AggregateRoot<Guid>
{
//...
}
````
Define the repository interface as below:
````C#
public interface IIdentityUserRepository : IBasicRepository<IdentityUser, Guid>
{
//...
}
````
* **Do** define repository interfaces in the **domain layer**.
* **Do not** inherit the repository interface from `IRepository` interfaces. Because it inherits `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** define all repository methods as **asynchronous**.
* **Do** add a `cancellationToken` parameter to every method of the repository.
* **Do** create a **synchronous extension** method for each asynchronous repository method.
* ...
#### Integrations
##### Entity Framework Core
##### MongoDB

2
src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -12,6 +12,8 @@ using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Domain.Repositories.MongoDB namespace Volo.Abp.Domain.Repositories.MongoDB
{ {
//TODO: Use GetCancellationToken() method!
public class MongoDbRepository<TMongoDbContext, TEntity> : RepositoryBase<TEntity>, IMongoDbRepository<TEntity> public class MongoDbRepository<TMongoDbContext, TEntity> : RepositoryBase<TEntity>, IMongoDbRepository<TEntity>
where TMongoDbContext : IAbpMongoDbContext where TMongoDbContext : IAbpMongoDbContext
where TEntity : class, IEntity where TEntity : class, IEntity

Loading…
Cancel
Save