Browse Source

Created initial mongodb integration doc

pull/279/head
Halil İbrahim Kalkan 8 years ago
parent
commit
8b7a11361c
  1. 12
      docs/Entity-Framework-Core.md
  2. 2
      docs/Index.md
  3. 99
      docs/MongoDB.md

12
docs/Entity-Framework-Core.md

@ -1,10 +1,10 @@
## Entity Framework Core Integration ## Entity Framework Core Integration
This document explains how to integrate EF Core as ORM provider to ABP based applications and how to configure it in details. This document explains how to integrate EF Core as an ORM provider to ABP based applications and how to configure it.
### Installation ### Installation
`Volo.Abp.EntityFrameworkCore` is the main nuget package for EF Core integration. Install it to your project (for a layered application, to your data/infrastructure layer): `Volo.Abp.EntityFrameworkCore` is the main nuget package for the EF Core integration. Install it to your project (for a layered application, to your data/infrastructure layer):
```` ````
Install-Package Volo.Abp.EntityFrameworkCore Install-Package Volo.Abp.EntityFrameworkCore
@ -92,18 +92,12 @@ services.AddAbpDbContext<MyDbContext>(options =>
}); });
```` ````
Then you can inject and use `IRepository<TEntity>` or `IQueryableRepository<TEntity>` in your services (see repository documentation - TODO). Then you can inject and use `IRepository<TEntity>` or `IQueryableRepository<TEntity>` in your services.
TODO: Example
#### Add Custom Repositories #### Add Custom Repositories
TODO... TODO...
### Best Practices
See [best practices](Best-Practices/) for EF Core integration.
#### Set Base DbContext Class or Interface for Default Repositories #### Set Base DbContext Class or Interface for Default Repositories
... ...

2
docs/Index.md

@ -29,4 +29,4 @@
* Unit Of Work * Unit Of Work
* Data Access * Data Access
* [Entity Framework Core Integration](Entity-Framework-Core.md) * [Entity Framework Core Integration](Entity-Framework-Core.md)
* MongoDB Integration * [MongoDB Integration](MongoDB.md)

99
docs/MongoDB.md

@ -0,0 +1,99 @@
## MongoDB Integration
This document explains how to integrate MongoDB as a database provider to ABP based applications and how to configure it.
### Installation
`Volo.Abp.MongoDB` is the main nuget package for the MongoDB integration. Install it to your project (for a layered application, to your data/infrastructure layer):
```
Install-Package Volo.Abp.MongoDB
```
Then add `AbpMongoDbModule` module dependency to your [module](Module-Development-Basics.md):
```c#
using Volo.Abp.MongoDB;
using Volo.Abp.Modularity;
namespace MyCompany.MyProject
{
[DependsOn(typeof(AbpMongoDbModule))]
public class MyModule : AbpModule
{
//...
}
}
```
### Creating a Mongo Db Context
ABP introduces **Mongo Db Context** concept (which is similar to Entity Framework Core's DbContext) to make it easier to use collections and configure them. An example is shown below:
```c#
public class MyDbContext : AbpMongoDbContext
{
public IMongoCollection<Question> Questions => Collection<Question>();
public IMongoCollection<Category> Categories => Collection<Category>();
protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
modelBuilder.Entity<Question>(b =>
{
b.CollectionName = "Questions";
});
}
}
```
* It's derived from `AbpMongoDbContext` class.
* Adds a public `IMongoCollection<TEntity>` property for each mongo collection. ABP uses these properties to create default repositories by default.
* Overriding `CreateModel` method allows to configure collections (like their collection name in the database).
### Registering DbContext To Dependency Injection
Use `AddAbpDbContext` method in your module to register your DbContext class for [dependency injection](Dependency-Injection.md) system.
```c#
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.MongoDB;
using Volo.Abp.Modularity;
namespace MyCompany.MyProject
{
[DependsOn(typeof(AbpMongoDbModule))]
public class MyModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddMongoDbContext<MyDbContext>();
//...
}
}
}
```
#### Add Default Repositories
ABP can automatically create [repositories](Repositories.md) for the entities in your Db Context. Just use `AddDefaultRepositories()` option on registration:
````C#
services.AddMongoDbContext<MyDbContext>(options =>
{
options.AddDefaultRepositories();
});
````
This will create a repository for each aggreate root entity (classes derived from AggregateRoot) by default. If you want to create repositories for other entities too, then set `includeAllEntities` to `true`:
```c#
services.AddMongoDbContext<MyDbContext>(options =>
{
options.AddDefaultRepositories(includeAllEntities: true);
});
```
Then you can inject and use `IRepository<TEntity>` or `IQueryableRepository<TEntity>` in your services.
Loading…
Cancel
Save