Browse Source

Translate the Getting-Started-AspNetCore-Application document.

pull/536/head
maliming 8 years ago
parent
commit
08f10cd42f
  1. 62
      docs/zh-Hans/Getting-Started-AspNetCore-Application.md

62
docs/zh-Hans/Getting-Started-AspNetCore-Application.md

@ -1,30 +1,32 @@
## Getting Started ABP With AspNet Core MVC Web Application
## 在AspNet Core MVC Web Application中使用ABP
This tutorial explains how to start ABP from scratch with minimal dependencies. You generally want to start with a ***[startup template](https://abp.io/Templates)***.
本教程将介绍如何开始以最少的依赖关系开始使用ABP开发. You generally want to start with a ***[startup template](https://abp.io/Templates)***
### Create A New Project
通常情况下你需要下载一个 ***[启动模板](https://abp.io/Templates)***
1. Create a new empty AspNet Core Web Application from Visual Studio:
### 创建一个新项目
1. 使用Visual Studio创建一个空的AspNet Core Web Application:
![](images/create-new-aspnet-core-application.png)
2. Select Empty Template
2. 选择空模板
![](images/select-empty-web-application.png)
You could select another template, but I want to show it from a clear project.
你可以选择其它模板,但是我想要从一个简洁的项目演示它.
### Install Volo.Abp.AspNetCore.Mvc Package
### 安装 Volo.Abp.AspNetCore.Mvc 包
Volo.Abp.AspNetCore.Mvc is AspNet Core MVC integration package for ABP. So, install it to your project:
Volo.Abp.AspNetCore.Mvc是ABP集成AspNet Core MVC的包,请安装它到你项目中:
````
Install-Package Volo.Abp.AspNetCore.Mvc
````
### Create First ABP Module
### 创建ABP模块
ABP is a modular framework and it requires a **startup (root) module** class derived from ``AbpModule``:
ABP是一个模块化框架,它需要一个**启动 (根) 模块**继承自``AbpModule``:
````C#
using Microsoft.AspNetCore.Builder;
@ -56,15 +58,15 @@ namespace BasicAspNetCoreApplication
}
````
``AppModule`` is a good name for the startup module for an application.
``AppModule`` 是应用程序启动模块的好名称(建议你的启动模块也使用这个命名).
ABP packages define module classes and a module can depend on another module. In the code above, our ``AppModule`` depends on ``AbpAspNetCoreMvcModule`` (defined by Volo.Abp.AspNetCore.Mvc package). It's common to add a ``DependsOn`` attribute after installing a new ABP nuget package.
ABP的包定义了这个模块类,模块可以依赖其它模块.在上面的代码中 ``AppModule`` 依赖于 ``AbpAspNetCoreMvcModule`` (模块存在于Volo.Abp.AspNetCore.Mvc包中). 安装新的ABP的包后添加``DependsOn``是很非常常见的做法.
Instead of Startup class, we are configuring ASP.NET Core pipeline in this module class.
我们在此模块类中配置ASP.NET Core管道,而不是Startup类中.
### The Startup Class
### 启动类
Next step is to modify Startup class to integrate to ABP module system:
接下来修改启动类集成ABP模块系统:
````C#
using System;
@ -91,13 +93,13 @@ namespace BasicAspNetCoreApplication
````
Changed ``ConfigureServices`` method to return ``IServiceProvider`` instead of ``void``. This change allows us to replace AspNet Core's Dependency Injection with another framework (see Autofac integration section below). ``services.AddApplication<AppModule>()`` adds all services defined in all modules beginning from the ``AppModule``.
修改``ConfigureServices``方法的返回值为``IServiceProvider``(默认是``void``).这个修改允许我们替换AspNet Core的依赖注入框架. (参阅下面的Autofac集成部分). ``services.AddApplication<AppModule>()``添加了所有模块中定义的全部服务.
``app.InitializeApplication()`` call in ``Configure`` method initializes and starts the application.
``app.InitializeApplication()`` 调用 ``Configure`` 方法初始化并启动应用程序
### Hello World!
The application above does nothing. Let's create an MVC controller does something:
上面的应用程序什么都不没有做,让我们创建一个MVC控制器实现一些功能:
````C#
using Microsoft.AspNetCore.Mvc;
@ -116,42 +118,44 @@ namespace BasicAspNetCoreApplication.Controllers
````
If you run the application, you will see a "Hello World!" message on the page.
如果运行这个应用程序你会在页面中看到"Hello World!".
Derived ``HomeController`` from ``AbpController`` instead of standard ``Controller`` class. This is not required, but ``AbpController`` class has useful base properties and methods to make your development easier.
### Using Autofac as the Dependency Injection Framework
从``AbpController``派生``HomeController`` 而不是继承自``Controller``类.虽然这不是强制要求,但是``AbpController``类有很多有用的有属性和方法,使你的开发更容易.
### 使用 Autofac 依赖注入框架
While AspNet Core's Dependency Injection (DI) system is fine for basic requirements, Autofac provides advanced features like Property Injection and Method Interception which are required by ABP to perform advanced application framework features.
虽然AspNet Core的依赖注入(DI)系统适用于基本要求,但Autofac提供了属性注入和方法拦截等高级功能,这些功能是ABP执行高级应用程序框架功能所必需的.
Replacing AspNet Core's DI system by Autofac and integrating to ABP is pretty easy.
用Autofac取代AspNet Core的DI系统并集成到ABP非常简单.
1. Install Volo.Abp.Autofac package
1. 安装 Volo.Abp.Autofac 包
````
Install-Package Volo.Abp.Autofac
````
2. Add ``AbpAutofacModule`` Dependency
2. 添加 ``AbpAutofacModule`` 依赖
````C#
[DependsOn(typeof(AbpAspNetCoreMvcModule))]
[DependsOn(typeof(AbpAutofacModule))] //Add dependency to ABP Autofac module
[DependsOn(typeof(AbpAutofacModule))] // 在模块上添加依赖AbpAutofacModule
public class AppModule : AbpModule
{
...
}
````
3. Change ``services.AddApplication<AppModule>();`` line in the ``Startup`` class as shown below:
3. 修改在``Startup``类下的``services.AddApplication<AppModule>();``如下所示:
````C#
services.AddApplication<AppModule>(options =>
{
options.UseAutofac(); //Integrate to Autofac
options.UseAutofac(); // 集成 Autofac
});
````
### Source Code
### 源码
Get source code of the sample project created in this tutorial from [here](../samples/BasicAspNetCoreApplication).
从[此处](../samples/BasicAspNetCoreApplication)获取本教程中创建的示例项目的源代码.
Loading…
Cancel
Save