ASP.NET Core实践:ABP模块化&统一返回结果
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ASP.NET Core实践:ABP模块化&统一返回结果,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2024字,纯文字阅读大概需要3分钟。
内容图文
![ASP.NET Core实践:ABP模块化&统一返回结果](/upload/InfoBanner/zyjiaocheng/624/8bc49c9d45fe49c4a6dec93107b53194.jpg)
一、ABP框架
1、简介
ASP.NET Boilerplate (ABP) is an open source and well-documented application framework. It's not just a framework, it also provides a strong architectural model based on Domain Driven Design, with all the best practices in mind.
2、特点
(1)模块化
- 模块结构
包括 IOC、应用配置、应用startup&shutdown的事件
- 使用
注册服务
实现模块的属性、事件及模块依赖
(2)默认仓库
提供了完善的数据库操作方法
(3)工作单元
- 默认工作单元
Some methods are unit of work methods by default:
All MVC, Web API and ASP.NET Core MVC Controller actions.
All Application Service methods.
All Repository methods.
- 使用特性
[UnitOfWork]
(4)多语言
-
多数据源
支持Json、XML、Resource、自定义数据源
-
满足各种使用场景
Class、Razor View、JS
(5)自动映射
[AutoMapTo(typeof(User))]
[AutoMapFrom(typeof(UserDto))]
[AutoMap]
(6)动态API
直接将“应用服务层”的方法生成Restful API进行暴露
(7)统一返回结果
效果
{ "result": { ... }, "targetUrl": null, "success": true, "error": null, "unAuthorizedRequest": false, "__abp": true }
模型类
(8)...
异常处理、动态JS代理等
二、ABP模块化-返回结果分析
1、Startup注册ABP模块化服务
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { //此处省略其它注册服务 ... //Configure Abp and Dependency Injection return services.AddAbp<WebApiModule>(options => { //Configure Log4Net logging options.IocManager.IocContainer.AddFacility<LoggingFacility>( f => f.UseAbpLog4Net().WithConfig("log4net.config") ); });
第一个模块化类
[DependsOn( typeof(WebCoreModule))] public class WebApiModule: AbpModule { private readonly IConfigurationRoot _appConfiguration; public WebApiModule(IWebHostEnvironment env) { _appConfiguration = AppConfigurations.Get(env.ContentRootPath, env.EnvironmentName); }
2、针对AbpModule的服务容器扩展
调用MvcOptions的扩展
3、MvcOptions的扩展
添加了结果过滤器Action Result Filter
4、结果过滤器
5、包装器工厂
6、包装器
7、统一的返回结果
三、参考
-
ABP官网
https://aspnetboilerplate.com/Pages/Documents/Introduction
内容总结
以上是互联网集市为您收集整理的ASP.NET Core实践:ABP模块化&统一返回结果全部内容,希望文章能够帮你解决ASP.NET Core实践:ABP模块化&统一返回结果所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。