地址:https://aspnetboilerplate.com/Pages/Documents
什么是ASP.NET样板?
ASP.NET Boilerplate(ABP)是一个开放源代码且文档齐全的应用程序框架。 它不仅是一个框架,而且还提供了一个基于域驱动设计的强大架构模型,同时考虑了所有最佳实践。
ABP与最新的ASP.NET Core和EF Core一起使用,但也支持ASP.NET MVC 5.x和EF6.x。
A Quick Sample
Let's investigate a simple class to see ABP's benefits:
让我们研究一个简单的类以了解ABP的好处:
public class TaskAppService : ApplicationService, ITaskAppService { private readonly IRepository<Task> _taskRepository; public TaskAppService(IRepository<Task> taskRepository) { _taskRepository = taskRepository; } [AbpAuthorize(MyPermissions.UpdateTasks)] public async Task UpdateTask(UpdateTaskInput input) { Logger.Info("Updating a task for input: " + input); var task = await _taskRepository.FirstOrDefaultAsync(input.TaskId); if (task == null) { throw new UserFriendlyException(L("CouldNotFindTheTaskMessage")); } ObjectMapper.MapTo(input, task); } }
在这里,我们看到了示例应用程序服务方法。 表示层直接使用DDD中的应用程序服务来执行应用程序的用例。 将UpdateTask视为JavaScript通过AJAX调用的方法。
让我们在这里看到ABP的一些好处:
依赖注入:
ABP使用并提供常规的DI基础结构。 由于此类是一种应用程序服务,因此通常将其作为瞬态(根据请求创建)注册到DI容器。它可以简单地注入任何依赖项(例如本示例中的IRepository <Task>)。
存储库:
ABP可以为每个实体创建默认存储库(例如本示例中的IRepository <Task>)。 默认存储库具有许多有用的方法,例如本示例中使用的FirstOrDefault方法。我们可以扩展默认存储库以满足我们的需求。 存储库抽象了DBMS和ORM,并简化了数据访问逻辑。
授权:
ABP可以声明性检查权限。 如果当前用户没有“更新任务”权限或未登录,则它阻止访问UpdateTask方法。ABP不仅使用声明性属性,而且还具有其他授权方式。
验证:
ABP自动检查输入是否为空。 它还基于标准数据注释属性和自定义验证规则来验证输入的所有属性。如果请求无效,它将引发适当的验证异常并在客户端进行处理。
审核日志记录:
用户,浏览器,IP地址,呼叫服务,方法,参数,呼叫时间,执行持续时间和其他一些信息会根据约定和配置自动为每个请求保存。
工作单元:
在ABP中,默认情况下,每种应用程序服务方法都假定为工作单元。 它会自动创建一个连接,并在方法开始时开始一个事务。如果该方法无例外地成功完成,则将提交事务并释放连接。 即使此方法使用不同的存储库或方法,它们都将是原子的(事务性的)。提交事务后,将自动保存对实体的所有更改。 我们甚至不需要调用上面所示的_repository.Update(task)方法。
异常处理:
我们几乎不需要在Web应用程序上手动处理ABP中的异常。 默认情况下,所有异常都会自动处理!如果发生异常,ABP会自动记录该异常并将正确的结果返回给客户端。 例如,如果这是一个AJAX请求,它将向客户端返回一个JSON对象,指示发生错误。 除非该示例中使用的是UserFriendlyException异常,否则它将向客户端隐藏实际的异常。 它还了解并处理客户端的错误,并向用户显示适当的消息。
日志记录:
如您所见,我们可以使用基类中定义的Logger对象编写日志。 Log4Net默认情况下使用,但它是可更改和可配置的。
本地化:
请注意,在引发异常时我们使用了“ L”方法? 这样,它会根据当前用户的文化自动进行本地化。有关更多信息,请参见本地化文档。
自动映射:
在最后一行,我们使用ABP的IObjectMapper的MapTo方法映射输入。 属性到实体属性。它使用AutoMapper库执行映射。 我们可以根据命名约定轻松地将属性从一个对象映射到另一个对象。
动态API层:
实际上,TaskAppService是一个简单的类。 通常,我们必须编写包装API控制器以将方法公开给JavaScript客户端,但是ABP在运行时会自动执行。这样,我们可以直接从客户端使用应用程序服务方法。
评价:好先进啊………………
动态JavaScript AJAX代理:
ABP创建代理方法,使调用应用程序服务方法就像在客户端上调用JavaScript方法一样简单。
我们可以在这个简单的类中看到ABP的好处。 所有这些任务通常会花费大量时间,但是会由框架自动处理。
除了这个简单的示例之外,ABP还为模块化,多租户,缓存,后台作业,数据过滤器,设置管理,域事件,单元和集成测试等提供了强大的基础架构和开发模型。您专注于业务代码 不要重复自己!
入门
您可以从启动模板或介绍教程开始。
Startup Templates
Directly create a modern looking startup project from the startup templates.
从启动模板直接创建外观现代的启动项目。
启动模板为应用程序提供了基本布局和一些常用功能。 有几个具有不同选项的启动模板。
ASP.NET Core
- Single Page Application with ASP.NET Core & Angular
- Multi-Page Application with ASP.NET Core & jQuery
ASP.NET MVC 5.x
See the download page for other combinations.
有关其他组合,请参见下载页面。
Introduction Tutorials(入门教程)
Step by step tutorials introduces the framework and explains how to create your application based on the startup templates.
逐步教程介绍了该框架,并说明了如何基于启动模板创建应用程序。
ASP.NET Core
- Introduction with ASP.NET Core & Entity Framework Core
- Developing a multi-tenant (SaaS) application with ASP.NET Core, EntityFramework Core & Angular
ASP.NET MVC 5.x
- Introduction with ASP.NET MVC 5.x, Web API 2.x, EntityFramework 6.x & AngularJS 1.x
- Developing a multi-tenant (SaaS) application with ASP.NET MVC 5.x, EntityFramework 6.x & AngularJS 1.x
Samples(样品示例)
There are many sample projects developed with the framework. See the samples page.
该框架开发了许多示例项目。 请参阅示例页面。
Community(社区)
This is an open source project and open to contributions from the community.
这是一个开源项目,欢迎社区的贡献。
- Use the GitHub repository to access the latest source code, create issues and send pull requests.
- Use aspnetboilerplate tag on stackoverflow to ask questions about the usage.
- Follow aspboilerplate on twitter to be informed about the happenings.
- 使用GitHub存储库访问最新源代码,创建问题并发送拉取请求。
- 在stackoverflow上使用aspnetboilerplate标记来询问有关用法的问题。
- 在Twitter上关注aspboilerplate,以了解有关情况。
总结:这个是文档的第一页内容翻译,内容和第二篇文章:
很相似。第一页文档主要介绍了一下内容:
1,说了abp的概念;
2,举了一个代码示例,根据代码示例列举了使用abp的好处;
3,列举了abp提供了哪些模板;
4,列举出入门教程的连接,可以根据入门教程一步一步开始学习abp;
5,列举了示例项目url地址;
6,介绍社区相关信息,可以参与abp开发。项目在github上。
ABP to use and provide regular DI infrastructure. Because this is an application service, which is registered as it is often transient (created upon request) to the DI container. It can simply inject any dependencies (e.g. in this example IRepository <Task>).
Repository:
ABP can create a default storage (e.g. in this example IRepository <Task>) for each entity. Default repository have many useful methods, e.g. FirstOrDefault methods used in this example. We can extend the default repository to meet our needs. Abstract repository DBMS and ORM, and simplifies the data access logic.
Authorization:
ABP can declare check permissions. If the current user does not have "Update Tasks" permission or not logged on, it blocks access to UpdateTask method. ABP not only declarative attributes, but also has other unauthorized manner.
verification:
ABP automatically checks whether the input is empty. It is also based on the standard data annotation attributes and all attributes custom validation rules to validate input. If the request is invalid, it throws an appropriate exception handling authentication at the client.
Audit Logging:
User, browser, IP address, service calls, methods, parameters, call time, duration, and perform some other information will be automatically saved for each request by convention and configuration.
Unit of work:
In ABP, the default method for each application services are assumed to be the work unit. It automatically creates a connection and start a transaction when the method begins. If the process is completed successfully, without exception, will commit the transaction and release the connection. This method uses even different repositories or a method, which will be atoms (transactional). After the transaction is committed, it will automatically save all changes to the entity. We do not even call shown above _repository.Update (task) method.
Exception Handling:
We almost do not need to manually handle exceptions in the ABP Web application. By default, all exceptions are handled automatically! If an exception occurs, ABP will automatically log the exception and the right results back to the client. For example, if this is an AJAX request, it returns to the client a JSON object, indicating an error. Unless used in this example is UserFriendlyException abnormal, otherwise it will hide the actual exception to the client. It also understand and deal with client error, appropriate message is displayed to the user.
Logging:
As you can see, we can write the log using the Logger object defined in the base class. Log4Net used by default, but can be changed and it is configurable.
Localization:
Please note that when an exception is thrown we use "L" method? In this way, it will automatically localized based on the current user's culture. For more information, see the localized documentation.
Automatic Mapping:
In the last line, we use IObjectMapper of ABP MapTo method of mapping input. Attributes to entity attributes. It uses AutoMapper library to perform the mapping. We can easily attribute mapping according to the naming convention from one object to another.
Dynamic API layer:
In fact, TaskAppService is a simple class. In general, we have to write a wrapper API to control methods to JavaScript clients, but ABP performed automatically at runtime. In this way, we can use the method of application services directly from the client.
Evaluation: Good Advanced ah ..................
Dynamic JavaScript AJAX proxy:
ABP create a proxy method, the calling application service method is as simple as calling a JavaScript method on the client.