最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Asp.Net Core Web Api最佳實(shí)踐

2023-04-23 20:14 作者:zgcdboy  | 我要投稿
  • 控制器使用屬性:ApiController

  • 控制器使用屬性:Attribute Routing

  • 模型校驗(yàn):Model Validation

  • Minimize Controller Size

  • Use Filters to Apply Policies:緩存、模型校驗(yàn)、統(tǒng)一異常處理、統(tǒng)一返回結(jié)果類型

  • async / await

  • Response Caching

  • Response Compression

  • Content Negotiation

  • Default Exception Handler

  • ActionResult<T>

  • ControllBase Base Class

Minimize Controller Size

Keep Controllers Small and Easy to Manage

  • Minimize logic in action methods

    • Replace duplicate logic with filters

    • Avoid business logic

    • Avoid data access logic

  • Avoid try-catch

  • Large controllers tend to:

    • Lack cohesion

    • Geteven larger over time

    • Have more total dependencies and coupling

User Filters and Middleware

Repetitive code in actions/endpoints can be refactored into filters

if it doesn't need MVC details, can user middleward instead

Filters/Middleward == Consistent Policy

  • Model Validation([ApiController])

  • Exception Middleware and Logging

  • Analytics

Response Caching

[ResponseCache] adds cache headers

  • Used by Clients

  • Used by intermediate proxies

  • Not stored on the server by default

  • Abides by RFC 7234 on HTTP Caching

Add Response Caching Middleward

  • Supports VaryByParam options

  • Stores responses in server memory


Response Compression

Rely on Server Compression by default

  • IIS,IIS Express support compression by default

Dot't Commpress Small Responses

  • Less than 1000 bytes typically not worth it

Respect Clinet Accept-Encoding Header

  • Send Content-Encoding Header with response

Use caution with compression and HTTPS

Configuring Content Negotiation(按客戶端要求返回類型:xml,json)

Configuring Exception Handlers

Production Error Handler

Development Error Handler

Minimal APl Swagger Integration


Asp.Net Core Web Api最佳實(shí)踐的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
广西| 周至县| 高邮市| 沙坪坝区| 桦甸市| 富蕴县| 北流市| 金门县| 曲沃县| 姚安县| 元阳县| 措美县| 将乐县| 安康市| 双柏县| 团风县| 穆棱市| 尼玛县| 东乡族自治县| 中山市| 沙河市| 光山县| 海阳市| 扶风县| 波密县| 扎兰屯市| 雷山县| 桐乡市| 毕节市| 碌曲县| 特克斯县| 灵山县| 新营市| 苗栗县| 石楼县| 长葛市| 平度市| 梁河县| 肃南| 扎鲁特旗| 廉江市|