You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
46 KiB
JavaScript
1 line
46 KiB
JavaScript
"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[8132],{904:(n,e,i)=>{i.r(e),i.d(e,{assets:()=>a,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>p,toc:()=>d});var s=i(5893),r=i(1151),o=(i(4996),i(4866)),t=i(5162);const l={id:"options",title:"4.2 \u9009\u9879",sidebar_label:"4.2 \u9009\u9879",description:"\u914d\u7f6e\u4e5f\u53ef\u4ee5\u8fdb\u884c OOP \u64cd\u4f5c"},c=void 0,p={id:"options",title:"4.2 \u9009\u9879",description:"\u914d\u7f6e\u4e5f\u53ef\u4ee5\u8fdb\u884c OOP \u64cd\u4f5c",source:"@site/docs/options.mdx",sourceDirName:".",slug:"/options",permalink:"/docs/options",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/options.mdx",tags:[],version:"current",lastUpdatedBy:"\u67e0\u6aac\u82cf\u6253",lastUpdatedAt:1681124070,formattedLastUpdatedAt:"Apr 10, 2023",frontMatter:{id:"options",title:"4.2 \u9009\u9879",sidebar_label:"4.2 \u9009\u9879",description:"\u914d\u7f6e\u4e5f\u53ef\u4ee5\u8fdb\u884c OOP \u64cd\u4f5c"},sidebar:"docs",previous:{title:"4.1 \u914d\u7f6e",permalink:"/docs/configuration"},next:{title:"5. Web \u5e94\u7528\u5f00\u53d1",permalink:"/docs/category/web"}},a={},d=[{value:"4.2.1 \u4ec0\u4e48\u662f\u9009\u9879",id:"421-\u4ec0\u4e48\u662f\u9009\u9879",level:2},{value:"4.2.2 \u4e0e\u914d\u7f6e\u7684\u533a\u522b",id:"422-\u4e0e\u914d\u7f6e\u7684\u533a\u522b",level:2},{value:"4.2.3 \u9009\u9879\u7684\u4f7f\u7528",id:"423-\u9009\u9879\u7684\u4f7f\u7528",level:2},{value:"4.2.3.1 \u914d\u7f6e <code>appsettings.json</code> \u4fe1\u606f",id:"4231-\u914d\u7f6e-appsettingsjson-\u4fe1\u606f",level:3},{value:"4.2.3.2 \u521b\u5efa <code>AppInfoOptions</code> \u5f3a\u7c7b\u578b\u7c7b",id:"4232-\u521b\u5efa-appinfooptions-\u5f3a\u7c7b\u578b\u7c7b",level:3},{value:"4.2.3.3 \u6ce8\u518c <code>AppInfoOptions</code> \u670d\u52a1",id:"4233-\u6ce8\u518c-appinfooptions-\u670d\u52a1",level:3},{value:"4.2.3.4 \u8bfb\u53d6 <code>AppInfoOptions</code> \u4fe1\u606f",id:"4234-\u8bfb\u53d6-appinfooptions-\u4fe1\u606f",level:3},{value:"4.2.3.5 \u5982\u4f55\u9009\u62e9\u8bfb\u53d6\u65b9\u5f0f",id:"4235-\u5982\u4f55\u9009\u62e9\u8bfb\u53d6\u65b9\u5f0f",level:3},{value:"4.2.4 \u9009\u9879\u63a5\u53e3\u8bf4\u660e",id:"424-\u9009\u9879\u63a5\u53e3\u8bf4\u660e",level:2},{value:"4.2.5 \u9009\u9879\u81ea\u5b9a\u4e49\u914d\u7f6e",id:"425-\u9009\u9879\u81ea\u5b9a\u4e49\u914d\u7f6e",level:2},{value:"4.2.5.1 \u9009\u9879\u67e5\u627e\u952e\u6d41\u7a0b",id:"4251-\u9009\u9879\u67e5\u627e\u952e\u6d41\u7a0b",level:3},{value:"4.2.6 <code>[OptionsSettings]</code> \u8bf4\u660e",id:"426-optionssettings-\u8bf4\u660e",level:2},{value:"4.2.7 \u9009\u9879\u9a8c\u8bc1",id:"427-\u9009\u9879\u9a8c\u8bc1",level:2},{value:"4.2.8 \u9009\u9879\u540e\u671f\u914d\u7f6e",id:"428-\u9009\u9879\u540e\u671f\u914d\u7f6e",level:2},{value:"4.2.9 \u9009\u9879\u66f4\u6539\u901a\u77e5\uff08<code>\u70ed\u66f4\u65b0</code>\uff09",id:"429-\u9009\u9879\u66f4\u6539\u901a\u77e5\u70ed\u66f4\u65b0",level:2},{value:"4.2.9.1 \u5173\u4e8e\u591a\u6b21\u89e6\u53d1\u95ee\u9898",id:"4291-\u5173\u4e8e\u591a\u6b21\u89e6\u53d1\u95ee\u9898",level:3},{value:"4.2.10 \u9009\u9879\u7684\u4f18\u7f3a\u70b9",id:"4210-\u9009\u9879\u7684\u4f18\u7f3a\u70b9",level:2},{value:"4.2.11 \u81ea\u5b9a\u4e49\u5c5e\u6027 <code>Key</code> \u6620\u5c04",id:"4211-\u81ea\u5b9a\u4e49\u5c5e\u6027-key-\u6620\u5c04",level:2},{value:"4.2.12 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"4212-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function u(n){const e={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.a)(),...n.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e.h2,{id:"421-\u4ec0\u4e48\u662f\u9009\u9879",children:"4.2.1 \u4ec0\u4e48\u662f\u9009\u9879"}),"\n",(0,s.jsxs)(e.p,{children:["\u9009\u9879\u662f ",(0,s.jsx)(e.code,{children:"ASP.NET Core"})," \u63a8\u8350\u7684\u52a8\u6001\u8bfb\u53d6\u914d\u7f6e\u7684\u65b9\u5f0f\uff0c\u8fd9\u79cd\u65b9\u5f0f\u5c06\u914d\u7f6e\u6587\u4ef6\u6570\u636e\u7528\u4e00\u4e2a",(0,s.jsx)(e.strong,{children:"\u5f3a\u7c7b\u578b"}),"\u6765\u6258\u7ba1\uff0c\u80fd\u591f\u5b9e\u73b0\u914d\u7f6e\u9a8c\u8bc1\u3001\u9ed8\u8ba4\u503c\u914d\u7f6e\u3001\u5b9e\u65f6\u8bfb\u53d6\u7b49\u529f\u80fd\u3002"]}),"\n",(0,s.jsx)(e.h2,{id:"422-\u4e0e\u914d\u7f6e\u7684\u533a\u522b",children:"4.2.2 \u4e0e\u914d\u7f6e\u7684\u533a\u522b"}),"\n",(0,s.jsx)(e.p,{children:"\u9009\u9879\u5b9e\u9645\u4e0a\u4e5f\u662f\u914d\u7f6e\uff0c\u4f46\u5728\u540e\u8005\u7684\u57fa\u7840\u4e0a\u6dfb\u52a0\u4e86\u914d\u7f6e\u9a8c\u8bc1\u3001\u9ed8\u8ba4\u503c/\u540e\u671f\u914d\u7f6e\u8bbe\u5b9a\u53ca\u63d0\u4f9b\u4e86\u591a\u79cd\u63a5\u53e3\u8bfb\u53d6\u914d\u7f6e\u4fe1\u606f\uff0c\u540c\u65f6\u8fd8\u652f\u6301\u4f9b\u914d\u7f6e\u66f4\u6539\u901a\u77e5\u7b49\u5f3a\u5927\u7075\u6d3b\u529f\u80fd\u3002"}),"\n",(0,s.jsxs)(e.p,{children:["\u6240\u4ee5\uff0c\u9664\u4e86\u4e00\u6b21\u6027\u8bfb\u53d6\u4f7f\u7528\u7684\u914d\u7f6e\u4ee5\u5916\uff0c\u90fd\u5e94\u8be5\u9009\u7528 ",(0,s.jsx)(e.strong,{children:"\u9009\u9879"})," \u66ff\u6362 ",(0,s.jsx)(e.strong,{children:"\u914d\u7f6e"}),"\u3002"]}),"\n",(0,s.jsx)(e.admonition,{title:"\u77e5\u8bc6\u5bfc\u822a",type:"tip",children:(0,s.jsxs)(e.p,{children:["\u6709\u5173\u914d\u7f6e\u8bf4\u660e\u53ef\u67e5\u770b\u300a",(0,s.jsx)(e.a,{href:"/docs/configuration",children:"4.1 \u914d\u7f6e"}),"\u300b \u7ae0\u8282\u3002"]})}),"\n",(0,s.jsx)(e.h2,{id:"423-\u9009\u9879\u7684\u4f7f\u7528",children:"4.2.3 \u9009\u9879\u7684\u4f7f\u7528"}),"\n",(0,s.jsxs)(e.p,{children:["\u5047\u8bbe\u6211\u4eec\u9700\u8981\u5728\u7cfb\u7edf\u8fd0\u884c\u65f6\u83b7\u53d6",(0,s.jsx)(e.strong,{children:"\u7cfb\u7edf\u540d\u79f0\u3001\u7248\u672c\u53f7\u53ca\u7248\u6743\u4fe1\u606f"}),"\uff0c\u8fd9\u4e9b\u4fe1\u606f\u53ef\u80fd\u968f\u65f6\u53d8\u5316\u800c\u4e14\u9700\u8981\u5728\u591a\u4e2a\u5730\u65b9\u4f7f\u7528\u3002\u8fd9\u65f6\u5c31\u9700\u8981\u5c06\u8fd9\u4e9b\u4fe1\u606f\u914d\u7f6e\u8d77\u6765\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a"]}),"\n",(0,s.jsxs)(e.h3,{id:"4231-\u914d\u7f6e-appsettingsjson-\u4fe1\u606f",children:["4.2.3.1 \u914d\u7f6e ",(0,s.jsx)(e.code,{children:"appsettings.json"})," \u4fe1\u606f"]}),"\n",(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-json",metastring:"showLineNumbers {2-6}",children:'{\r\n "AppInfo": {\r\n "Name": "Furion",\r\n "Version": "1.0.0",\r\n "Company": "Baiqian"\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(e.h3,{id:"4232-\u521b\u5efa-appinfooptions-\u5f3a\u7c7b\u578b\u7c7b",children:["4.2.3.2 \u521b\u5efa ",(0,s.jsx)(e.code,{children:"AppInfoOptions"})," \u5f3a\u7c7b\u578b\u7c7b"]}),"\n",(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {1,5}",children:"using Furion.ConfigurableOptions;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class AppInfoOptions : IConfigurableOptions\r\n {\r\n public string Name { get; set; }\r\n public string Version { get; set; }\r\n public string Company { get; set; }\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(e.admonition,{title:"\u6e29\u99a8\u63d0\u793a",type:"note",children:[(0,s.jsxs)(e.p,{children:["\u5efa\u8bae\u6240\u6709\u9009\u9879\u7c7b\u90fd\u5e94\u8be5\u4ee5 ",(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"Options"})})," \u547d\u540d\u7ed3\u5c3e\u3002"]}),(0,s.jsxs)(e.p,{children:["\u53e6\u5916\uff0c",(0,s.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e86\u975e\u5e38\u7075\u6d3b\u7684\u6ce8\u518c\u9009\u9879\u670d\u52a1\u7684\u65b9\u6cd5\uff0c\u53ea\u9700\u8981\u7ee7\u627f ",(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"IConfigurableOptions"})})," \u63a5\u53e3\u5373\u53ef\uff0c\u8be5\u63a5\u53e3\u4f4d\u4e8e ",(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"Furion.ConfigurableOptions"})})," \u547d\u540d\u7a7a\u95f4\u4e0b\u3002"]})]}),"\n",(0,s.jsxs)(e.h3,{id:"4233-\u6ce8\u518c-appinfooptions-\u670d\u52a1",children:["4.2.3.3 \u6ce8\u518c ",(0,s.jsx)(e.code,{children:"AppInfoOptions"})," \u670d\u52a1"]}),"\n",(0,s.jsx)(e.p,{children:(0,s.jsx)(e.strong,{children:"\u9009\u9879\u4e0d\u540c\u4e8e\u914d\u7f6e\uff0c\u9700\u5728\u5e94\u7528\u542f\u52a8\u65f6\u6ce8\u518c"})}),"\n",(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:'showLineNumbers {12} title="Furion.Web.Core\\FurWebCoreStartup.cs"',children:"using Microsoft.AspNetCore.Builder;\r\nusing Microsoft.AspNetCore.Hosting;\r\nusing Microsoft.Extensions.DependencyInjection;\r\n\r\nnamespace Furion.Web.Core\r\n{\r\n [AppStartup(800)]\r\n public sealed class FurWebCoreStartup : AppStartup\r\n {\r\n public void ConfigureServices(IServiceCollection services)\r\n {\r\n services.AddConfigurableOptions<AppInfoOptions>();\r\n }\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(e.h3,{id:"4234-\u8bfb\u53d6-appinfooptions-\u4fe1\u606f",children:["4.2.3.4 \u8bfb\u53d6 ",(0,s.jsx)(e.code,{children:"AppInfoOptions"})," \u4fe1\u606f"]}),"\n",(0,s.jsxs)(e.p,{children:["\u5728 ",(0,s.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u4e2d\uff0c\u63d0\u4f9b\u4e86\u591a\u79cd\u8bfb\u53d6\u65b9\u5f0f\uff1a"]}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u901a\u8fc7 ",(0,s.jsx)(e.code,{children:"App.GetConfig<TOptions>(path)"})," \u8bfb\u53d6\uff08",(0,s.jsx)(e.strong,{children:"\u4e0d\u63a8\u8350"}),"\uff09"]}),"\n",(0,s.jsxs)(e.li,{children:["\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165\u4ee5\u4e0b\u5b9e\u4f8b\u8bfb\u53d6\uff1a","\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsx)(e.li,{children:(0,s.jsx)(e.code,{children:"IOptions<TOptions>"})}),"\n",(0,s.jsx)(e.li,{children:(0,s.jsx)(e.code,{children:"IOptionsSnapshot<TOptions>"})}),"\n",(0,s.jsx)(e.li,{children:(0,s.jsx)(e.code,{children:"IOptionsMonitor<TOptions>"})}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(e.li,{children:["\u901a\u8fc7 ",(0,s.jsx)(e.code,{children:"App"})," \u9759\u6001\u7c7b\u63d0\u4f9b\u7684\u9759\u6001\u65b9\u6cd5\u83b7\u53d6\uff1a","\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsx)(e.li,{children:(0,s.jsx)(e.code,{children:"App.GetOptions<TOptions>()"})}),"\n",(0,s.jsx)(e.li,{children:(0,s.jsx)(e.code,{children:"App.GetOptionsMonitor<TOptions>()"})}),"\n",(0,s.jsx)(e.li,{children:(0,s.jsx)(e.code,{children:"App.GetOptionsSnapshot<TOptions>()"})}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(e.admonition,{title:"\u7279\u522b\u6ce8\u610f",type:"warning",children:(0,s.jsxs)(e.p,{children:["\u7981\u6b62\u5728\u4e3b\u673a\u542f\u52a8\u65f6\u901a\u8fc7 ",(0,s.jsx)(e.code,{children:"App.GetOptions<TOptions>"})," \u83b7\u53d6\u9009\u9879\uff0c\u5982\u9700\u83b7\u53d6\u914d\u7f6e\u9009\u9879\u7406\u5e94\u901a\u8fc7 ",(0,s.jsx)(e.code,{children:'App.GetConfig<TOptions>("\u914d\u7f6e\u8282\u70b9", true)'}),"\u3002"]})}),"\n",(0,s.jsxs)(o.Z,{defaultValue:"App.GetConfig<TOptions>(path)",values:[{label:"App.GetConfig<TOptions>(path)",value:"App.GetConfig<TOptions>(path)"},{label:"\u4f9d\u8d56\u6ce8\u5165\u65b9\u5f0f",value:"\u4f9d\u8d56\u6ce8\u5165\u65b9\u5f0f"},{label:"App.GetOptions<TOptions>()",value:"App.GetOptions<TOptions>()"}],children:[(0,s.jsx)(t.Z,{value:"App.GetConfig<TOptions>(path)",children:(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {13-16}",children:'using Furion.Application;\r\nusing Microsoft.AspNetCore.Mvc;\r\n\r\nnamespace Furion.Web.Entry.Controllers\r\n{\r\n [Route("api/[controller]")]\r\n public class DefaultController : ControllerBase\r\n {\r\n [HttpGet]\r\n public string Get()\r\n {\r\n // \u4e0d\u63a8\u8350\u91c7\u7528\u6b64\u65b9\u5f0f\u8bfb\u53d6\uff0c\u8be5\u65b9\u5f0f\u4ec5\u5728 ConfigureServices \u542f\u52a8\u65f6\u4f7f\u7528\r\n var appInfo = App.GetConfig<AppInfoOptions>("AppInfo", true);\r\n return $@"\u540d\u79f0\uff1a{appInfo.Name}\uff0c\r\n \u7248\u672c\uff1a{appInfo.Version}\uff0c\r\n \u516c\u53f8\uff1a{appInfo.Company}";\r\n }\r\n }\r\n}\n'})})}),(0,s.jsx)(t.Z,{value:"\u4f9d\u8d56\u6ce8\u5165\u65b9\u5f0f",children:(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {3,15-17,27-29,31-33,35-37}",children:'using Furion.Application;\r\nusing Microsoft.AspNetCore.Mvc;\r\nusing Microsoft.Extensions.Options;\r\n\r\nnamespace Furion.Web.Entry.Controllers\r\n{\r\n [Route("api/[controller]")]\r\n public class DefaultController : ControllerBase\r\n {\r\n private readonly AppInfoOptions options1;\r\n private readonly AppInfoOptions options2;\r\n private readonly AppInfoOptions options3;\r\n\r\n public DefaultController(\r\n IOptions<AppInfoOptions> options\r\n , IOptionsSnapshot<AppInfoOptions> optionsSnapshot\r\n , IOptionsMonitor<AppInfoOptions> optionsMonitor)\r\n {\r\n options1 = options.Value;\r\n options2 = optionsSnapshot.Value;\r\n options3 = optionsMonitor.CurrentValue;\r\n }\r\n\r\n [HttpGet]\r\n public string Get()\r\n {\r\n var info1 = $@"\u540d\u79f0\uff1a{options1.Name}\uff0c\r\n \u7248\u672c\uff1a{options1.Version}\uff0c\r\n \u516c\u53f8\uff1a{options1.Company}";\r\n\r\n var info2 = $@"\u540d\u79f0\uff1a{options2.Name}\uff0c\r\n \u7248\u672c\uff1a{options2.Version}\uff0c\r\n \u516c\u53f8\uff1a{options2.Company}";\r\n\r\n var info3 = $@"\u540d\u79f0\uff1a{options3.Name}\uff0c\r\n \u7248\u672c\uff1a{options3.Version}\uff0c\r\n \u516c\u53f8\uff1a{options3.Company}";\r\n\r\n return $"{info1}-{info2}-{info3}";\r\n }\r\n }\r\n}\n'})})}),(0,s.jsx)(t.Z,{value:"App.GetOptions<TOptions>()",children:(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {12-15,17-20,22-25}",children:'using Furion.Application;\r\nusing Microsoft.AspNetCore.Mvc;\r\n\r\nnamespace Furion.Web.Entry.Controllers\r\n{\r\n [Route("api/[controller]")]\r\n public class DefaultController : ControllerBase\r\n {\r\n [HttpGet]\r\n public string Get()\r\n {\r\n var options1 = App.GetOptions<AppInfoOptions>();\r\n var info1 = $@"\u540d\u79f0\uff1a{options1.Name}\uff0c\r\n \u7248\u672c\uff1a{options1.Version}\uff0c\r\n \u516c\u53f8\uff1a{options1.Company}";\r\n\r\n var options2 = App.GetOptionsSnapshot<AppInfoOptions>();\r\n var info2 = $@"\u540d\u79f0\uff1a{options2.Name}\uff0c\r\n \u7248\u672c\uff1a{options2.Version}\uff0c\r\n \u516c\u53f8\uff1a{options2.Company}";\r\n\r\n var options3 = App.GetOptionsMonitor<AppInfoOptions>();\r\n var info3 = $@"\u540d\u79f0\uff1a{options3.Name}\uff0c\r\n \u7248\u672c\uff1a{options3.Version}\uff0c\r\n \u516c\u53f8\uff1a{options3.Company}";\r\n\r\n return $"{info1}-{info2}-{info3}";\r\n }\r\n }\r\n}\n'})})})]}),"\n",(0,s.jsx)(e.h3,{id:"4235-\u5982\u4f55\u9009\u62e9\u8bfb\u53d6\u65b9\u5f0f",children:"4.2.3.5 \u5982\u4f55\u9009\u62e9\u8bfb\u53d6\u65b9\u5f0f"}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u5982\u679c\u9009\u9879\u9700\u8981\u5728\u591a\u4e2a\u5730\u65b9\u4f7f\u7528\uff0c\u5219\u65e0\u8bba\u4efb\u4f55\u65f6\u5019\u90fd\u4e0d\u63a8\u8350\u4f7f\u7528 ",(0,s.jsx)(e.code,{children:"App.GetOptions<TOptions>()"})]}),"\n",(0,s.jsxs)(e.li,{children:["\u5728\u53ef\u4f9d\u8d56\u6ce8\u5165\u7c7b\u4e2d\uff0c\u4f9d\u8d56\u6ce8\u5165 ",(0,s.jsx)(e.code,{children:"IOptions[Snapshot|Monitor]<TOptions>"})," \u8bfb\u53d6"]}),"\n",(0,s.jsxs)(e.li,{children:["\u5728\u9759\u6001\u7c7b/\u975e\u4f9d\u8d56\u6ce8\u5165\u7c7b\u4e2d\uff0c\u9009\u62e9 ",(0,s.jsx)(e.code,{children:"App.GetOptions[Snapshot|Monitor]<TOptions>()"})," \u8bfb\u53d6"]}),"\n"]}),"\n",(0,s.jsx)(e.h2,{id:"424-\u9009\u9879\u63a5\u53e3\u8bf4\u660e",children:"4.2.4 \u9009\u9879\u63a5\u53e3\u8bf4\u660e"}),"\n",(0,s.jsxs)(e.p,{children:[(0,s.jsx)(e.code,{children:"ASP.NET Core"})," \u5e94\u7528\u63d0\u4f9b\u4e86\u591a\u79cd\u8bfb\u53d6\u9009\u9879\u7684\u63a5\u53e3\uff1a"]}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:[(0,s.jsx)(e.code,{children:"IOptions<TOptions>"}),"\uff1a","\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u4e0d\u652f\u6301\uff1a","\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsx)(e.li,{children:"\u5728\u5e94\u7528\u542f\u52a8\u540e\u8bfb\u53d6\u914d\u7f6e\u6570\u636e"}),"\n",(0,s.jsx)(e.li,{children:"\u547d\u540d\u9009\u9879"}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(e.li,{children:"\u6ce8\u518c\u4e3a\u5355\u4e00\u5b9e\u4f8b\u4e14\u53ef\u4ee5\u6ce8\u5165\u5230\u4efb\u4f55\u670d\u52a1\u751f\u5b58\u671f"}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(e.li,{children:[(0,s.jsx)(e.code,{children:"IOptionsSnapshot<TOptions>"}),"\uff1a","\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsx)(e.li,{children:"\u5728\u6bcf\u6b21\u8bf7\u6c42\u65f6\u5e94\u91cd\u65b0\u8ba1\u7b97\u9009\u9879\u7684\u65b9\u6848\u4e2d\u6709\u7528"}),"\n",(0,s.jsx)(e.li,{children:"\u6ce8\u518c\u4e3a\u8303\u56f4\u5185\uff0c\u56e0\u6b64\u65e0\u6cd5\u6ce8\u5165\u5230\u5355\u4e00\u5b9e\u4f8b\u670d\u52a1"}),"\n",(0,s.jsx)(e.li,{children:"\u652f\u6301\u547d\u540d\u9009\u9879"}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(e.li,{children:[(0,s.jsx)(e.code,{children:"IOptionsMonitor<TOptions>"}),"\uff1a","\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsx)(e.li,{children:"\u7528\u4e8e\u68c0\u7d22\u9009\u9879\u5e76\u7ba1\u7406 TOptions \u5b9e\u4f8b\u7684\u9009\u9879\u901a\u77e5\u3002"}),"\n",(0,s.jsx)(e.li,{children:"\u6ce8\u518c\u4e3a\u5355\u4e00\u5b9e\u4f8b\u4e14\u53ef\u4ee5\u6ce8\u5165\u5230\u4efb\u4f55\u670d\u52a1\u751f\u5b58\u671f\u3002"}),"\n",(0,s.jsxs)(e.li,{children:["\u652f\u6301\uff1a","\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsx)(e.li,{children:"\u66f4\u6539\u901a\u77e5"}),"\n",(0,s.jsx)(e.li,{children:"\u547d\u540d\u9009\u9879"}),"\n",(0,s.jsx)(e.li,{children:"\u53ef\u91cd\u8f7d\u914d\u7f6e"}),"\n",(0,s.jsxs)(e.li,{children:["\u9009\u62e9\u6027\u9009\u9879\u5931\u6548 ",(0,s.jsx)(e.code,{children:"(IOptionsMonitorCache<TOptions>)"})]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(e.admonition,{title:"\u6ce8\u610f\u4e8b\u9879",type:"warning",children:(0,s.jsxs)(e.p,{children:["\u5728\u4f7f\u7528 ",(0,s.jsx)(e.code,{children:"IConfigurableOptionsListener"})," \u76d1\u542c\u9009\u9879\u540e\uff0c\u5982\u8981\u83b7\u53d6\u6700\u65b0\u7684\u914d\u7f6e\u4fe1\u606f\uff0c\u8bf7\u4f7f\u7528 ",(0,s.jsx)(e.code,{children:"App.GetOptionsMonitor<TOptions>()"})," \u800c\u4e0d\u662f ",(0,s.jsx)(e.code,{children:"App.GetOptions<TOptions>()"}),"\u3002"]})}),"\n",(0,s.jsx)(e.admonition,{title:"\u4e86\u89e3\u66f4\u591a",type:"note",children:(0,s.jsxs)(e.p,{children:["\u60f3\u4e86\u89e3\u66f4\u591a ",(0,s.jsx)(e.code,{children:"\u9009\u9879\u63a5\u53e3"})," \u77e5\u8bc6\u53ef\u67e5\u9605 ",(0,s.jsx)(e.a,{href:"https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration/options?view=aspnetcore-5.0#options-interfaces",children:"ASP.NET Core - \u9009\u9879 - \u9009\u9879\u63a5\u53e3"})," \u5c0f\u8282\u3002"]})}),"\n",(0,s.jsx)(e.h2,{id:"425-\u9009\u9879\u81ea\u5b9a\u4e49\u914d\u7f6e",children:"4.2.5 \u9009\u9879\u81ea\u5b9a\u4e49\u914d\u7f6e"}),"\n",(0,s.jsxs)(e.p,{children:["\u6211\u4eec\u77e5\u9053\uff0c\u9009\u9879\u5b9e\u9645\u4e0a\u9700\u8981\u548c\u914d\u7f6e\u6587\u4ef6\u7279\u5b9a\u952e\u503c\u6302\u94a9\uff0c\u90a3 ",(0,s.jsx)(e.code,{children:"Furion"})," \u662f\u5982\u4f55\u51c6\u786e\u7684\u627e\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u952e\u503c\u7684\u5462\uff1f"]}),"\n",(0,s.jsx)(e.h3,{id:"4251-\u9009\u9879\u67e5\u627e\u952e\u6d41\u7a0b",children:"4.2.5.1 \u9009\u9879\u67e5\u627e\u952e\u6d41\u7a0b"}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:[(0,s.jsxs)(e.strong,{children:["\u6ca1\u6709\u8d34 ",(0,s.jsx)(e.code,{children:"[OptionsSettings]"})," \u7279\u6027"]}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u4ee5 ",(0,s.jsx)(e.code,{children:"Options"})," \u7ed3\u5c3e\uff0c\u5219\u53bb\u9664 ",(0,s.jsx)(e.code,{children:"Options"})," \u5b57\u7b26\u4e32"]}),"\n",(0,s.jsxs)(e.li,{children:["\u5426\u5219\u8fd4\u56de ",(0,s.jsx)(e.code,{children:"\u7c7b\u540d\u79f0"})]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(e.li,{children:[(0,s.jsxs)(e.strong,{children:["\u8d34\u4e86 ",(0,s.jsx)(e.code,{children:"[OptionsSettings]"})," \u7279\u6027"]}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u5982\u679c\u914d\u7f6e\u4e86 ",(0,s.jsx)(e.code,{children:"Path"})," \u5c5e\u6027\uff0c\u5219\u8fd4\u56de ",(0,s.jsx)(e.code,{children:"Path"})," \u7684\u503c"]}),"\n",(0,s.jsxs)(e.li,{children:["\u5426\u5219\u8fd4\u56de ",(0,s.jsx)(e.code,{children:"\u7c7b\u540d\u79f0"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(o.Z,{defaultValue:"non-optionsettings",values:[{label:"\u65e0[OptionsSettings]",value:"non-optionsettings"},{label:"\u6709[OptionsSettings]",value:"has-optionsettings"}],children:[(0,s.jsxs)(t.Z,{value:"non-optionsettings",children:[(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u4ee5 ",(0,s.jsx)(e.code,{children:"Options"})," \u7ed3\u5c3e\uff0c\u5219\u952e\u540d\u4e3a\uff1a",(0,s.jsx)(e.code,{children:"AppInfo"})]}),"\n"]}),(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {1}",children:"public class AppInfoOptions : IConfigurableOptions\r\n{\r\n public string Name { get; set; }\r\n public string Version { get; set; }\r\n public string Company { get; set; }\r\n}\n"})}),(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u4e0d\u4ee5 ",(0,s.jsx)(e.code,{children:"Options"})," \u7ed3\u5c3e\uff0c\u5219\u952e\u540d\u4e3a\uff1a",(0,s.jsx)(e.code,{children:"AppInfoSettings"})]}),"\n"]}),(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {1}",children:"public class AppInfoSettings : IConfigurableOptions\r\n{\r\n public string Name { get; set; }\r\n public string Version { get; set; }\r\n public string Company { get; set; }\r\n}\n"})})]}),(0,s.jsxs)(t.Z,{value:"has-optionsettings",children:[(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u914d\u7f6e\u4e86 ",(0,s.jsx)(e.code,{children:"Path"})," \u5c5e\u6027\uff0c\u5219\u952e\u540d\u4e3a\uff1a",(0,s.jsx)(e.code,{children:"AppSettings:AppInfo"})]}),"\n"]}),(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {1}",children:'[OptionsSettings("AppSettings:AppInfo")]\r\npublic class AppInfoOptions : IConfigurableOptions\r\n{\r\n public string Name { get; set; }\r\n public string Version { get; set; }\r\n public string Company { get; set; }\r\n}\n'})}),(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u6ca1\u6709\u914d\u7f6e ",(0,s.jsx)(e.code,{children:"Path"})," \u5c5e\u6027\uff0c\uff0c\u5219\u952e\u540d\u4e3a\uff1a",(0,s.jsx)(e.code,{children:"AppInfoSettings"})]}),"\n"]}),(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {1}",children:"[OptionsSettings]\r\npublic class AppInfoSettings : IConfigurableOptions\r\n{\r\n public string Name { get; set; }\r\n public string Version { get; set; }\r\n public string Company { get; set; }\r\n}\n"})})]})]}),"\n",(0,s.jsxs)(e.h2,{id:"426-optionssettings-\u8bf4\u660e",children:["4.2.6 ",(0,s.jsx)(e.code,{children:"[OptionsSettings]"})," \u8bf4\u660e"]}),"\n",(0,s.jsxs)(e.p,{children:["\u9009\u9879\u7c7b\u53ef\u4ee5\u901a\u8fc7 ",(0,s.jsx)(e.code,{children:"[OptionsSettings]"})," \u6765\u914d\u7f6e\u67e5\u627e\u8def\u5f84\u503c\u3002"]}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:[(0,s.jsx)(e.code,{children:"Path"}),"\uff1a\u5bf9\u5e94\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u952e\uff0c\u652f\u6301 ",(0,s.jsx)(e.strong,{children:"\u5206\u5c42\u952e"})," \u5b57\u7b26\u4e32\uff0c\u53c2\u89c1\uff1a\u300a",(0,s.jsx)(e.a,{href:"configuration/#413-%E8%B7%AF%E5%BE%84%E7%AC%A6-%E6%9F%A5%E6%89%BE%E8%8A%82%E7%82%B9",children:"4.1 \u914d\u7f6e - 4.1.3 \u8def\u5f84\u7b26 \u67e5\u627e\u8282\u70b9"}),"\u300b"]}),"\n",(0,s.jsxs)(e.li,{children:[(0,s.jsx)(e.code,{children:"PostConfigureAll"}),"\uff1a\u9009\u9879\u540e\u671f\u914d\u7f6e\uff0c\u9ed8\u8ba4 ",(0,s.jsx)(e.code,{children:"false"}),"\u3002",(0,s.jsx)(e.a,{href:"https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration/options?view=aspnetcore-3.1#options-post-configuration",children:"ASP.NET Core - \u9009\u9879 - \u9009\u9879\u540e\u671f\u914d\u7f6e"})]}),"\n"]}),"\n",(0,s.jsx)(e.h2,{id:"427-\u9009\u9879\u9a8c\u8bc1",children:"4.2.7 \u9009\u9879\u9a8c\u8bc1"}),"\n",(0,s.jsxs)(e.p,{children:["\u9009\u9879\u652f\u6301\u9a8c\u8bc1\u914d\u7f6e\u6709\u6548\u6027\uff0c\u5728 ",(0,s.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u4e2d\uff0c\u901a\u8fc7 ",(0,s.jsx)(e.code,{children:"services.AddConfigurableOptions<TOptions>()"})," \u6ce8\u518c\u9009\u9879\u9ed8\u8ba4\u542f\u7528\u4e86\u9a8c\u8bc1\u652f\u6301\u3002"]}),"\n",(0,s.jsx)(e.p,{children:"\u5305\u62ec\uff1a"}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u7279\u6027\u65b9\u5f0f ",(0,s.jsx)(e.code,{children:"DataAnnotations"})]}),"\n",(0,s.jsxs)(e.li,{children:["\u81ea\u5b9a\u4e49\u590d\u6742\u9a8c\u8bc1 ",(0,s.jsx)(e.code,{children:"IValidateOptions<TOptions>"})]}),"\n"]}),"\n",(0,s.jsxs)(o.Z,{defaultValue:"texin",values:[{label:"\u7279\u6027\u65b9\u5f0f",value:"texin"},{label:"\u590d\u6742\u9a8c\u8bc1",value:"fuza"}],children:[(0,s.jsx)(t.Z,{value:"texin",children:(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {2,8,10,12}",children:'using Furion.ConfigurableOptions;\r\nusing System.ComponentModel.DataAnnotations;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class AppInfoOptions : IConfigurableOptions\r\n {\r\n [Required(ErrorMessage = "\u540d\u79f0\u4e0d\u80fd\u4e3a\u7a7a")]\r\n public string Name { get; set; }\r\n [Required, RegularExpression(@"^[0-9][0-9\\.]+[0-9]$", ErrorMessage = "\u4e0d\u662f\u6709\u6548\u7684\u7248\u672c\u53f7")]\r\n public string Version { get; set; }\r\n [Required, MaxLength(100)]\r\n public string Company { get; set; }\r\n }\r\n}\n'})})}),(0,s.jsxs)(t.Z,{value:"fuza",children:[(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u81ea\u5b9a\u4e49\u9a8c\u8bc1\u7c7b ",(0,s.jsx)(e.code,{children:"AppInfoValidation"})," \u5e76\u7ee7\u627f ",(0,s.jsx)(e.code,{children:"IValidateOptions<TOptions>"})," \u63a5\u53e3\uff0c\u540c\u65f6\u5b9e\u73b0 ",(0,s.jsx)(e.code,{children:"Validate"})," \u65b9\u6cd5\u3002"]}),"\n"]}),(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {1,6,8,12,15}",children:'using Microsoft.Extensions.Options;\r\nusing System.Text.RegularExpressions;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class AppInfoValidation : IValidateOptions<AppInfoOptions>\r\n {\r\n public ValidateOptionsResult Validate(string name, AppInfoOptions options)\r\n {\r\n if (!Regex.IsMatch(options.Version, @"^[0-9][0-9\\.]+[0-9]$"))\r\n {\r\n return ValidateOptionsResult.Fail("\u4e0d\u662f\u6709\u6548\u7684\u7248\u672c\u53f7");\r\n }\r\n\r\n return ValidateOptionsResult.Success;\r\n }\r\n }\r\n}\n'})}),(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\u9009\u9879\u7c7b\u7ee7\u627f ",(0,s.jsx)(e.code,{children:"IConfigurableOptions<TOptions, TOptionsValidation>"})," \u63a5\u53e3\uff0c\u5e76\u5b9e\u73b0\u8be5\u63a5\u53e3\u3002"]}),"\n"]}),(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {6,16-18}",children:'using Furion.ConfigurableOptions;\r\nusing System.ComponentModel.DataAnnotations;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class AppInfoOptions : IConfigurableOptions<AppInfoOptions, AppInfoValidation>\r\n {\r\n [Required(ErrorMessage = "\u540d\u79f0\u4e0d\u80fd\u4e3a\u7a7a")]\r\n public string Name { get; set; }\r\n [Required]\r\n public string Version { get; set; }\r\n [Required, MaxLength(100)]\r\n public string Company { get; set; }\r\n\r\n // \u9009\u9879\u540e\u671f\u914d\u7f6e\r\n public void PostConfigure(AppInfoOptions options, IConfiguration configuration)\r\n {\r\n }\r\n }\r\n}\n'})}),(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsx)(e.li,{children:"\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a"}),"\n"]}),(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {4,9,19,25,27,31,34}",children:'using Furion.ConfigurableOptions;\r\nusing Microsoft.Extensions.Options;\r\nusing System.ComponentModel.DataAnnotations;\r\nusing System.Text.RegularExpressions;\r\n\r\nnamespace Furion.Application\r\n{\r\n // \u7ee7\u627f IConfigurableOptions<TOptions, TOptionsValidation> \u63a5\u53e3\r\n public class AppInfoOptions : IConfigurableOptions<AppInfoOptions, AppInfoValidation>\r\n {\r\n [Required(ErrorMessage = "\u540d\u79f0\u4e0d\u80fd\u4e3a\u7a7a")]\r\n public string Name { get; set; }\r\n [Required]\r\n public string Version { get; set; }\r\n [Required, MaxLength(100)]\r\n public string Company { get; set; }\r\n\r\n // \u9009\u9879\u540e\u671f\u914d\u7f6e\r\n public void PostConfigure(AppInfoOptions options)\r\n {\r\n }\r\n }\r\n\r\n // \u521b\u5efa\u81ea\u5b9a\u4e49\u9a8c\u8bc1\u7c7b\r\n public class AppInfoValidation : IValidateOptions<AppInfoOptions>\r\n {\r\n public ValidateOptionsResult Validate(string name, AppInfoOptions options)\r\n {\r\n if (!Regex.IsMatch(options.Version, @"^[0-9][0-9\\.]+[0-9]$"))\r\n {\r\n return ValidateOptionsResult.Fail("\u4e0d\u662f\u6709\u6548\u7684\u7248\u672c\u53f7");\r\n }\r\n\r\n return ValidateOptionsResult.Success;\r\n }\r\n }\r\n}\n'})})]})]}),"\n",(0,s.jsx)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"note",children:(0,s.jsxs)(e.p,{children:[(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"IConfigurableOptions<TOptions, TOptionsValidation>"})})," \u7ee7\u627f\u81ea ",(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"IConfigurableOptions<TOptions>"})}),"\uff0c\u4e5f\u5c31\u662f\u81ea\u5b9a\u4e49\u590d\u6742\u9a8c\u8bc1\u9ed8\u8ba4\u5177\u6709 ",(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"PostConfigure(TOptions options)"})})," \u9009\u9879\u540e\u671f\u914d\u7f6e\u65b9\u6cd5\u3002\u5173\u4e8e\u300a",(0,s.jsx)(e.a,{href:"#428-%E9%80%89%E9%A1%B9%E5%90%8E%E6%9C%9F%E9%85%8D%E7%BD%AE",children:"4.2.8 \u9009\u9879\u540e\u671f\u914d\u7f6e"}),"\u300b\u5c06\u5728\u4e0b\u4e00\u5c0f\u8282\u8bf4\u660e\u3002"]})}),"\n",(0,s.jsx)(e.h2,{id:"428-\u9009\u9879\u540e\u671f\u914d\u7f6e",children:"4.2.8 \u9009\u9879\u540e\u671f\u914d\u7f6e"}),"\n",(0,s.jsx)(e.p,{children:"\u9009\u9879\u540e\u671f\u914d\u7f6e\u901a\u4fd7\u4e00\u70b9\u6765\u8bf4\uff0c\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u89e3\u6790\u503c\u6216\u8bbe\u5b9a\u9ed8\u8ba4\u503c/\u540e\u671f\u914d\u7f6e\u7b49\u3002"}),"\n",(0,s.jsxs)(e.p,{children:["\u5728 ",(0,s.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u4e2d\uff0c\u914d\u7f6e\u9009\u9879\u540e\u671f\u914d\u7f6e\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u8981\u7ee7\u627f ",(0,s.jsx)(e.code,{children:"IConfigurableOptions<TOptions>"})," \u63a5\u53e3\u5e76\u5b9e\u73b0 ",(0,s.jsx)(e.code,{children:"PostConfigure(TOptions options)"})," \u65b9\u6cd5\u3002"]}),"\n",(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {7,16-21}",children:'using Furion.ConfigurableOptions;\r\nusing Microsoft.Extensions.Configuration;\r\nusing System.ComponentModel.DataAnnotations;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class AppInfoOptions : IConfigurableOptions<AppInfoOptions>\r\n {\r\n [Required(ErrorMessage = "\u540d\u79f0\u4e0d\u80fd\u4e3a\u7a7a")]\r\n public string Name { get; set; }\r\n [Required]\r\n public string Version { get; set; }\r\n [Required, MaxLength(100)]\r\n public string Company { get; set; }\r\n\r\n public void PostConfigure(AppInfoOptions options, IConfiguration configuration)\r\n {\r\n options.Name ??= "Furion";\r\n options.Version ??= "1.0.0";\r\n options.Company ??= "Baiqian";\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsx)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"note",children:(0,s.jsxs)(e.p,{children:[(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"IConfigurableOptions<TOptions, TOptionsValidation>"})})," \u7ee7\u627f\u81ea ",(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"IConfigurableOptions<TOptions>"})}),"\uff0c\u4e5f\u5c31\u662f\u81ea\u5b9a\u4e49\u590d\u6742\u9a8c\u8bc1\u9ed8\u8ba4\u5177\u6709 ",(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"PostConfigure(TOptions options, IConfiguration configuration)"})})," \u9009\u9879\u540e\u671f\u914d\u7f6e\u65b9\u6cd5\u3002"]})}),"\n",(0,s.jsxs)(e.h2,{id:"429-\u9009\u9879\u66f4\u6539\u901a\u77e5\u70ed\u66f4\u65b0",children:["4.2.9 \u9009\u9879\u66f4\u6539\u901a\u77e5\uff08",(0,s.jsx)(e.code,{children:"\u70ed\u66f4\u65b0"}),"\uff09"]}),"\n",(0,s.jsxs)(e.p,{children:[(0,s.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e86\u975e\u5e38\u7b80\u5355\u4e14\u7075\u6d3b\u7684\u65b9\u5f0f\u76d1\u542c\u9009\u9879\u66f4\u6539\uff0c\u4e5f\u5c31\u662f ",(0,s.jsxs)(e.strong,{children:[(0,s.jsx)(e.code,{children:"appsettings.json"})," \u6216 \u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\u53d1\u751f\u4efb\u4f55\u66f4\u6539\u90fd\u4f1a\u89e6\u53d1\u5904\u7406\u65b9\u6cd5"]}),"\u3002"]}),"\n",(0,s.jsxs)(e.p,{children:["\u4f7f\u7528\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u7ee7\u627f ",(0,s.jsx)(e.code,{children:"IConfigurableOptionsListener<TOptions>"})," \u63a5\u53e3\u5e76\u5b9e\u73b0 ",(0,s.jsx)(e.code,{children:"void OnListener(TOptions options, IConfiguration configuration)"})," \u65b9\u6cd5\u5373\u53ef\u3002"]}),"\n",(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {5,11-15}",children:"using Furion.ConfigurableOptions;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class AppInfoOptions : IConfigurableOptionsListener<AppInfoOptions>\r\n {\r\n public string Name { get; set; }\r\n public string Version { get; set; }\r\n public string Company { get; set; }\r\n\r\n public void OnListener(AppInfoOptions options, IConfiguration configuration)\r\n {\r\n var name = options.Name; // \u5b9e\u65f6\u7684\u6700\u65b0\u503c\r\n var version = options.Version; // \u5b9e\u65f6\u7684\u6700\u65b0\u503c\r\n }\r\n\r\n public void PostConfigure(AppInfoOptions options, IConfiguration configuration)\r\n {\r\n }\r\n }\r\n}\n"})}),"\n",(0,s.jsx)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"note",children:(0,s.jsxs)(e.p,{children:[(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"IConfigurableOptionsListener<TOptions>"})})," \u7ee7\u627f\u81ea ",(0,s.jsx)(e.strong,{children:(0,s.jsx)(e.code,{children:"IConfigurableOptions<TOptions>"})}),"\u3002"]})}),"\n",(0,s.jsx)(e.h3,{id:"4291-\u5173\u4e8e\u591a\u6b21\u89e6\u53d1\u95ee\u9898",children:"4.2.9.1 \u5173\u4e8e\u591a\u6b21\u89e6\u53d1\u95ee\u9898"}),"\n",(0,s.jsxs)(e.p,{children:["\u5728 ",(0,s.jsx)(e.code,{children:"Furion"})," \u5e95\u5c42\u4f7f\u7528\u7684\u662f ",(0,s.jsx)(e.code,{children:"ChangeToken.OnChange"})," \u76d1\u542c\u6587\u4ef6\u66f4\u6539\uff0c\u4f46\u662f\u6b64\u65b9\u5f0f\u4f1a\u5bfc\u81f4 ",(0,s.jsx)(e.code,{children:"OnListener"})," \u89e6\u53d1\u4e24\u6b21\uff0c\u8fd9\u5e76\u975e\u662f\u6846\u67b6\u7684 ",(0,s.jsx)(e.code,{children:"bug"}),"\uff0c\u800c\u662f ",(0,s.jsx)(e.code,{children:".NET Core"})," \u672c\u8eab\u5b58\u5728\u7684\u95ee\u9898\uff0c\u8be6\u89c1\uff1a",(0,s.jsx)(e.a,{href:"https://github.com/dotnet/aspnetcore/issues/2542",children:"https://github.com/dotnet/aspnetcore/issues/2542"})]}),"\n",(0,s.jsxs)(e.p,{children:["\u6240\u4ee5\uff0c",(0,s.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u4e5f\u7ed9\u51fa\u53e6\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u53ef\u66ff\u4ee3 ",(0,s.jsx)(e.code,{children:"IConfigurableOptionsListener"})," \u7684\u65b9\u5f0f\uff0c\u4e5f\u5c31\u662f\u901a\u8fc7\u5c40\u90e8\u6ce8\u5165 ",(0,s.jsx)(e.code,{children:"IOptionsMonitor"})," \u7684\u65b9\u5f0f\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {1,3,7,9,14,19}",children:"public class YourService : IYourService, IDisposable\r\n{\r\n private readonly IDisposable _optionsReloadToken;\r\n\r\n private YourOptions _options;\r\n\r\n public YourService(IOptionsMonitor<YourOptions> options)\r\n {\r\n (_optionsReloadToken, _options) = (options.OnChange(ReloadOptions), options.CurrentValue);\r\n }\r\n\r\n private void ReloadOptions(YourOptions options)\r\n {\r\n _options = options;\r\n }\r\n\r\n public void Dispose()\r\n {\r\n _optionsReloadToken?.Dispose();\r\n }\r\n}\n"})}),"\n",(0,s.jsx)(e.p,{children:"\u8fd9\u79cd\u65b9\u5f0f\u867d\u7136\u5570\u55e6\uff0c\u4f46\u662f\u53ef\u4ee5\u5f88\u597d\u548c\u4e1a\u52a1\u4ee3\u7801\u5951\u5408\u3002"}),"\n",(0,s.jsx)(e.h2,{id:"4210-\u9009\u9879\u7684\u4f18\u7f3a\u70b9",children:"4.2.10 \u9009\u9879\u7684\u4f18\u7f3a\u70b9"}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsxs)(e.li,{children:["\n",(0,s.jsx)(e.p,{children:"\u4f18\u70b9"}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsx)(e.li,{children:"\u5f3a\u7c7b\u578b\u914d\u7f6e"}),"\n",(0,s.jsx)(e.li,{children:"\u63d0\u4f9b\u591a\u79cd\u8bfb\u53d6\u65b9\u5f0f"}),"\n",(0,s.jsx)(e.li,{children:"\u652f\u6301\u70ed\u52a0\u8f7d"}),"\n",(0,s.jsx)(e.li,{children:"\u652f\u6301\u8bbe\u7f6e\u9ed8\u8ba4\u503c/\u540e\u671f\u914d\u7f6e"}),"\n",(0,s.jsx)(e.li,{children:"\u652f\u6301\u5728\u8fd0\u884c\u73af\u5883\u4e2d\u52a8\u6001\u914d\u7f6e"}),"\n",(0,s.jsx)(e.li,{children:"\u652f\u6301\u9a8c\u8bc1\u914d\u7f6e\u6709\u6548\u6027"}),"\n",(0,s.jsx)(e.li,{children:"\u652f\u6301\u66f4\u6539\u901a\u77e5"}),"\n",(0,s.jsx)(e.li,{children:"\u652f\u6301\u547d\u540d\u9009\u9879"}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(e.li,{children:["\n",(0,s.jsx)(e.p,{children:"\u7f3a\u70b9"}),"\n",(0,s.jsxs)(e.ul,{children:["\n",(0,s.jsx)(e.li,{children:"\u9700\u8981\u5b9a\u4e49\u5bf9\u5e94\u7c7b\u578b"}),"\n",(0,s.jsx)(e.li,{children:"\u9700\u8981\u5728\u542f\u52a8\u65f6\u6ce8\u518c"}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(e.h2,{id:"4211-\u81ea\u5b9a\u4e49\u5c5e\u6027-key-\u6620\u5c04",children:["4.2.11 \u81ea\u5b9a\u4e49\u5c5e\u6027 ",(0,s.jsx)(e.code,{children:"Key"})," \u6620\u5c04"]}),"\n",(0,s.jsx)(e.admonition,{title:"\u7248\u672c\u8bf4\u660e",type:"important",children:(0,s.jsxs)(e.p,{children:["\u4ee5\u4e0b\u5185\u5bb9\u4ec5\u9650 ",(0,s.jsx)(e.code,{children:"Furion v3.4.3+"})," \u7248\u672c\u4f7f\u7528\u3002"]})}),"\n",(0,s.jsxs)(e.p,{children:["\u6709\u65f6\u5019\u6211\u4eec\u5728 ",(0,s.jsx)(e.code,{children:"appsettings.json"})," \u4e2d\u914d\u7f6e\u7684 ",(0,s.jsx)(e.code,{children:"Key"})," \u548c\u9009\u9879\u5b9a\u4e49\u7684\u5c5e\u6027\u540d\u4e0d\u4e00\u6837\uff0c\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u7528\u5230 ",(0,s.jsx)(e.code,{children:"[MapSettings]"})," \u7279\u6027\u5373\u53ef\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-json",metastring:"showLineNumbers {4}",children:'"AppInfo": {\r\n "Name": "Furion",\r\n "Version": "1.0.0",\r\n "Company_Name": "Baiqian"\r\n}\n'})}),"\n",(0,s.jsx)(e.pre,{children:(0,s.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {6-7}",children:'public class AppInfoOptions : IConfigurableOptions\r\n{\r\n public string Name { get; set; }\r\n public string Version { get; set; }\r\n\r\n [MapSettings("Company_Name")]\r\n public string Company { get; set; }\r\n}\n'})}),"\n",(0,s.jsx)(e.admonition,{title:"\u7279\u522b\u6ce8\u610f",type:"tip",children:(0,s.jsxs)(e.p,{children:[(0,s.jsx)(e.code,{children:"[MapSettings]"})," \u914d\u7f6e\u7684 ",(0,s.jsx)(e.code,{children:"Key"})," \u4f1a\u81ea\u5b9a\u5e94\u7528\u9009\u9879\u7684 ",(0,s.jsx)(e.code,{children:"Key"})," \u4f5c\u4e3a\u8d77\u59cb\u70b9\uff0c\u5982\u5b9e\u9645\u4e0a ",(0,s.jsx)(e.code,{children:"Company"})," \u5c5e\u6027\u5bf9\u5e94\u7684 ",(0,s.jsx)(e.code,{children:"Key"})," \u4e3a\uff1a",(0,s.jsx)(e.code,{children:"AppInfo:Company_Name"}),"\u3002"]})}),"\n",(0,s.jsx)(e.h2,{id:"4212-\u53cd\u9988\u4e0e\u5efa\u8bae",children:"4.2.12 \u53cd\u9988\u4e0e\u5efa\u8bae"}),"\n",(0,s.jsx)(e.admonition,{title:"\u4e0e\u6211\u4eec\u4ea4\u6d41",type:"note",children:(0,s.jsxs)(e.p,{children:["\u7ed9 Furion \u63d0 ",(0,s.jsx)(e.a,{href:"https://gitee.com/dotnetchina/Furion/issues/new?issue",children:"Issue"}),"\u3002"]})}),"\n",(0,s.jsx)(e.hr,{}),"\n",(0,s.jsx)(e.admonition,{title:"\u4e86\u89e3\u66f4\u591a",type:"note",children:(0,s.jsxs)(e.p,{children:["\u60f3\u4e86\u89e3\u66f4\u591a ",(0,s.jsx)(e.code,{children:"\u9009\u9879"})," \u77e5\u8bc6\u53ef\u67e5\u9605 ",(0,s.jsx)(e.a,{href:"https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration/options?view=aspnetcore-5.0",children:"ASP.NET Core - \u9009\u9879"})," \u7ae0\u8282\u3002"]})})]})}function h(n={}){const{wrapper:e}={...(0,r.a)(),...n.components};return e?(0,s.jsx)(e,{...n,children:(0,s.jsx)(u,{...n})}):u(n)}},5162:(n,e,i)=>{i.d(e,{Z:()=>t});i(7294);var s=i(4334);const r={tabItem:"tabItem_Ymn6"};var o=i(5893);function t(n){let{children:e,hidden:i,className:t}=n;return(0,o.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,t),hidden:i,children:e})}},4866:(n,e,i)=>{i.d(e,{Z:()=>I});var s=i(7294),r=i(4334),o=i(2466),t=i(6550),l=i(469),c=i(1980),p=i(7392),a=i(12);function d(n){return s.Children.toArray(n).filter((n=>"\n"!==n)).map((n=>{if(!n||(0,s.isValidElement)(n)&&function(n){const{props:e}=n;return!!e&&"object"==typeof e&&"value"in e}(n))return n;throw new Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof n.type?n.type:n.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(n){const{values:e,children:i}=n;return(0,s.useMemo)((()=>{const n=e??function(n){return d(n).map((n=>{let{props:{value:e,label:i,attributes:s,default:r}}=n;return{value:e,label:i,attributes:s,default:r}}))}(i);return function(n){const e=(0,p.l)(n,((n,e)=>n.value===e.value));if(e.length>0)throw new Error(`Docusaurus error: Duplicate values "${e.map((n=>n.value)).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(n),n}),[e,i])}function h(n){let{value:e,tabValues:i}=n;return i.some((n=>n.value===e))}function x(n){let{queryString:e=!1,groupId:i}=n;const r=(0,t.k6)(),o=function(n){let{queryString:e=!1,groupId:i}=n;if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!i)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return i??null}({queryString:e,groupId:i});return[(0,c._X)(o),(0,s.useCallback)((n=>{if(!o)return;const e=new URLSearchParams(r.location.search);e.set(o,n),r.replace({...r.location,search:e.toString()})}),[o,r])]}function j(n){const{defaultValue:e,queryString:i=!1,groupId:r}=n,o=u(n),[t,c]=(0,s.useState)((()=>function(n){let{defaultValue:e,tabValues:i}=n;if(0===i.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!h({value:e,tabValues:i}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${i.map((n=>n.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const s=i.find((n=>n.default))??i[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:e,tabValues:o}))),[p,d]=x({queryString:i,groupId:r}),[j,g]=function(n){let{groupId:e}=n;const i=function(n){return n?`docusaurus.tab.${n}`:null}(e),[r,o]=(0,a.Nk)(i);return[r,(0,s.useCallback)((n=>{i&&o.set(n)}),[i,o])]}({groupId:r}),f=(()=>{const n=p??j;return h({value:n,tabValues:o})?n:null})();(0,l.Z)((()=>{f&&c(f)}),[f]);return{selectedValue:t,selectValue:(0,s.useCallback)((n=>{if(!h({value:n,tabValues:o}))throw new Error(`Can't select invalid tab value=${n}`);c(n),d(n),g(n)}),[d,g,o]),tabValues:o}}var g=i(2389);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var m=i(5893);function b(n){let{className:e,block:i,selectedValue:s,selectValue:t,tabValues:l}=n;const c=[],{blockElementScrollPositionUntilNextRender:p}=(0,o.o5)(),a=n=>{const e=n.currentTarget,i=c.indexOf(e),r=l[i].value;r!==s&&(p(e),t(r))},d=n=>{let e=null;switch(n.key){case"Enter":a(n);break;case"ArrowRight":{const i=c.indexOf(n.currentTarget)+1;e=c[i]??c[0];break}case"ArrowLeft":{const i=c.indexOf(n.currentTarget)-1;e=c[i]??c[c.length-1];break}}e?.focus()};return(0,m.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":i},e),children:l.map((n=>{let{value:e,label:i,attributes:o}=n;return(0,m.jsx)("li",{role:"tab",tabIndex:s===e?0:-1,"aria-selected":s===e,ref:n=>c.push(n),onKeyDown:d,onClick:a,...o,className:(0,r.Z)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":s===e}),children:i??e},e)}))})}function O(n){let{lazy:e,children:i,selectedValue:r}=n;const o=(Array.isArray(i)?i:[i]).filter(Boolean);if(e){const n=o.find((n=>n.props.value===r));return n?(0,s.cloneElement)(n,{className:"margin-top--md"}):null}return(0,m.jsx)("div",{className:"margin-top--md",children:o.map(((n,e)=>(0,s.cloneElement)(n,{key:e,hidden:n.props.value!==r})))})}function v(n){const e=j(n);return(0,m.jsxs)("div",{className:(0,r.Z)("tabs-container",f.tabList),children:[(0,m.jsx)(b,{...n,...e}),(0,m.jsx)(O,{...n,...e})]})}function I(n){const e=(0,g.Z)();return(0,m.jsx)(v,{...n,children:d(n.children)},String(e))}},1151:(n,e,i)=>{i.d(e,{Z:()=>l,a:()=>t});var s=i(7294);const r={},o=s.createContext(r);function t(n){const e=s.useContext(o);return s.useMemo((function(){return"function"==typeof n?n(e):{...e,...n}}),[e,n])}function l(n){let e;return e=n.disableParentContext?"function"==typeof n.components?n.components(r):n.components||r:t(n.components),s.createElement(o.Provider,{value:e},n.children)}}}]); |