text: (window.webpackJsonp=window.webpackJsonp||[]).push([[84],{160:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return i})),n.d(t,"metadata",(function(){return o})),n.d(t,"toc",(function(){return p})),n.d(t,"default",(function(){return l}));var r=n(3),a=n(7),c=(n(0),n(199)),i={id:"app",title:"1. App \u9759\u6001\u7c7b",sidebar_label:"1. App \u9759\u6001\u7c7b"},o={unversionedId:"global/app",id:"global/app",isDocsHomePage:!1,title:"1. App \u9759\u6001\u7c7b",description:"1.1 \u83b7\u53d6\u5168\u5c40\u914d\u7f6e",source:"@site/docs\\global\\app.mdx",slug:"/global/app",permalink:"/docs/global/app",editUrl:"https://gitee.com/dotnetchina/Furion/tree/master/handbook/docs/global/app.mdx",version:"current",lastUpdatedBy:"Monk",lastUpdatedAt:1612492226,sidebar_label:"1. App \u9759\u6001\u7c7b",sidebar:"global",next:{title:"2. Db \u9759\u6001\u7c7b",permalink:"/docs/global/db"}},p=[{value:"1.1 \u83b7\u53d6\u5168\u5c40\u914d\u7f6e",id:"11-\u83b7\u53d6\u5168\u5c40\u914d\u7f6e",children:[]},{value:"1.2 \u83b7\u53d6\u914d\u7f6e\u5bf9\u8c61",id:"12-\u83b7\u53d6\u914d\u7f6e\u5bf9\u8c61",children:[]},{value:"1.3 \u83b7\u53d6\u73af\u5883\u5bf9\u8c61",id:"13-\u83b7\u53d6\u73af\u5883\u5bf9\u8c61",children:[]},{value:"1.4 \u83b7\u53d6\u9879\u76ee\u6240\u6709\u7a0b\u5e8f\u96c6",id:"14-\u83b7\u53d6\u9879\u76ee\u6240\u6709\u7a0b\u5e8f\u96c6",children:[]},{value:"1.5 \u83b7\u53d6\u9879\u76ee\u6240\u6709\u6709\u6548\u7c7b\u578b",id:"15-\u83b7\u53d6\u9879\u76ee\u6240\u6709\u6709\u6548\u7c7b\u578b",children:[]},{value:"1.6 \u83b7\u53d6 <code>HttpContext</code>",id:"16-\u83b7\u53d6-httpcontext",children:[]},{value:"1.7 \u83b7\u53d6\u767b\u5f55\u7684 <code>User</code> \u5bf9\u8c61",id:"17-\u83b7\u53d6\u767b\u5f55\u7684-user-\u5bf9\u8c61",children:[]},{value:"1.8 \u83b7\u53d6\u670d\u52a1\u63d0\u4f9b\u5668",id:"18-\u83b7\u53d6\u670d\u52a1\u63d0\u4f9b\u5668",children:[]},{value:"1.9 \u89e3\u6790\u670d\u52a1",id:"19-\u89e3\u6790\u670d\u52a1",children:[]},{value:"1.10 \u83b7\u53d6\u9009\u9879\u914d\u7f6e",id:"110-\u83b7\u53d6\u9009\u9879\u914d\u7f6e",children:[]},{value:"1.11 \u6253\u5370\u6570\u636e\u5230 <code>MiniProfiler</code>",id:"111-\u6253\u5370\u6570\u636e\u5230-miniprofiler",children:[]},{value:"1.12 \u83b7\u53d6\u5e94\u7528\u540d\u79f0",id:"112-\u83b7\u53d6\u5e94\u7528\u540d\u79f0",children:[]},{value:"1.13 \u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55",id:"113-\u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55",children:[]},{value:"1.14 \u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55 <code>wwwroot</code> \u76ee\u5f55",id:"114-\u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55-wwwroot-\u76ee\u5f55",children:[]},{value:"1.15 \u83b7\u53d6\u542f\u52a8\u9879\u76ee\u6240\u5728\u7a0b\u5e8f\u96c6",id:"115-\u83b7\u53d6\u542f\u52a8\u9879\u76ee\u6240\u5728\u7a0b\u5e8f\u96c6",children:[]},{value:"1.16 \u83b7\u53d6\u542f\u52a8\u9879\u76ee <code>bin</code> \u76ee\u5f55",id:"116-\u83b7\u53d6\u542f\u52a8\u9879\u76ee-bin-\u76ee\u5f55",children:[]},{value:"1.17 \u83b7\u53d6\u73af\u5883\u53d8\u91cf\u540d",id:"117-\u83b7\u53d6\u73af\u5883\u53d8\u91cf\u540d",children:[]},{value:"1.18 \u5224\u65ad\u7cfb\u7edf\u73af\u5883",id:"118-\u5224\u65ad\u7cfb\u7edf\u73af\u5883",children:[]},{value:"1.19 \u83b7\u53d6\u670d\u52a1\u5668\u4fe1\u606f",id:"119-\u83b7\u53d6\u670d\u52a1\u5668\u4fe1\u606f",children:[]}],b={toc:p};function l(e){var t=e.components,n=Object(a.a)(e,["components"]);return Object(c.b)("wrapper",Object(r.a)({},b,n,{components:t,mdxType:"MDXLayout"}),Object(c.b)("h2",{id:"11-\u83b7\u53d6\u5168\u5c40\u914d\u7f6e"},"1.1 \u83b7\u53d6\u5168\u5c40\u914d\u7f6e"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var settings = App.Settings;\n")),Object(c.b)("h2",{id:"12-\u83b7\u53d6\u914d\u7f6e\u5bf9\u8c61"},"1.2 \u83b7\u53d6\u914d\u7f6e\u5bf9\u8c61"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),'// \u83b7\u53d6 IConfiguration \u5bf9\u8c61\nvar configuration = App.Configuration;\nvar value = configuration["xxx:xxx"];\n\n// \u83b7\u53d6\u6307\u5b9a\u8282\u70b9\u503c\u5e76\u8f6c\u6210 T \u7c7b\u578b\nvar data = App.GetConfig<TConfig>("key:key2");\n')),Object(c.b)("h2",{id:"13-\u83b7\u53d6\u73af\u5883\u5bf9\u8c61"},"1.3 \u83b7\u53d6\u73af\u5883\u5bf9\u8c61"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var webHostEnvironment = App.WebHostEnvironment;\n")),Object(c.b)("h2",{id:"14-\u83b7\u53d6\u9879\u76ee\u6240\u6709\u7a0b\u5e8f\u96c6"},"1.4 \u83b7\u53d6\u9879\u76ee\u6240\u6709\u7a0b\u5e8f\u96c6"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var assemblies = App.Assemblies;\n")),Object(c.b)("h2",{id:"15-\u83b7\u53d6\u9879\u76ee\u6240\u6709\u6709\u6548\u7c7b\u578b"},"1.5 \u83b7\u53d6\u9879\u76ee\u6240\u6709\u6709\u6548\u7c7b\u578b"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var types = App.EffectiveTypes;\n")),Object(c.b)("h2",{id:"16-\u83b7\u53d6-httpcontext"},"1.6 \u83b7\u53d6 ",Object(c.b)("inlineCode",{parentName:"h2"},"HttpContext")),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var httpContext = App.HttpContext;\n")),Object(c.b)("h2",{id:"17-\u83b7\u53d6\u767b\u5f55\u7684-user-\u5bf9\u8c61"},"1.7 \u83b7\u53d6\u767b\u5f55\u7684 ",Object(c.b)("inlineCode",{parentName:"h2"},"User")," \u5bf9\u8c61"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),'var contextUser = App.User;\n\n// \u83b7\u53d6 `Jwt` \u5b58\u50a8\u7684\u4fe1\u606f\nvar userId = App.User?.FindFirstValue("\u952e");\n')),Object(c.b)("p",null,Object(c.b)("strong",{parentName:"p"},"\u6ce8\u610f\u5f15\u5165 ",Object(c.b)("inlineCode",{parentName:"strong"},"System.Security.Claims")," \u547d\u540d\u7a7a\u95f4")),Object(c.b)("h2",{id:"18-\u83b7\u53d6\u670d\u52a1\u63d0\u4f9b\u5668"},"1.8 \u83b7\u53d6\u670d\u52a1\u63d0\u4f9b\u5668"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var serviceProvider = App.ServiceProvider;\n")),Object(c.b)("h2",{id:"19-\u89e3\u6790\u670d\u52a1"},"1.9 \u89e3\u6790\u670d\u52a1"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var service = App.GetService<TService>();\nvar service2 = App.GetService(typeof(TService));\n\nvar service3 = App.GetRequiredService<TService>();\nvar service4 = App.GetRequiredService(typeof(TService));\n")),Object(c.b)("h2",{id:"110-\u83b7\u53d6\u9009\u9879\u914d\u7f6e"},"1.10 \u83b7\u53d6\u9009\u9879\u914d\u7f6e"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var options = App.GetOptions<TOptions>();\nvar options2 = App.GetOptionsMonitor<TOptions>();\nvar options3 = App.GetOptionsSnapshot<TOptions>();\n")),Object(c.b)("h2",{id:"111-\u6253\u5370\u6570\u636e\u5230-miniprofiler"},"1.11 \u6253\u5370\u6570\u636e\u5230 ",Object(c.b)("inlineCode",{parentName:"h2"},"MiniProfiler")),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),'App.PrintToMiniProfiler("\u5206\u7c7b", "\u72b6\u6001", "\u8981\u6253\u5370\u7684\u6d88\u606f");\n')),Object(c.b)("h2",{id:"112-\u83b7\u53d6\u5e94\u7528\u540d\u79f0"},"1.12 \u83b7\u53d6\u5e94\u7528\u540d\u79f0"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var applicationName = App.WebHostEnvironment.ApplicationName;\n")),Object(c.b)("h2",{id:"113-\u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55"},"1.13 \u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var webRootPath = App.WebHostEnvironment.ContentRootPath;\n")),Object(c.b)("h2",{id:"114-\u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55-wwwroot-\u76ee\u5f55"},"1.14 \u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55 ",Object(c.b)("inlineCode",{parentName:"h2"},"wwwroot")," \u76ee\u5f55"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var wwwroot = App.WebHostEnvironment.WebRootPath;\n")),Object(c.b)("h2",{id:"115-\u83b7\u53d6\u542f\u52a8\u9879\u76ee\u6240\u5728\u7a0b\u5e8f\u96c6"},"1.15 \u83b7\u53d6\u542f\u52a8\u9879\u76ee\u6240\u5728\u7a0b\u5e8f\u96c6"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var webAssembly = Assembly.GetEntryAssembly();\n")),Object(c.b)("h2",{id:"116-\u83b7\u53d6\u542f\u52a8\u9879\u76ee-bin-\u76ee\u5f55"},"1.16 \u83b7\u53d6\u542f\u52a8\u9879\u76ee ",Object(c.b)("inlineCode",{parentName:"h2"},"bin")," \u76ee\u5f55"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var binPath = AppContext.BaseDirectory;\n")),Object(c.b)("h2",{id:"117-\u83b7\u53d6\u73af\u5883\u53d8\u91cf\u540d"},"1.17 \u83b7\u53d6\u73af\u5883\u53d8\u91cf\u540d"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"var environmentName = App.WebHostEnvironment.EnvironmentName;\n")),Object(c.b)("h2",{id:"118-\u5224\u65ad\u7cfb\u7edf\u73af\u5883"},"1.18 \u5224\u65ad\u7cfb\u7edf\u73af\u5883"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),'// \u5224\u65ad\u662f\u5426\u5f00\u53d1\u73af\u5883\nvar isDevelopment = App.WebHostEnvironment.IsDevelopment();\n\n// \u5224\u65ad\u662f\u5426\u751f\u4ea7\u73af\u5883\nvar isProduction = App.WebHostEnvironment.IsProduction();\n\n// \u5224\u65ad\u662f\u5426 Stage \u73af\u5883\nvar isStaging = App.WebHostEnvironment.IsStaging();\n\n// \u5224\u65ad\u662f\u5426\u662f\u7279\u5b9a\u73af\u5883\uff0c\u6bd4\u5982\u81ea\u5b9a\u4e49\u6d4b\u8bd5\u73af\u5883\nvar isTest = App.WebHostEnvironment.IsEnvironment("TestEnvironment");\n')),Object(c.b)("p",null,Object(c.b)("strong",{parentName:"p"},"\u6ce8\u610f\uff0c\u9700\u5f15\u7528 ",Object(c.b)("inlineCode",{parentName:"strong"},"Microsoft.Extensions.Hosting")," \u547d\u540d\u7a7a\u95f4")),Object(c.b)("h2",{id:"119-\u83b7\u53d6\u670d\u52a1\u5668\u4fe1\u606f"},"1.19 \u83b7\u53d6\u670d\u52a1\u5668\u4fe1\u606f"),Object(c.b)("pre",null,Object(c.b)("code",Object(r.a)({parentName:"pre"},{className:"language-cs"}),"// \u83b7\u53d6\u7cfb\u7edf\u67b6\u6784\nvar osArchitecture = RuntimeInformation.OSArchitecture; // => X64\n\n// \u83b7\u53d6\u7cfb\u7edf\u540d\u79f0\nvar osDescription = RuntimeInformation.OSDescription;   // => Windows 10 \u4f01\u4e1a\u7248\n\n// \u83b7\u53d6\u8fdb\u7a0b\u67b6\u6784\nvar processArchitecture = RuntimeInformation.ProcessArchitecture;   // => X64\n\n// \u662f\u5426\u662f64\u4f4d\u64cd\u4f5c\u7cfb\u7edf\nvar is64BitOperatingSystem = Environment.Is64BitOperatingSystem;    // => True\n")))}l.isMDXComponent=!0},199:function(e,t,n){"use strict";n.d(t,"a",(function(){return s})),n.d(t,"b",(function(){return O}));var r=n(0),a=n.n(r);function c(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){c(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function p(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},c=Object.keys(e);for(r=0;r<c.length;r++)n=c[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(r=0;r<c.length;r++)n=c[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var b=a.a.createContext({}),l=function(e){var t=a.a.useContext(b),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},s=function(e){var t=l(e.components);return a.a.createElement(b.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.a.createElement(a.a.Fragment,{},t)}},u=a.a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,c=e.originalType,i=e.parentName,b=p(e,["components","mdxType","originalType","parentName"]),s=l(n),u=r,O=s["".concat(i,".").concat(u)]||s[u]||d[u]||c;return n?a.a.createElement(O,o(o({ref:t},b),{},{components:n})):a.a.createElement(O,o({ref:t},b))}));function O(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var c=n.length,i=new Array(c);i[0]=u;var o={};for(var p in t)hasOwnProperty.call(t,p)&&(o[p]=t[p]);o.originalType=e,o.mdxType="string"==typeof e?e:r,i[1]=o;for(var b=2;b<c;b++)i[b]=n[b];return a.a.createElement.apply(null,i)}return a.a.createElement.apply(null,n)}u.displayName="MDXCreateElement"}}]);