Abp Tips - How to set the global property DontWrapResult

demo Institute Add

GitHub related demo address:
to explain demo, non-abp official website template, use Visual Studio 2019 to create the asp.net core 2.2 webapiproject, the introduction of Abp.AspNetCore package, simply transform the look.

Adaptation Abp

Simple enumeration transformation steps:

  1. Initialize the project
  2. Abp.AspNetCore introduced by nuget
  3. Create a module
  4. Transformation Startup
  5. Controller needs to inherit AbpController

After the transformation is complete in accordance with the above steps, operating site, to return the following results (in order to facilitate viewing of json been formatted string returned)

{
  "result": [
    "value1",
    "value2"
  ],
  "targetUrl": null,
  "success": true,
  "error": null,
  "unAuthorizedRequest": false,
  "__abp": true
}

WrapResult and DontWrapResult

And using properties WrapResult DontWrapResult control whether or Action Controller process. By default, the package will return a result, the package as a result. [DontWrapResult]Equivalent [WrapResult(WrapOnSuccess = false, WrapOnError = false)].
For me, I do not want to get clean return, do not need any package. Then I can just add the Controller and Action [DontWrapResult], shielding package. Each did not want to add a Controller or Action, are added to the property? You need global configuration Configuration.Modules.AbpAspNetCore().
Configuration is as follows

var result = new DontWrapResultAttribute();
Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnError = result.WrapOnError;
Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnSuccess = result.WrapOnSuccess;

For details, see: How Global WrapResult

After global configuration, return the following

[
  "value1",
  "value2"
]

Guess you like

Origin www.cnblogs.com/AlienXu/p/11202541.html