Browse Source

Merge branch 'dev' of https://github.com/abpframework/abp into pr/139-hardDelete

pull/2807/head
Galip Tolga Erdem 7 years ago
parent
commit
89bf4a660e
  1. 3
      abp_io/AbpIoLocalization/AbpIoLocalization/Commercial/Localization/Resources/en.json
  2. 8
      docs/en/Multi-Tenancy.md
  3. 58
      docs/zh-Hans/Entity-Framework-Core-MySQL.md
  4. 90
      docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md
  5. 52
      docs/zh-Hans/Entity-Framework-Core-PostgreSQL.md
  6. 41
      docs/zh-Hans/Entity-Framework-Core-SQLite.md
  7. 52
      docs/zh-Hans/Entity-Framework-Core.md
  8. 2
      docs/zh-Hans/Microservice-Architecture.md
  9. 8
      docs/zh-Hans/Multi-Tenancy.md
  10. 122
      docs/zh-Hans/Options.md
  11. 54
      docs/zh-Hans/docs-nav.json
  12. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationAdder.cs
  13. 2
      modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/Models/UserLoginInfo.cs
  14. 2
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs
  15. 9
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml
  16. 4
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs
  17. 1
      modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj
  18. 12
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Styles/vs.css
  19. 2
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Styles/vs.min.css
  20. 12
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Styles/vs.scss
  21. 4
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateDto.cs
  22. 4
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserUpdateDto.cs
  23. 4
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs
  24. 2
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs

3
abp_io/AbpIoLocalization/AbpIoLocalization/Commercial/Localization/Resources/en.json

@ -27,6 +27,7 @@
"ApiKey": "API key",
"UserNameNotFound": "There is no user with username {0}",
"SuccessfullyAddedToNewsletter": "Thanks you for subscribing to our newsletter!",
"ManageProfile": "Manage your profile"
"ManageProfile": "Manage your profile",
"EmailNotValid": "Please enter a valid email address."
}
}

8
docs/en/Multi-Tenancy.md

@ -98,7 +98,7 @@ The first thing for a multi-tenant application is to determine the current tenan
##### Custom Tenant Resolvers
You can add your custom tenant resolver to **TenantResolveOptions** in your module's ConfigureServices method as like below:
You can add your custom tenant resolver to **AbpTenantResolveOptions** in your module's ConfigureServices method as like below:
````C#
using Microsoft.Extensions.DependencyInjection;
@ -112,7 +112,7 @@ namespace MyCompany.MyProject
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<TenantResolveOptions>(options =>
Configure<AbpTenantResolveOptions>(options =>
{
options.TenantResolvers.Add(new MyCustomTenantResolveContributor());
});
@ -323,7 +323,7 @@ services.Configure<AbpAspNetCoreMultiTenancyOptions>(options =>
##### Domain Tenant Resolver
In a real application, most of times you will want to determine current tenant either by subdomain (like mytenant1.mydomain.com) or by the whole domain (like mytenant.com). If so, you can configure TenantResolveOptions to add a domain tenant resolver.
In a real application, most of times you will want to determine current tenant either by subdomain (like mytenant1.mydomain.com) or by the whole domain (like mytenant.com). If so, you can configure AbpTenantResolveOptions to add a domain tenant resolver.
###### Example: Add a subdomain resolver
@ -340,7 +340,7 @@ namespace MyCompany.MyProject
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<TenantResolveOptions>(options =>
Configure<AbpTenantResolveOptions>(options =>
{
//Subdomain format: {0}.mydomain.com (adding as the highest priority resolver)
options.TenantResolvers.Insert(0, new DomainTenantResolver("{0}.mydomain.com"));

58
docs/zh-Hans/Entity-Framework-Core-MySQL.md

@ -0,0 +1,58 @@
# 切换到EF Core MySql提供程序
本文介绍如何将预配置为SqlServer提供程序的 **[应用程序启动模板](Startup-Templates/Application.md)** 切换到 **MySql** 数据库提供程序
## 替换Volo.Abp.EntityFrameworkCore.SqlServer包
解决方案中的 `.EntityFrameworkCore` 项目依赖于 [Volo.Abp.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.SqlServer) NuGet包. 删除这个包并且添加相同版本的 [Volo.Abp.EntityFrameworkCore.MySQL](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.MySQL) 包.
## 替换模块依赖项
在 `.EntityFrameworkCore` 项目中找到 **YourProjectName*EntityFrameworkCoreModule** 类, 删除 `DependsOn` attribute 上的`typeof(AbpEntityFrameworkCoreSqlServerModule)`, 添加 `typeof(AbpEntityFrameworkCoreMySQLModule)` (或者替换 `using Volo.Abp.EntityFrameworkCore.SqlServer;` 为 `using Volo.Abp.EntityFrameworkCore.MySQL;`).
## UseMySQL()
查找你的解决方案中 `UseSqlServer()`调用,替换为 `UseMySQL()`. 检查下列文件:
* `.EntityFrameworkCore` 项目中的*YourProjectName*EntityFrameworkCoreModule.cs.
* `.EntityFrameworkCore` 项目中的*YourProjectName*MigrationsDbContextFactory.cs.
> 根据你的解决方案的结构,你可能发现更多需要改变代码的文件.
## 更改连接字符串
MySQL连接字符串与SQL Server连接字符串不同. 所以检查你的解决方案中所有的 `appsettings.json` 文件,更改其中的连接字符串. 有关MySQL连接字符串选项的详细内容请参见[connectionstrings.com](https://www.connectionstrings.com/mysql/).
通常需要更改 `.DbMigrator` 和 `.Web` 项目里面的 `appsettings.json` ,但它取决于你的解决方案结构.
## 更改迁移DbContext
MySQL DBMS与SQL Server有一些细微的差异. 某些模块数据库映射配置(尤其是字段长度)会导致MySQL出现问题. 例如某些[IdentityServer模块](Modules/IdentityServer.md)表就存在这样的问题,它提供了一个选项可以根据您的DBMS配置字段.
启动模板包含*YourProjectName*MigrationsDbContext,它负责维护和迁移数据库架构. 此DbContext基本上调用依赖模块的扩展方法来配置其数据库表.
打开 *YourProjectName*MigrationsDbContext 更改 `builder.ConfigureIdentityServer();` 行,如下所示:
````csharp
builder.ConfigureIdentityServer(options =>
{
options.DatabaseProvider = EfCoreDatabaseProvider.MySql;
});
````
然后 `ConfigureIdentityServer()` 方法会将字段长度设置为不超过MySQL的限制. 如果在创建或执行数据库迁移时遇到任何问题请参考相关的模块文档.
## 重新生成迁移
启动模板使用[Entity Framework Core的Code First迁移](https://docs.microsoft.com/zh-cn/ef/core/managing-schemas/migrations/). EF Core迁移取决于所选的DBMS提供程序. 因此更改DBMS提供程序会导致迁移失败.
* 删除 `.EntityFrameworkCore.DbMigrations` 项目下的Migrations文件夹,并重新生成解决方案.
* 在包管理控制台中运行 `Add-Migration "Initial"`(在解决方案资源管理器选择 `.DbMigrator` (或 `.Web`) 做为启动项目并且选择 `.EntityFrameworkCore.DbMigrations` 做为默认项目).
这将创建一个配置所有数据库对象(表)的数据库迁移.
运行 `.DbMigrator` 项目创建数据库和初始种子数据.
## 运行应用程序
它已准备就绪, 只需要运行该应用程序与享受编码.

90
docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md

@ -0,0 +1,90 @@
# 切换到EF Core 其它DBMS提供程序
**[应用程序启动模板](Startup-Templates/Application.md)** 为EF Core预配置了Sql Server提供程序,EF Core支持许多其它DBMS,你可以在基于ABP的应用程序使用它们.
ABP框架为一些常见的DMBS提供了简化配置的集成包(有关可用集成包的列表,请参阅[EF Core文档](Entity-Framework-Core.md)),你也可以不使用集成包配置DBMS提供程序.
虽然总是建议使用集成包(它也使不同模块之间的依赖版本成为标准版本),但是如果没有用于DBMS提供程序的集成包,也可以手动集成.
本文介绍了如何在不使用[MySQL集成包](Entity-Framework-Core-MySQL.md)的情况下切换到MySQL.
## 替换SQL Server依赖
* 删除 `.EntityFrameworkCore` 项目依赖的 [Volo.Abp.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.SqlServer) NuGet 包.
* 添加 [Pomelo.EntityFrameworkCore.MySql](https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql/) NuGet 包到 `.EntityFrameworkCore` 项目.
## 删除模块依赖项
从 ***YourProjectName*EntityFrameworkCoreModule** 类的依赖列表中删除`AbpEntityFrameworkCoreSqlServerModule`.
## 更改UseSqlServer()调用
在*YourProjectName*EntityFrameworkCoreModule类中找到以下代码:
````csharp
Configure<AbpDbContextOptions>(options =>
{
options.UseSqlServer();
});
````
替换成以下代码:
````csharp
Configure<AbpDbContextOptions>(options =>
{
options.Configure(ctx =>
{
if (ctx.ExistingConnection != null)
{
ctx.DbContextOptions.UseMySql(ctx.ExistingConnection);
}
else
{
ctx.DbContextOptions.UseMySql(ctx.ConnectionString);
}
});
});
````
* 调用的 `UseMySql` 代码是在 Pomelo.EntityFrameworkCore.MySql 包中定义的,方法还有附加选项,如果需要可以使用它.
* 这段代码首先检查当前请求中是否存在到相同数据库的现有(活动)连接,并在可能的情况下重用它. 这允许在不同的DbContext类型之间共享单个事务. ABP处理其余的事情.
* 如果没有活动的连接,它将把 `ctx.ConnectionString` 传递给UseMySql(这将创建新的数据库连接). 这里使用 `ctx.ConnectionString` 很重要. 不要传递静态连接字符串(或配置中的连接字符串). 因为ABP在多数据库或[多租户](Multi-Tenancy.md)环境中[动态确定正确的连接字符串](Connection-Strings.md).
## 更改连接连接字符串
MySQL连接字符串与SQL Server连接字符串不同. 所以检查你的解决方案中所有的 `appsettings.json` 文件,更改其中的连接字符串. 有关MySQL连接字符串选项的详细内容请参见[connectionstrings.com](https://www.connectionstrings.com/mysql/).
通常需要更改 `.DbMigrator` 和 `.Web` 项目里面的 `appsettings.json` ,但它取决于你的解决方案结构.
## 更改迁移DbContext
MySQL DBMS与SQL Server有一些细微的差异. 某些模块数据库映射配置(尤其是字段长度)会导致MySQL出现问题. 例如某些[IdentityServer模块](Modules/IdentityServer.md)表就存在这样的问题,它提供了一个选项可以根据您的DBMS配置字段.
启动模板包含*YourProjectName*MigrationsDbContext,它负责维护和迁移数据库架构. 此DbContext基本上调用依赖模块的扩展方法来配置其数据库表.
打开 *YourProjectName*MigrationsDbContext 更改 `builder.ConfigureIdentityServer();` 行,如下所示:
````csharp
builder.ConfigureIdentityServer(options =>
{
options.DatabaseProvider = EfCoreDatabaseProvider.MySql;
});
````
然后 `ConfigureIdentityServer()` 方法会将字段长度设置为超过MySQL的限制. 如果在创建或执行数据库迁移时遇到任何问题请参考相关的模块文档.
## 重新生成迁移
启动模板使用[Entity Framework Core的Code First迁移](https://docs.microsoft.com/zh-cn/ef/core/managing-schemas/migrations/). EF Core迁移取决于所选的DBMS提供程序. 因此更改DBMS提供程序会导致迁移失败.
* 删除 `.EntityFrameworkCore.DbMigrations` 项目下的Migrations文件夹,并重新生成解决方案.
* 在包管理控制台中运行 `Add-Migration "Initial"`(在解决方案资源管理器选择 `.DbMigrator` (或 `.Web`) 做为启动项目并且选择 `.EntityFrameworkCore.DbMigrations` 做为默认项目).
这将创建一个配置所有数据库对象(表)的数据库迁移.
运行 `.DbMigrator` 项目创建数据库和初始种子数据.
## 运行应用程序
它已准备就绪, 只需要运行该应用程序与享受编码.

52
docs/zh-Hans/Entity-Framework-Core-PostgreSQL.md

@ -1,35 +1,41 @@
## Entity Framework Core PostgreSQL 集成
# 切换到EF Core PostgreSQL提供程序
> 参阅 [Entity Framework Core 集成文档](../Entity-Framework-Core.md) 了解集成EF Core的基础知识.
本文介绍如何将预配置为SqlServer提供程序的 **[应用程序启动模板](Startup-Templates/Application.md)** 切换到 **PostgreSQL** 数据库提供程序
### 更新 EntityFrameworkCore 项目
## 替换Volo.Abp.EntityFrameworkCore.SqlServer包
- 在 `Acme.BookStore.EntityFrameworkCore` 中将包 `Volo.Abp.EntityFrameworkCore.SqlServer` 替换为 `Volo.Abp.EntityFrameworkCore.PostgreSql`
- 打开 `BookStoreEntityFrameworkCoreModule` 模块类
- 将 `AbpEntityFrameworkCoreSqlServerModule` 替换为 `AbpEntityFrameworkCorePostgreSqlModule`
- 将 `options.UseSqlServer()` 替换为 `options.UsePostgreSql()`
- 在其他的项目中将 `appsetting.json` 文件中的连接字符串更新为PostgreSQL链接字符串
解决方案中的 `.EntityFrameworkCore` 项目依赖于 [Volo.Abp.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.SqlServer) NuGet包. 删除这个包并且添加相同版本的 [Volo.Abp.EntityFrameworkCore.PostgreSql](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.PostgreSql) 包.
#### 删除现有迁移
## 替换模块依赖项
删除所有的现有迁移文件 (包括 `DbContextModelSnapshot`)
在 `.EntityFrameworkCore` 项目中找到 **YourProjectName*EntityFrameworkCoreModule** 类, 删除 `DependsOn` attribute 上的`typeof(AbpEntityFrameworkCoreSqlServerModule)`, 添加 `typeof(AbpEntityFrameworkCorePostgreSqlModule)` (或者替换 `using Volo.Abp.EntityFrameworkCore.SqlServer;` 为 `using Volo.Abp.EntityFrameworkCore.PostgreSql;`).
![postgresql-delete-initial-migrations](images/postgresql-delete-initial-migrations.png)
## UsePostgreSql()
#### 生成生成迁移并更新数据库
查找你的解决方案中 `UseSqlServer()`调用,替换为 `UsePostgreSql()`. 检查下列文件:
设置正确的启动项目 (通常是Web项目),
打开 **程序包管理器控制台** (工具 -> Nuget包管理器 -> 程序包管理器控制台), 选择 `Acme.BookStore.EntityFrameworkCore.DbMigrations` 做为 **默认项目** 并执行以下命令:
* `.EntityFrameworkCore` 项目中的*YourProjectName*EntityFrameworkCoreModule.cs.
* `.EntityFrameworkCore` 项目中的*YourProjectName*MigrationsDbContextFactory.cs.
运行 `Add-Migration` 命令.
````
PM> Add-Migration Initial
````
> 根据你的解决方案的结构,你可能发现更多需要改变代码的文件.
然后执行 `Update-Database` 执行更新数据库:
## 更改连接字符串
````
PM> Update-Database
````
PostgreSql连接字符串与SQL Server连接字符串不同. 所以检查你的解决方案中所有的 `appsettings.json` 文件,更改其中的连接字符串. 有关PostgreSql连接字符串选项的详细内容请参见[connectionstrings.com](https://www.connectionstrings.com/postgresql/).
![postgresql-update-database](images/postgresql-update-database.png)
通常需要更改 `.DbMigrator` 和 `.Web` 项目里面的 `appsettings.json` ,但它取决于你的解决方案结构.
## 重新生成迁移
启动模板使用[Entity Framework Core的Code First迁移](https://docs.microsoft.com/zh-cn/ef/core/managing-schemas/migrations/). EF Core迁移取决于所选的DBMS提供程序. 因此更改DBMS提供程序会导致迁移失败.
* 删除 `.EntityFrameworkCore.DbMigrations` 项目下的Migrations文件夹,并重新生成解决方案.
* 在包管理控制台中运行 `Add-Migration "Initial"`(在解决方案资源管理器选择 `.DbMigrator` (或 `.Web`) 做为启动项目并且选择 `.EntityFrameworkCore.DbMigrations` 做为默认项目).
这将创建一个配置所有数据库对象(表)的数据库迁移.
运行 `.DbMigrator` 项目创建数据库和初始种子数据.
## 运行应用程序
它已准备就绪, 只需要运行该应用程序与享受编码.

41
docs/zh-Hans/Entity-Framework-Core-SQLite.md

@ -0,0 +1,41 @@
# 切换到EF Core SQLite提供程序
本文介绍如何将预配置为SqlServer提供程序的 **[应用程序启动模板](Startup-Templates/Application.md)** 切换到 **SQLite** 数据库提供程序.
## 替换Volo.Abp.EntityFrameworkCore.SqlServer包
解决方案中的 `.EntityFrameworkCore` 项目依赖于 [Volo.Abp.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.SqlServer) NuGet包. 删除这个包并且添加相同版本的 [Volo.Abp.EntityFrameworkCore.SQLite](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.SQLite) 包.
## 替换模块依赖项
在 `.EntityFrameworkCore` 项目中找到 **YourProjectName*EntityFrameworkCoreModule** 类, 删除 `DependsOn` attribute 上的`typeof(AbpEntityFrameworkCoreSqlServerModule)`, 添加 `typeof(AbpEntityFrameworkCoreSqliteModule)` (或者替换 `using Volo.Abp.EntityFrameworkCore.SqlServer;` 为 `using Volo.Abp.EntityFrameworkCore.Sqlite;`).
## UseSqlite()
查找你的解决方案中 `UseSqlServer()`调用,替换为 `UseSqlite()`. 检查下列文件:
* `.EntityFrameworkCore` 项目中的*YourProjectName*EntityFrameworkCoreModule.cs.
* `.EntityFrameworkCore` 项目中的*YourProjectName*MigrationsDbContextFactory.cs.
> 根据你的解决方案的结构,你可能发现更多需要改变代码的文件.
## 更改连接字符串
SQLite连接字符串与SQL Server连接字符串不同. 所以检查你的解决方案中所有的 `appsettings.json` 文件,更改其中的连接字符串. 有关SQLite连接字符串选项的详细内容请参见[connectionstrings.com](https://www.connectionstrings.com/sqlite/).
通常需要更改 `.DbMigrator` 和 `.Web` 项目里面的 `appsettings.json` ,但它取决于你的解决方案结构.
## 重新生成迁移
启动模板使用[Entity Framework Core的Code First迁移](https://docs.microsoft.com/zh-cn/ef/core/managing-schemas/migrations/). EF Core迁移取决于所选的DBMS提供程序. 因此更改DBMS提供程序会导致迁移失败.
* 删除 `.EntityFrameworkCore.DbMigrations` 项目下的Migrations文件夹,并重新生成解决方案.
* 在包管理控制台中运行 `Add-Migration "Initial"`(在解决方案资源管理器选择 `.DbMigrator` (或 `.Web`) 做为启动项目并且选择 `.EntityFrameworkCore.DbMigrations` 做为默认项目).
这将创建一个配置所有数据库对象(表)的数据库迁移.
运行 `.DbMigrator` 项目创建数据库和初始种子数据.
## 运行应用程序
它已准备就绪, 只需要运行该应用程序与享受编码.

52
docs/zh-Hans/Entity-Framework-Core.md

@ -1,8 +1,8 @@
## Entity Framework Core 集成
# Entity Framework Core 集成
本文介绍了如何将EF Core作为ORM提供程序集成到基于ABP的应用程序以及如何对其进行配置.
### 安装
## 安装
`Volo.Abp.EntityFrameworkCore` 是EF Core 集成的主要nuget包. 将其安装到你的项目中(在分层应用程序中适用于 数据访问/基础设施层):
@ -26,7 +26,22 @@ namespace MyCompany.MyProject
}
````
### 创建 DbContext
> 注: 你可以直接下载预装EF Core的[启动模板](https://abp.io/Templates).
### 数据库管理系统选择
EF Core支持多种数据库管理系统([查看全部](https://docs.microsoft.com/en-us/ef/core/providers/)). ABP框架和本文档不依赖于任何特定的DBMS.
如果要创建一个可重用的库,应避免依赖于特定的DBMS包.但在最终的应用程序中,始终会选择一个DBMS.
ABP框架为一些常见的DBMS提供了集成包,使配置变得更加简单. [启动模板](Startup-Templates/Index.md)附带**预先配置的SQL Server (localdb)**.请参阅以下文档,了解如何配置其他DBMS提供程序:
* [MySQL](Entity-Framework-Core-MySQL.md)
* [PostgreSQL](Entity-Framework-Core-PostgreSQL.md)
* [SQLite](Entity-Framework-Core-SQLite.md)
* [Others](Entity-Framework-Core-Other-DBMS.md)
## 创建 DbContext
你可以平常一样创建DbContext,它需要继承自 `AbpDbContext<T>`. 如下所示:
@ -48,7 +63,22 @@ namespace MyCompany.MyProject
}
````
### 将DbContext注册到依赖注入
### 配置连接字符串选择
如果你的应用程序有多个数据库,你可以使用 `connectionStringName]` Attribute为你的DbContext配置连接字符串名称.
例:
```csharp
[ConnectionStringName("MySecondConnString")]
public class MyDbContext : AbpDbContext<MyDbContext>
{
}
```
如果不进行配置,则使用`Default`连接字符串. 如果你配置特定的连接字符串的名称,但在应用程序配置中没有定义这个连接字符串名称,那么它会回退到`Default`连接字符串(参阅[连接字符串文档](Connection-Strings.md)了解更多信息).
## 将DbContext注册到依赖注入
在module中的ConfigureServices方法使用 `AddAbpDbContext` 在[依赖注入](Dependency-Injection.md)系统注册DbContext类.
@ -72,7 +102,7 @@ namespace MyCompany.MyProject
}
````
#### 添加默认仓储
### 添加默认仓储
ABP会自动为DbContext中的实体创建[默认仓储](Repositories.md). 需要在注册的时使用options添加`AddDefaultRepositories()`:
@ -174,7 +204,7 @@ public class BookRepository : EfCoreRepository<BookStoreDbContext, Book, Guid>,
现在可以在需要时[注入](Dependency-Injection.md)`IBookRepository`并使用`DeleteBooksByType`方法.
##### 覆盖默认通用仓储
#### 覆盖默认通用仓储
即使创建了自定义仓储,仍可以注入使用默认通用仓储(在本例中是 `IRepository<Book, Guid>`). 默认仓储实现不会使用你创建的自定义仓储类.
@ -200,7 +230,7 @@ public override async Task DeleteAsync(
}
````
#### 访问 EF Core API
### 访问 EF Core API
大多数情况下应该隐藏仓储后面的EF Core API(这也是仓储的设计目地). 但是如果想要通过仓储访问DbContext实现,则可以使用`GetDbContext()`或`GetDbSet()`扩展方法. 例:
@ -226,9 +256,9 @@ public class BookService
> 要点: 你必须在使用`DbContext`的项目里引用`Volo.Abp.EntityFrameworkCore`包. 这会破坏封装,但在这种情况下,这就是你需要的.
#### 高级主题
### 高级主题
##### 设置默认仓储类
#### 设置默认仓储类
默认的通用仓储的默认实现是`EfCoreRepository`类,你可以创建自己的实现,并将其做为默认实现
@ -273,7 +303,7 @@ context.Services.AddAbpDbContext<BookStoreDbContext>(options =>
});
```
#### 为默认仓储设置Base DbContext类或接口
### 为默认仓储设置Base DbContext类或接口
如果你的DbContext继承了另外一个DbContext或实现了一个接口,你可以使用这个基类或接口作为默认仓储的DbContext. 例:
@ -305,7 +335,7 @@ public class BookRepository : EfCoreRepository<IBookStoreDbContext, Book, Guid>,
使用DbContext接口的一个优点是它可以被其他实现替换.
#### 替换其他仓储
### 替换其他仓储
正确定义并使用DbContext接口后,任何其他实现都可以使用以下ReplaceDbContext options 替换它:

2
docs/zh-Hans/Microservice-Architecture.md

@ -23,7 +23,7 @@ ABP框架的主要目标之一就是提供**便捷的基础设施来创建微服
然而开发一个良好的模块化应用程序不是那么简单,因为很难像微服务那样**保持模块之间的隔离** (参阅 [Stefan Tilkov的文章](https://martinfowler.com/articles/dont-start-monolith.html)). 微服务架构会自然的让你开发隔离的服务,但是在模块化的单体应用程序中,模块很容易彼此紧密耦合并设计出**弱模块边界**和API约定.
ABP可以帮助你,它提供了与**与微服务兼容的严格模块架构** 在这个架构中你的模块被分割成多个层/项目,在自己的VS解决方案中进行开发,该解决方案完成独立于其它模块. 这种方式开发的模块是一种天然的微服务,但是它可以很容易的插入到单体应用程序中. 请参阅**微服务优先的模块设计**的[模块开发最佳实践指南](Best-Practices/Index.md). 所有[标准的ABP模块](https://github.com/abpframework/abp/tree/master/modules)都是基于本指南开发的. 因此你可以将这些模块嵌入到单体解决方案中使用它们,也可以单独部署通过远程API调用. 它们可以共享一个数据库,也可以通过简单配置使用自己的数据库.
ABP可以帮助你,它提供了与**与微服务兼容的严格模块架构** 在这个架构中你的模块被分割成多个层/项目,在自己的VS解决方案中进行开发,该解决方案完全独立于其它模块. 这种方式开发的模块是一种天然的微服务,但是它可以很容易的插入到单体应用程序中. 请参阅**微服务优先的模块设计**的[模块开发最佳实践指南](Best-Practices/Index.md). 所有[标准的ABP模块](https://github.com/abpframework/abp/tree/master/modules)都是基于本指南开发的. 因此你可以将这些模块嵌入到单体解决方案中使用它们,也可以单独部署通过远程API调用. 它们可以共享一个数据库,也可以通过简单配置使用自己的数据库.
## 微服务解决方案示例

8
docs/zh-Hans/Multi-Tenancy.md

@ -99,7 +99,7 @@ Volo.Abp.MultiTenancy只提供了用于确定当前租户的抽象(称为租户
##### 自定义租户解析器
你可以像下面这样,在你模块的ConfigureServices方法中将自定义解析器并添加到 **TenantResolveOptions**中:
你可以像下面这样,在你模块的ConfigureServices方法中将自定义解析器并添加到 **AbpTenantResolveOptions**中:
````C#
using Microsoft.Extensions.DependencyInjection;
@ -113,7 +113,7 @@ namespace MyCompany.MyProject
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<TenantResolveOptions>(options =>
Configure<AbpTenantResolveOptions>(options =>
{
options.TenantResolvers.Add(new MyCustomTenantResolveContributor());
});
@ -323,7 +323,7 @@ services.Configure<AbpAspNetCoreMultiTenancyOptions>(options =>
##### 域名租户解析器
实际项目中,大多数情况下你想通过子域名(如mytenant1.mydomain.com)或全域名(如mytenant.com)中确定当前租户.如果是这样,你可以配置TenantResolveOptions添加一个域名租户解析器.
实际项目中,大多数情况下你想通过子域名(如mytenant1.mydomain.com)或全域名(如mytenant.com)中确定当前租户.如果是这样,你可以配置AbpTenantResolveOptions添加一个域名租户解析器.
###### 例子:添加子域名解析器
@ -340,7 +340,7 @@ namespace MyCompany.MyProject
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<TenantResolveOptions>(options =>
Configure<AbpTenantResolveOptions>(options =>
{
//子域名格式: {0}.mydomain.com (作为最高优先级解析器添加)
options.TenantResolvers.Insert(0, new DomainTenantResolver("{0}.mydomain.com"));

122
docs/zh-Hans/Options.md

@ -1,3 +1,121 @@
# Options
# 选项
TODO!
微软引入[选项模式](https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration/options),它是用于配置框架服务使用的设置. 选项模式由[Microsoft.Extensions.Options](https://www.nuget.org/packages/Microsoft.Extensions.Options)NuGet包实现,除了ASP.NET Core应用,它还适用于任何类型的应用程序.
ABP框架遵循选项模式,并定义了用于配置框架和模块的选项类(在相关功能文档中有详细的说明).
由于[微软的文档](https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration/options)详细解释了选项模式,本文中只会介绍ABP增加的一些功能.
## 配置选项
通常配置选项在 `Startup` 类的 `ConfigureServices` 方法中. 但由于ABP框架提供了模块化基础设施,因此你可以在[模块](Module-Development-Basics.md)的`ConfigureServices` 方法配置选项.
例:
````csharp
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.Configure<AbpAuditingOptions>(options =>
{
options.IsEnabled = false;
});
}
````
* `AbpAuditingOptions` 是一个简单的类,定义了一些属性,例如这里使用的 `IsEnabled`.
* `AbpModule` 基类定义 `Configure` 方法简化代码. 你可以直接使用 `Configure<...>`,而不是`context.Services.Configure <...>`.
如果你正在开发一个可重用的模块,你可能需要定义一个允许开发人员配置模块的选项类. 这时定义一个如下所示的普通类:
````csharp
public class MyOptions
{
public int Value1 { get; set; }
public bool Value2 { get; set; }
}
````
然后开发人员可以像上面 `AbpAuditingOptions` 示例一样配置你的选项:
````csharp
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<MyOptions>(options =>
{
options.Value1 = 42;
options.Value2 = true;
});
}
````
* 在本示例中,使用了简化的 `Configure<...>`方法.
### 获取选项值
在你需要获得一个选项值时,将 `IOptions<TOption>` 服务[注入](Dependency-Injection.md)到你的类中,使用它的 `.Value` 属性得到值.
例:
````csharp
public class MyService : ITransientDependency
{
private readonly MyOptions _options;
public MyService(IOptions<MyOptions> options)
{
_options = options.Value; //Notice the options.Value usage!
}
public void DoIt()
{
var v1 = _options.Value1;
var v2 = _options.Value2;
}
}
````
阅读[微软文档](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options)了解选择模式的所有细节.
## 预配置
选项模式的限制之一是你只能解析(注入) `IOptions <MyOptions>` 并在依赖注入配置完成(即所有模块的`ConfigureServices`方法完成)后获取选项值.
如果你正在开发一个模块,可能需要让开发者能够设置一些选项,并在依赖注入注册阶段使用这些选项. 你可能需要根据选项值配置其他服务或更改依赖注入的注册代码.
对于此类情况,ABP为 `IServiceCollection` 引入了 `PreConfigure<TOptions>` 和 `ExecutePreConfiguredActions<TOptions>` 扩展方法. 该模式的工作原理如下所述。
1. 你的模块中定义计划选项类. 例:
````csharp
public class MyPreOptions
{
public bool MyValue { get; set; }
}
````
然后任何依赖于模块的模块类都可以在其 `PreConfigureServices` 方法中使用 `PreConfigure<TOptions>` 方法.
例:
````csharp
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<MyPreOptions>(options =>
{
options.MyValue = true;
});
}
````
> 多个模块可以预配置选项,并根据它们的依赖顺序覆盖选项值.
最后在你的模块 `ConfigureServices` 方法中执行 `ExecutePreConfiguredActions` 方法来获得配置的选项值.
例:
````csharp
public override void ConfigureServices(ServiceConfigurationContext context)
{
var options = context.Services.ExecutePreConfiguredActions<MyPreOptions>();
if (options.MyValue)
{
//...
}
}
````

54
docs/zh-Hans/docs-nav.json

@ -52,6 +52,10 @@
"text": "配置",
"path": "Configuration.md"
},
{
"text": "选项",
"path": "Options.md"
},
{
"text": "依赖注入",
"path": "Dependency-Injection.md",
@ -85,7 +89,8 @@
]
},
{
"text": "授权"
"text": "授权",
"path": "Authorization.md"
},
{
"text": "缓存",
@ -256,22 +261,43 @@
"path":"Data-Access.md",
"items": [
{
"text": "Entity Framework Core 集成",
"path": "Entity-Framework-Core.md",
"items": [
"text": "连接字符串",
"path": "Connection-Strings.md"
},
{
"text": "数据库提供程序",
"items": [
{
"text": "Entity Framework Core",
"path": "Entity-Framework-Core.md",
"items": [
{
"text": "切换到MySql",
"path": "Entity-Framework-Core-MySQL.md"
},
{
"text": "切换到PostgreSQL",
"path": "Entity-Framework-Core-PostgreSQL.md"
},
{
"text": "切换到SQLite",
"path": "Entity-Framework-Core-SQLite.md"
},
{
"text": "切换到其他DBMS",
"path": "Entity-Framework-Core-Other-DBMS.md"
}
]
},
{
"text": "PostgreSQL 集成",
"path": "Entity-Framework-Core-PostgreSQL.md"
"text": "MongoDB",
"path": "MongoDB.md"
},
{
"text": "Dapper",
"path": "Dapper.md"
}
]
},
{
"text": "MongoDB 集成",
"path": "MongoDB.md"
},
{
"text": "Dapper 集成",
"path": "Dapper.md"
}
]
},

4
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationAdder.cs

@ -12,7 +12,7 @@ namespace Volo.Abp.Cli.ProjectModification
var moduleName = ParseModuleName(module);
var migrationName = "Added_" + moduleName + "_Module" + GetUniquePostFix();
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef migrations add " + migrationName + GetStartupProjectOption(startupProject));
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" && dotnet ef migrations add " + migrationName + GetStartupProjectOption(startupProject));
if (updateDatabase)
{
@ -22,7 +22,7 @@ namespace Volo.Abp.Cli.ProjectModification
protected void UpdateDatabase(string csprojFile, string startupProject)
{
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef database update" + GetStartupProjectOption(startupProject));
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" && dotnet ef database update" + GetStartupProjectOption(startupProject));
}
protected virtual string ParseModuleName(string fullModuleName)

2
modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/Models/UserLoginInfo.cs

@ -1,5 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Auditing;
namespace Volo.Abp.Account.Web.Areas.Account.Controllers.Models
{
@ -12,6 +13,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers.Models
[Required]
[StringLength(32)]
[DataType(DataType.Password)]
[DisableAuditing]
public string Password { get; set; }
public bool RememberMe { get; set; }

2
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs

@ -11,6 +11,7 @@ using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Volo.Abp.Account.Settings;
using Volo.Abp.Auditing;
using Volo.Abp.Identity;
using Volo.Abp.Security.Claims;
using Volo.Abp.Settings;
@ -254,6 +255,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
[Required]
[StringLength(IdentityUserConsts.MaxPasswordLength)]
[DataType(DataType.Password)]
[DisableAuditing]
public string Password { get; set; }
public bool RememberMe { get; set; }

9
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml

@ -1,11 +1,12 @@
@page
@model Volo.Abp.Account.Web.Pages.Account.ManageModel
@using Volo.Abp.Account.Web.Pages.Account
@using Volo.Abp.Identity.Settings
@using Volo.Abp.Settings
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject ISettingProvider SettingManager
@inject IThemeManager ThemeManager
@inherits Volo.Abp.Account.Web.Pages.Account.AccountPage
@model ManageModel
@{
Layout = ThemeManager.CurrentTheme.GetApplicationLayout();
var isUserNameUpdateEnabled = string.Equals(await SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled), "true",
@ -15,10 +16,12 @@
StringComparison.OrdinalIgnoreCase);
}
@section scripts {
<abp-script src="/Pages/Account/Manage.js" />
<abp-script-bundle name="@typeof(ManageModel).FullName">
<abp-script src="/Pages/Account/Manage.js" />
</abp-script-bundle>
}
<abp-card>
<abp-card-body>
<abp-card-body>
<abp-tabs tab-style="PillVertical">
<abp-tab title="@L["ChangePassword"].Value">
<h4>@L["ChangePassword"].Value</h4><hr />

4
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs

@ -1,9 +1,10 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Account.Settings;
using Volo.Abp.Auditing;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Identity;
using Volo.Abp.Settings;
@ -83,6 +84,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
[Required]
[StringLength(IdentityUserConsts.MaxPasswordLength)]
[DataType(DataType.Password)]
[DisableAuditing]
public string Password { get; set; }
}
}

1
modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj

@ -30,7 +30,6 @@
<Content Remove="Pages\**\*.js" />
<Content Remove="Pages\**\*.css" />
<Content Remove="Properties\launchSettings.json" />
<None Remove="Pages\Account\Manage.js" />
<None Include="Properties\launchSettings.json" />
</ItemGroup>

12
modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Styles/vs.css

@ -137,17 +137,17 @@
.docs-page .docs-sidebar .docs-top .navbar-logo .navbar-brand strong {
font-weight: 300;
text-transform: uppercase;
font-size: .9rem;
opacity: .6; }
font-size: .7em;
letter-spacing: 1px; }
.docs-page .docs-sidebar .docs-top .navbar-logo .go-back-site {
color: #000;
opacity: .15;
transition: .4s;
font-size: .75rem;
opacity: .65;
transition: .2s;
font-size: .8em;
font-weight: 300; }
.docs-page .docs-sidebar .docs-top .navbar-logo .go-back-site:hover {
text-decoration: none;
opacity: .5; }
opacity: 1; }
.docs-page .docs-sidebar .docs-top .navbar-logo .navbar-logo-desc {
font-size: .85em; }
.docs-page .docs-sidebar .docs-top .navbar-logo .navbar-logo-desc strong {

2
modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Styles/vs.min.css

File diff suppressed because one or more lines are too long

12
modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Styles/vs.scss

@ -233,21 +233,21 @@ body {
strong {
font-weight: 300;
text-transform: uppercase;
font-size: .9rem;
opacity: .6;
font-size: .7em;
letter-spacing: 1px;
}
}
.go-back-site {
color: #000;
opacity: .15;
transition: .4s;
font-size: .75rem;
opacity: .65;
transition: .2s;
font-size: .8em;
font-weight: 300;
&:hover {
text-decoration: none;
opacity: .5;
opacity: 1;
}
}

4
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateDto.cs

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Auditing;
namespace Volo.Abp.Identity
{
@ -6,6 +7,7 @@ namespace Volo.Abp.Identity
{
[Required]
[StringLength(IdentityUserConsts.MaxPasswordLength)]
[DisableAuditing]
public string Password { get; set; }
}
}

4
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserUpdateDto.cs

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Identity
@ -6,6 +7,7 @@ namespace Volo.Abp.Identity
public class IdentityUserUpdateDto : IdentityUserCreateOrUpdateDtoBase, IHasConcurrencyStamp
{
[StringLength(IdentityUserConsts.MaxPasswordLength)]
[DisableAuditing]
public string Password { get; set; }
public string ConcurrencyStamp { get; set; }

4
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs

@ -1,8 +1,9 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Auditing;
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity.Web.Pages.Identity.Users
@ -65,6 +66,7 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users
[Required]
[StringLength(IdentityUserConsts.MaxPasswordLength)]
[DataType(DataType.Password)]
[DisableAuditing]
public string Password { get; set; }
[Required]

2
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs

@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Auditing;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Entities;
@ -75,6 +76,7 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users
[StringLength(IdentityUserConsts.MaxPasswordLength)]
[DataType(DataType.Password)]
[DisableAuditing]
public string Password { get; set; }
[Required]

Loading…
Cancel
Save