"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[4197],{9451:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>a,contentTitle:()=>d,default:()=>x,frontMatter:()=>o,metadata:()=>t,toc:()=>h});var s=r(5893),i=r(1151),c=r(4996),l=r(510);const o={id:"dependency-injection",title:"12. \u4f9d\u8d56\u6ce8\u5165/\u63a7\u5236\u53cd\u8f6c",sidebar_label:"12. \u4f9d\u8d56\u6ce8\u5165/\u63a7\u5236\u53cd\u8f6c"},d=void 0,t={id:"dependency-injection",title:"12. \u4f9d\u8d56\u6ce8\u5165/\u63a7\u5236\u53cd\u8f6c",description:"\ud83d\udcdd \u6a21\u5757\u66f4\u65b0\u65e5\u5fd7",source:"@site/docs/dependency-injection.mdx",sourceDirName:".",slug:"/dependency-injection",permalink:"/docs/dependency-injection",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/dependency-injection.mdx",tags:[],version:"current",lastUpdatedBy:"\u767e\u5c0f\u50e7",lastUpdatedAt:1695424618,formattedLastUpdatedAt:"Sep 22, 2023",frontMatter:{id:"dependency-injection",title:"12. \u4f9d\u8d56\u6ce8\u5165/\u63a7\u5236\u53cd\u8f6c",sidebar_label:"12. \u4f9d\u8d56\u6ce8\u5165/\u63a7\u5236\u53cd\u8f6c"},sidebar:"docs",previous:{title:"11. SaaS \u591a\u79df\u6237",permalink:"/docs/saas"},next:{title:"13. \u5bf9\u8c61\u6570\u636e\u6620\u5c04 (Mapper)",permalink:"/docs/object-mapper"}},a={},h=[{value:"12.1 \u4f9d\u8d56\u6ce8\u5165",id:"121-\u4f9d\u8d56\u6ce8\u5165",level:2},{value:"12.2 \u63a7\u5236\u53cd\u8f6c",id:"122-\u63a7\u5236\u53cd\u8f6c",level:2},{value:"12.3 IOC/DI
\u4f18\u7f3a\u70b9",id:"123-iocdi-\u4f18\u7f3a\u70b9",level:2},{value:"12.4 \u4f9d\u8d56\u6ce8\u5165\u7684\u4e09\u79cd\u65b9\u5f0f",id:"124-\u4f9d\u8d56\u6ce8\u5165\u7684\u4e09\u79cd\u65b9\u5f0f",level:2},{value:"12.4.1 \u6784\u9020\u65b9\u6cd5\u6ce8\u5165",id:"1241-\u6784\u9020\u65b9\u6cd5\u6ce8\u5165",level:3},{value:"12.4.2 \u5c5e\u6027\u65b9\u5f0f\u6ce8\u5165",id:"1242-\u5c5e\u6027\u65b9\u5f0f\u6ce8\u5165",level:3},{value:"12.4.3 \u65b9\u6cd5\u53c2\u6570\u6ce8\u5165",id:"1243-\u65b9\u6cd5\u53c2\u6570\u6ce8\u5165",level:3},{value:"12.5 \u6ce8\u518c\u5bf9\u8c61\u751f\u5b58\u671f",id:"125-\u6ce8\u518c\u5bf9\u8c61\u751f\u5b58\u671f",level:2},{value:"12.5.1 \u6682\u65f6/\u77ac\u65f6
\u751f\u5b58\u671f",id:"1251-\u6682\u65f6\u77ac\u65f6-\u751f\u5b58\u671f",level:3},{value:"12.5.2 \u4f5c\u7528\u57df
\u751f\u5b58\u671f",id:"1252-\u4f5c\u7528\u57df-\u751f\u5b58\u671f",level:3},{value:"12.5.3 \u5355\u4f8b
\u751f\u5b58\u671f",id:"1253-\u5355\u4f8b-\u751f\u5b58\u671f",level:3},{value:"12.6 \u5185\u7f6e\u4f9d\u8d56\u63a5\u53e3",id:"126-\u5185\u7f6e\u4f9d\u8d56\u63a5\u53e3",level:2},{value:"12.7 \u5e38\u89c1\u4f7f\u7528",id:"127-\u5e38\u89c1\u4f7f\u7528",level:2},{value:"12.7.1 \u7b2c\u4e00\u4e2a\u4f8b\u5b50",id:"1271-\u7b2c\u4e00\u4e2a\u4f8b\u5b50",level:3},{value:"12.7.2 \u6ce8\u518c\u6cdb\u578b\u5b9e\u4f8b",id:"1272-\u6ce8\u518c\u6cdb\u578b\u5b9e\u4f8b",level:3},{value:"12.7.3 \u4e00\u4e2a\u63a5\u53e3\u591a\u4e2a\u5b9e\u73b0",id:"1273-\u4e00\u4e2a\u63a5\u53e3\u591a\u4e2a\u5b9e\u73b0",level:3},{value:"12.7.4 \u65e0\u63a5\u53e3\u65b9\u5f0f",id:"1274-\u65e0\u63a5\u53e3\u65b9\u5f0f",level:3},{value:"12.8 [Injection]
\u7279\u6027\u914d\u7f6e",id:"128-injection-\u7279\u6027\u914d\u7f6e",level:2},{value:"12.9 \u81ea\u5b9a\u4e49\u9ad8\u7ea7\u6ce8\u518c",id:"129-\u81ea\u5b9a\u4e49\u9ad8\u7ea7\u6ce8\u518c",level:2},{value:"12.10 appsettings.json
\u914d\u7f6e\u6ce8\u518c",id:"1210-appsettingsjson-\u914d\u7f6e\u6ce8\u518c",level:2},{value:"12.11 \u6ce8\u518c\u987a\u5e8f\u548c\u4f18\u5148\u7ea7",id:"1211-\u6ce8\u518c\u987a\u5e8f\u548c\u4f18\u5148\u7ea7",level:2},{value:"12.12 Aop
\u6ce8\u518c\u62e6\u622a",id:"1212-aop-\u6ce8\u518c\u62e6\u622a",level:2},{value:"12.12.1 \u5168\u5c40Aop\u62e6\u622a
",id:"12121-\u5168\u5c40aop\u62e6\u622a",level:3},{value:"12.12.2 AOP
\u6ce8\u5165\u89e3\u6790\u670d\u52a1",id:"12122-aop-\u6ce8\u5165\u89e3\u6790\u670d\u52a1",level:3},{value:"12.12.3 AOP
\u7684\u4f5c\u7528",id:"12123-aop-\u7684\u4f5c\u7528",level:3},{value:"12.13 \u5728\u975e Web
\u6216\u591a\u7ebf\u7a0b\u89e3\u6790\u670d\u52a1",id:"1213-\u5728\u975e-web-\u6216\u591a\u7ebf\u7a0b\u89e3\u6790\u670d\u52a1",level:2},{value:"12.13.1 IServiceProvider
\u65b9\u5f0f",id:"12131-iserviceprovider-\u65b9\u5f0f",level:3},{value:"12.13.2 IServiceScopeFactory
\u65b9\u5f0f",id:"12132-iservicescopefactory-\u65b9\u5f0f",level:3},{value:"12.13.3 Scoped
\u9759\u6001\u7c7b",id:"12133-scoped-\u9759\u6001\u7c7b",level:3},{value:"12.14 \u5728 WinForm/WPF
\u4e2d\u4f7f\u7528",id:"1214-\u5728-winformwpf-\u4e2d\u4f7f\u7528",level:2},{value:"12.14.1 \u5728 WinForm
\u4e2d\u4f7f\u7528",id:"12141-\u5728-winform-\u4e2d\u4f7f\u7528",level:3},{value:"12.14.2 \u5728 WPF
\u4e2d\u4f7f\u7528",id:"12142-\u5728-wpf-\u4e2d\u4f7f\u7528",level:3},{value:"12.14.3 Native.CreateInstance<T>()
\u9759\u6001\u65b9\u6cd5",id:"12143-nativecreateinstancet-\u9759\u6001\u65b9\u6cd5",level:3},{value:"12.15 \u81ea\u5b9a\u4e49\u626b\u63cf/\u7b5b\u9009\u6ce8\u518c\u670d\u52a1",id:"1215-\u81ea\u5b9a\u4e49\u626b\u63cf\u7b5b\u9009\u6ce8\u518c\u670d\u52a1",level:2},{value:"12.16 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"1216-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function p(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",hr:"hr",li:"li",mdxAdmonitionTitle:"mdxAdmonitionTitle",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.a)(),...e.components},{Details:r}=n;return r||function(e,n){throw new Error("Expected "+(n?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Details",!0),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(r,{children:[(0,s.jsx)("summary",{children:"\ud83d\udcdd \u6a21\u5757\u66f4\u65b0\u65e5\u5fd7"}),(0,s.jsx)("div",{children:(0,s.jsx)("div",{children:(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"\u65b0\u7279\u6027"})}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\xa0",(0,s.jsx)(l.Z,{children:"\u65b0\u589e"})," ",(0,s.jsxs)(n.strong,{children:[(0,s.jsx)(n.code,{children:"WinForm/WPF"})," \u652f\u6301\u4f9d\u8d56\u6ce8\u5165\u7684 ",(0,s.jsx)(n.code,{children:"Native.CreateInstance()"})," \u9759\u6001\u65b9\u6cd5"]})," ",(0,s.jsx)("sup",{children:"4.8.7.23"})," ",(0,s.jsx)("sup",{children:"\u23f1\ufe0f2023.03.27"})," ",(0,s.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/commit/53d51c3645f4066f5d68d4726d78e389fd544560",children:"53d51c3"})]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"\u95ee\u9898\u4fee\u590d"})}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\xa0",(0,s.jsx)(l.Z,{children:"\u4fee\u590d"})," \u56e0 ",(0,s.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/commit/9d8cb82e4ce983839cf13c3c74640b08f258c325",children:"9d8cb82"})," \u4ee3\u7801\u63d0\u4ea4\u5bfc\u81f4\u547d\u540d\u670d\u52a1\u89e3\u6790\u5f02\u5e38\u95ee\u9898 ",(0,s.jsx)("sup",{children:"4.8.8.21"})," ",(0,s.jsx)("sup",{children:"\u23f1\ufe0f2023.05.18"})," ",(0,s.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/issues/I76JZR",children:"#I76JZR"})]}),"\n",(0,s.jsxs)(n.li,{children:["\xa0",(0,s.jsx)(l.Z,{children:"\u4fee\u590d"})," \u56e0 ",(0,s.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/commit/9d8cb82e4ce983839cf13c3c74640b08f258c325",children:"9d8cb82"})," \u4ee3\u7801\u63d0\u4ea4\u5bfc\u81f4\u670d\u52a1 ",(0,s.jsx)(n.code,{children:"AOP"})," \u5f02\u5e38\u62e6\u622a\u95ee\u9898 ",(0,s.jsx)("sup",{children:"4.8.8.17"})," ",(0,s.jsx)("sup",{children:"\u23f1\ufe0f2023.05.15"})," ",(0,s.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/issues/I73A8E",children:"#I73A8E"})]}),"\n"]}),"\n"]}),"\n"]})})})]}),"\n",(0,s.jsx)(n.h2,{id:"121-\u4f9d\u8d56\u6ce8\u5165",children:"12.1 \u4f9d\u8d56\u6ce8\u5165"}),"\n",(0,s.jsx)(n.p,{children:"\u6240\u8c13\u4f9d\u8d56\u6ce8\u5165\uff0c\u662f\u6307\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u9700\u8981\u8c03\u7528\u53e6\u4e00\u4e2a\u5bf9\u8c61\u534f\u52a9\u65f6\uff0c\u65e0\u987b\u5728\u4ee3\u7801\u4e2d\u521b\u5efa\u88ab\u8c03\u7528\u8005\uff0c\u800c\u662f\u4f9d\u8d56\u4e8e\u5916\u90e8\u7684\u6ce8\u5165\u3002"}),"\n",(0,s.jsx)(n.p,{children:"\u901a\u4fd7\u6765\u8bb2\uff0c\u5c31\u662f\u628a\u6709\u4f9d\u8d56\u5173\u7cfb\u7684\u7c7b\u653e\u5230\u5bb9\u5668\u4e2d\uff0c\u7136\u540e\u5728\u6211\u4eec\u9700\u8981\u8fd9\u4e9b\u7c7b\u65f6\uff0c\u5bb9\u5668\u81ea\u52a8\u89e3\u6790\u51fa\u8fd9\u4e9b\u7c7b\u7684\u5b9e\u4f8b\u3002"}),"\n",(0,s.jsx)(n.p,{children:"\u4f9d\u8d56\u6ce8\u5165\u6700\u5927\u7684\u597d\u5904\u662f\u5b9e\u73b0\u7c7b\u7684\u89e3\u8026\uff0c\u5229\u4e8e\u7a0b\u5e8f\u62d3\u5c55\u3001\u5355\u5143\u6d4b\u8bd5\u3001\u81ea\u52a8\u5316\u6a21\u62df\u6d4b\u8bd5\u7b49\u3002"}),"\n",(0,s.jsxs)(n.p,{children:["\u4f9d\u8d56\u6ce8\u5165\u7684\u82f1\u6587\u4e3a\uff1a",(0,s.jsx)(n.code,{children:"Dependency Injection"}),"\uff0c\u7b80\u79f0 ",(0,s.jsx)(n.code,{children:"DI"})]}),"\n",(0,s.jsx)(n.h2,{id:"122-\u63a7\u5236\u53cd\u8f6c",children:"12.2 \u63a7\u5236\u53cd\u8f6c"}),"\n",(0,s.jsxs)(n.p,{children:["\u63a7\u5236\u53cd\u8f6c\u53ea\u662f\u4e00\u4e2a\u6982\u5ff5\uff0c\u4e5f\u5c31\u662f\u5c06\u521b\u5efa\u5bf9\u8c61\u5b9e\u4f8b\u7684\u63a7\u5236\u6743\uff08\u539f\u672c\u662f\u7a0b\u5e8f\u5458\uff09\u4ece\u4ee3\u7801\u63a7\u5236\u6743\u5265\u79bb\u5230 ",(0,s.jsx)(n.code,{children:"IOC \u5bb9\u5668"})," \u4e2d\u63a7\u5236\u3002"]}),"\n",(0,s.jsxs)(n.p,{children:["\u63a7\u5236\u53cd\u8f6c\u7684\u82f1\u6587\u4e3a\uff1a",(0,s.jsx)(n.code,{children:"Inversion of Control"}),"\uff0c\u7b80\u79f0 ",(0,s.jsx)(n.code,{children:"IOC"})]}),"\n",(0,s.jsxs)(n.h2,{id:"123-iocdi-\u4f18\u7f3a\u70b9",children:["12.3 ",(0,s.jsx)(n.code,{children:"IOC/DI"})," \u4f18\u7f3a\u70b9"]}),"\n",(0,s.jsx)(n.p,{children:"\u4f20\u7edf\u7684\u4ee3\u7801\uff0c\u6bcf\u4e2a\u5bf9\u8c61\u8d1f\u8d23\u7ba1\u7406\u4e0e\u81ea\u5df1\u9700\u8981\u4f9d\u8d56\u7684\u5bf9\u8c61\uff0c\u5bfc\u81f4\u5982\u679c\u9700\u8981\u5207\u6362\u4f9d\u8d56\u5bf9\u8c61\u7684\u5b9e\u73b0\u7c7b\u65f6\uff0c\u9700\u8981\u4fee\u6539\u591a\u5904\u5730\u65b9\u3002\u540c\u65f6\uff0c\u8fc7\u5ea6\u8026\u5408\u4e5f\u4f7f\u5f97\u5bf9\u8c61\u96be\u4ee5\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5\u3002"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"\u4f18\u70b9"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"\u4f9d\u8d56\u6ce8\u5165\u628a\u5bf9\u8c61\u7684\u521b\u5efa\u4ea4\u7ed9\u5916\u90e8\u53bb\u7ba1\u7406,\u5f88\u597d\u7684\u89e3\u51b3\u4e86\u4ee3\u7801\u7d27\u8026\u5408\uff08tight couple\uff09\u7684\u95ee\u9898\uff0c\u662f\u4e00\u79cd\u8ba9\u4ee3\u7801\u5b9e\u73b0\u677e\u8026\u5408\uff08loose couple\uff09\u7684\u673a\u5236"}),"\n",(0,s.jsx)(n.li,{children:"\u677e\u8026\u5408\u8ba9\u4ee3\u7801\u66f4\u5177\u7075\u6d3b\u6027\uff0c\u80fd\u66f4\u597d\u5730\u5e94\u5bf9\u9700\u6c42\u53d8\u52a8\uff0c\u4ee5\u53ca\u65b9\u4fbf\u5355\u5143\u6d4b\u8bd5"}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"\u7f3a\u70b9"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\u76ee\u524d\u4e3b\u6d41\u7684 ",(0,s.jsx)(n.code,{children:"IOC/DI"})," \u57fa\u672c\u91c7\u7528\u53cd\u5c04\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u4f9d\u8d56\u6ce8\u5165\uff0c\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4f1a\u5f71\u54cd\u6027\u80fd"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"important",children:(0,s.jsxs)(n.p,{children:["\u5728\u672c\u7ae0\u8282\u4e0d\u6253\u7b97\u7ec6\u8bb2 ",(0,s.jsx)(n.code,{children:"\u4f9d\u8d56\u6ce8\u5165/\u63a7\u5236\u53cd\u8f6c"})," \u5177\u4f53\u5b9e\u73b0\u548c\u5e94\u7528\u573a\u666f\uff0c\u60f3\u4e86\u89e3\u66f4\u591a\u77e5\u8bc6\uff0c\u53ef\u67e5\u9605 \u3010",(0,s.jsx)(n.a,{href:"https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-5.0",children:"ASP.NET Core \u4f9d\u8d56\u6ce8\u5165"}),"\u3011 \u5b98\u65b9\u6587\u6863\u3002"]})}),"\n",(0,s.jsx)(n.h2,{id:"124-\u4f9d\u8d56\u6ce8\u5165\u7684\u4e09\u79cd\u65b9\u5f0f",children:"12.4 \u4f9d\u8d56\u6ce8\u5165\u7684\u4e09\u79cd\u65b9\u5f0f"}),"\n",(0,s.jsx)(n.h3,{id:"1241-\u6784\u9020\u65b9\u6cd5\u6ce8\u5165",children:"12.4.1 \u6784\u9020\u65b9\u6cd5\u6ce8\u5165"}),"\n",(0,s.jsx)(n.p,{children:"\u76ee\u524d\u6784\u9020\u65b9\u6cd5\u6ce8\u5165\u662f\u4f9d\u8d56\u6ce8\u5165\u63a8\u8350\u4f7f\u7528\u65b9\u5f0f\u3002"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"\u4f18\u70b9"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"\u5728\u6784\u9020\u65b9\u6cd5\u4e2d\u4f53\u73b0\u51fa\u5bf9\u5176\u4ed6\u7c7b\u7684\u4f9d\u8d56\uff0c\u4e00\u773c\u5c31\u80fd\u770b\u51fa\u8fd9\u4e2a\u7c7b\u9700\u8981\u4f9d\u8d56\u54ea\u4e9b\u7c7b\u624d\u80fd\u5de5\u4f5c"}),"\n",(0,s.jsx)(n.li,{children:"\u8131\u79bb\u4e86 IOC \u6846\u67b6\uff0c\u8fd9\u4e2a\u7c7b\u4ecd\u7136\u53ef\u4ee5\u5de5\u4f5c"}),"\n",(0,s.jsx)(n.li,{children:"\u4e00\u65e6\u5bf9\u8c61\u521d\u59cb\u5316\u6210\u529f\u4e86\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u7684\u72b6\u6001\u80af\u5b9a\u662f\u6b63\u786e\u7684"}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"\u7f3a\u70b9"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"\u6784\u9020\u51fd\u6570\u4f1a\u6709\u5f88\u591a\u53c2\u6570"}),"\n",(0,s.jsx)(n.li,{children:"\u6709\u4e9b\u7c7b\u662f\u9700\u8981\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\u7684\uff0c\u6bd4\u5982 MVC \u6846\u67b6\u7684 Controller \u7c7b\uff0c\u4e00\u65e6\u4f7f\u7528\u6784\u9020\u51fd\u6570\u6ce8\u5165\uff0c\u5c31\u65e0\u6cd5\u4f7f\u7528\u9ed8\u8ba4\u6784\u9020\u51fd\u6570"}),"\n",(0,s.jsx)(n.li,{children:"\u8fd9\u4e2a\u7c7b\u91cc\u9762\u7684\u6709\u4e9b\u65b9\u6cd5\u5e76\u4e0d\u9700\u8981\u7528\u5230\u8fd9\u4e9b\u4f9d\u8d56"}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"\u4ee3\u7801\u793a\u4f8b\uff1a"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {4}",children:"public class FurionService\r\n{\r\n private readonly IRepository _repository;\r\n public FurionService(IRepository repository)\r\n {\r\n _repository = repository;\r\n }\r\n}\n"})}),"\n",(0,s.jsx)(n.h3,{id:"1242-\u5c5e\u6027\u65b9\u5f0f\u6ce8\u5165",children:"12.4.2 \u5c5e\u6027\u65b9\u5f0f\u6ce8\u5165"}),"\n",(0,s.jsx)(n.admonition,{title:"\u7279\u522b\u58f0\u660e",type:"warning",children:(0,s.jsxs)(n.p,{children:["\u5728 ",(0,s.jsx)(n.code,{children:"Furion"})," \u65b0\u7248\u672c\u4e2d\uff0c\u5df2\u7ecf\u79fb\u9664\u5c5e\u6027\u6ce8\u5165\u529f\u80fd\uff0c\u5efa\u8bae\u4f7f\u7528\u6784\u9020\u51fd\u6570\u6216\u65b9\u6cd5\u65b9\u5f0f\u6ce8\u5165\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7 ",(0,s.jsx)(n.code,{children:"App.GetService"})," \u65b9\u5f0f\u6ce8\u5165\u3002"]})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"\u901a\u8fc7\u5c5e\u6027\u65b9\u5f0f\u6ce8\u5165\u5bb9\u6613\u548c\u7c7b\u7684\u5b9e\u4f8b\u5c5e\u6027\u6df7\u6dc6\uff0c\u4e0d\u5efa\u8bae\u4f7f\u7528\u3002"})}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"\u4f18\u70b9"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"\u5728\u5bf9\u8c61\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f\u5185\uff0c\u53ef\u4ee5\u968f\u65f6\u52a8\u6001\u7684\u6539\u53d8\u4f9d\u8d56"}),"\n",(0,s.jsx)(n.li,{children:"\u975e\u5e38\u7075\u6d3b"}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"\u7f3a\u70b9"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"\u5bf9\u8c61\u5728\u521b\u5efa\u540e\uff0c\u88ab\u8bbe\u7f6e\u4f9d\u8d56\u5bf9\u8c61\u4e4b\u524d\u8fd9\u6bb5\u65f6\u95f4\u72b6\u6001\u662f\u4e0d\u5bf9\u7684"}),"\n",(0,s.jsx)(n.li,{children:"\u4e0d\u76f4\u89c2\uff0c\u65e0\u6cd5\u6e05\u6670\u5730\u8868\u793a\u54ea\u4e9b\u5c5e\u6027\u662f\u5fc5\u987b\u7684"}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {3}",children:"public class FurionService\r\n{\r\n public IRepository Repository { get; set; }\r\n}\n"})}),"\n",(0,s.jsx)(n.h3,{id:"1243-\u65b9\u6cd5\u53c2\u6570\u6ce8\u5165",children:"12.4.3 \u65b9\u6cd5\u53c2\u6570\u6ce8\u5165"}),"\n",(0,s.jsx)(n.p,{children:"\u65b9\u6cd5\u53c2\u6570\u6ce8\u5165\u7684\u610f\u601d\u662f\u5728\u521b\u5efa\u5bf9\u8c61\u540e\uff0c\u901a\u8fc7\u81ea\u52a8\u8c03\u7528\u67d0\u4e2a\u65b9\u6cd5\u6765\u6ce8\u5165\u4f9d\u8d56\u3002"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"\u4f18\u70b9\uff1a"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"\u6bd4\u8f83\u7075\u6d3b"}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"\u7f3a\u70b9\uff1a"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"\u65b0\u52a0\u5165\u4f9d\u8d56\u65f6\u4f1a\u7834\u574f\u539f\u6709\u7684\u65b9\u6cd5\u7b7e\u540d\uff0c\u5982\u679c\u8fd9\u4e2a\u65b9\u6cd5\u5df2\u7ecf\u88ab\u5176\u4ed6\u5f88\u591a\u6a21\u5757\u7528\u5230\u5c31\u5f88\u9ebb\u70e6"}),"\n",(0,s.jsx)(n.li,{children:"\u4e0e\u6784\u9020\u65b9\u6cd5\u6ce8\u5165\u4e00\u6837\uff0c\u4f1a\u6709\u5f88\u591a\u53c2\u6570"}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {3}",children:"public class FurionService\r\n{\r\n public Person GetById([FromServices]IRepository repository, int id)\r\n {\r\n return repository.Find(id);\r\n }\r\n}\n"})}),"\n",(0,s.jsx)(n.h2,{id:"125-\u6ce8\u518c\u5bf9\u8c61\u751f\u5b58\u671f",children:"12.5 \u6ce8\u518c\u5bf9\u8c61\u751f\u5b58\u671f"}),"\n",(0,s.jsxs)(n.h3,{id:"1251-\u6682\u65f6\u77ac\u65f6-\u751f\u5b58\u671f",children:["12.5.1 ",(0,s.jsx)(n.code,{children:"\u6682\u65f6/\u77ac\u65f6"})," \u751f\u5b58\u671f"]}),"\n",(0,s.jsx)(n.p,{children:"\u6682\u65f6\u751f\u5b58\u671f\u670d\u52a1\u662f\u6bcf\u6b21\u4ece\u670d\u52a1\u5bb9\u5668\u8fdb\u884c\u8bf7\u6c42\u65f6\u521b\u5efa\u7684\u3002 \u8fd9\u79cd\u751f\u5b58\u671f\u9002\u5408\u8f7b\u91cf\u7ea7\u3001 \u65e0\u72b6\u6001\u7684\u670d\u52a1\u3002"}),"\n",(0,s.jsx)(n.p,{children:"\u5728\u5904\u7406\u8bf7\u6c42\u7684\u5e94\u7528\u4e2d\uff0c\u5728\u8bf7\u6c42\u7ed3\u675f\u65f6\u4f1a\u91ca\u653e\u6682\u65f6\u670d\u52a1\u3002"}),"\n",(0,s.jsxs)(n.p,{children:["\u901a\u5e38\u6211\u4eec\u4f7f\u7528 ",(0,s.jsx)(n.code,{children:"ITransient"})," \u63a5\u53e3\u4f9d\u8d56\u8868\u793a\u8be5\u751f\u547d\u5468\u671f\u3002"]}),"\n",(0,s.jsxs)(n.h3,{id:"1252-\u4f5c\u7528\u57df-\u751f\u5b58\u671f",children:["12.5.2 ",(0,s.jsx)(n.code,{children:"\u4f5c\u7528\u57df"})," \u751f\u5b58\u671f"]}),"\n",(0,s.jsx)(n.p,{children:"\u4f5c\u7528\u57df\u751f\u5b58\u671f\u670d\u52a1\u9488\u5bf9\u6bcf\u4e2a\u5ba2\u6237\u7aef\u8bf7\u6c42\uff08\u8fde\u63a5\uff09\u521b\u5efa\u4e00\u6b21\u3002\u5728\u5904\u7406\u8bf7\u6c42\u7684\u5e94\u7528\u4e2d\uff0c\u5728\u8bf7\u6c42\u7ed3\u675f\u65f6\u4f1a\u91ca\u653e\u6709\u4f5c\u7528\u57df\u7684\u670d\u52a1\u3002"}),"\n",(0,s.jsxs)(n.p,{children:["\u901a\u5e38\u6211\u4eec\u4f7f\u7528 ",(0,s.jsx)(n.code,{children:"IScoped"})," \u63a5\u53e3\u4f9d\u8d56\u8868\u793a\u8be5\u751f\u547d\u5468\u671f\u3002"]}),"\n",(0,s.jsxs)(n.h3,{id:"1253-\u5355\u4f8b-\u751f\u5b58\u671f",children:["12.5.3 ",(0,s.jsx)(n.code,{children:"\u5355\u4f8b"})," \u751f\u5b58\u671f"]}),"\n",(0,s.jsx)(n.p,{children:"\u5728\u9996\u6b21\u8bf7\u6c42\u5b83\u4eec\u65f6\u8fdb\u884c\u521b\u5efa\uff0c\u4e4b\u540e\u6bcf\u4e2a\u540e\u7eed\u8bf7\u6c42\u90fd\u4f7f\u7528\u76f8\u540c\u7684\u5b9e\u4f8b\u3002"}),"\n",(0,s.jsxs)(n.p,{children:["\u901a\u5e38\u6211\u4eec\u4f7f\u7528 ",(0,s.jsx)(n.code,{children:"ISingleton"})," \u63a5\u53e3\u4f9d\u8d56\u8868\u793a\u8be5\u751f\u547d\u5468\u671f\u3002"]}),"\n",(0,s.jsx)(n.admonition,{title:"\u4e86\u89e3\u66f4\u591a",type:"note",children:(0,s.jsxs)(n.p,{children:["\u60f3\u4e86\u89e3\u66f4\u591a ",(0,s.jsx)(n.code,{children:"\u670d\u52a1\u751f\u5b58\u671f"})," \u77e5\u8bc6\u53ef\u67e5\u9605 ",(0,s.jsx)(n.a,{href:"https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-5.0#service-lifetimes",children:"ASP.NET Core - \u4f9d\u8d56\u6ce8\u5165 - \u670d\u52a1\u751f\u5b58\u671f"})," \u7ae0\u8282\u3002"]})}),"\n",(0,s.jsx)(n.h2,{id:"126-\u5185\u7f6e\u4f9d\u8d56\u63a5\u53e3",children:"12.6 \u5185\u7f6e\u4f9d\u8d56\u63a5\u53e3"}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e09\u4e2a\u63a5\u53e3\u4f9d\u8d56\u5206\u522b\u5bf9\u5e94\u4e0d\u540c\u7684\u670d\u52a1\u751f\u5b58\u671f\uff1a"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"ITransient"}),"\uff1a\u5bf9\u5e94\u6682\u65f6/\u77ac\u65f6\u4f5c\u7528\u57df\u670d\u52a1\u751f\u5b58\u671f"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"IScoped"}),"\uff1a\u5bf9\u5e94\u8bf7\u6c42\u4f5c\u7528\u57df\u670d\u52a1\u751f\u5b58\u671f"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"ISingleton"}),"\uff1a\u5bf9\u5e94\u5355\u4f8b\u4f5c\u7528\u57df\u670d\u52a1\u751f\u5b58\u671f"]}),"\n"]}),"\n",(0,s.jsx)(n.admonition,{title:"\u7279\u522b\u6ce8\u610f",type:"warning",children:(0,s.jsx)(n.p,{children:"\u4ee5\u4e0a\u4e09\u4e2a\u63a5\u53e3\u53ea\u80fd\u5b9e\u4f8b\u7c7b\u5b9e\u73b0\uff0c\u5176\u4ed6\u9759\u6001\u7c7b\u3001\u62bd\u8c61\u7c7b\u3001\u53ca\u63a5\u53e3\u4e0d\u80fd\u5b9e\u73b0\u3002"})}),"\n",(0,s.jsx)(n.h2,{id:"127-\u5e38\u89c1\u4f7f\u7528",children:"12.7 \u5e38\u89c1\u4f7f\u7528"}),"\n",(0,s.jsx)(n.h3,{id:"1271-\u7b2c\u4e00\u4e2a\u4f8b\u5b50",children:"12.7.1 \u7b2c\u4e00\u4e2a\u4f8b\u5b50"}),"\n",(0,s.jsxs)(n.p,{children:["\u521b\u5efa ",(0,s.jsx)(n.code,{children:"IBusinessService"})," \u63a5\u53e3\u548c ",(0,s.jsx)(n.code,{children:"BusinessService"})," \u5b9e\u73b0\u7c7b\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {7,12}",children:"using Furion.Core;\r\nusing Furion.DatabaseAccessor;\r\nusing Furion.DependencyInjection;\r\n\r\nnamespace Furion.Application\r\n{\r\n public interface IBusinessService\r\n {\r\n Person Get(int id);\r\n }\r\n\r\n public class BusinessService : IBusinessService, ITransient\r\n {\r\n private readonly IRepository _personRepository;\r\n\r\n public BusinessService(IRepository personRepository)\r\n {\r\n _personRepository = personRepository;\r\n }\r\n\r\n public Person Get(int id)\r\n {\r\n return _personRepository.Find(id);\r\n }\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(n.p,{children:["\u521b\u5efa ",(0,s.jsx)(n.code,{children:"PersonController"})," \u63a7\u5236\u5668\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {11,19}",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 [ApiController]\r\n public class PersonController : ControllerBase\r\n {\r\n private readonly IBusinessService _businessService;\r\n public PersonController(IBusinessService businessService)\r\n {\r\n _businessService = businessService;\r\n }\r\n\r\n [HttpGet]\r\n public IActionResult Get(int id)\r\n {\r\n var person = _businessService.Get(id);\r\n return new JsonResult(person);\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsx)("img",{src:(0,c.Z)("img/di1.gif")}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"\u4f8b\u5b50\u89e3\u8bf4"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e86\u975e\u5e38\u7075\u6d3b\u4e14\u65b9\u4fbf\u7684\u5b9e\u73b0\u4f9d\u8d56\u6ce8\u5165\u7684\u65b9\u5f0f\uff0c\u53ea\u9700\u8981\u5b9e\u4f8b\u7c7b\u7ee7\u627f\u5bf9\u5e94\u751f\u5b58\u671f\u7684\u63a5\u53e3\u5373\u53ef\uff0c\u8fd9\u91cc\u7ee7\u627f\u4e86 ",(0,s.jsx)(n.code,{children:"ITransient"}),"\uff0c\u4e5f\u5c31\u8868\u660e\u4e86\u8fd9\u662f\u4e00\u4e2a ",(0,s.jsx)(n.code,{children:"\u6682\u65f6/\u77ac\u65f6"})," \u4f5c\u7528\u57df\u5b9e\u4f8b\u7c7b\u3002\u8be5\u7c7b\u5c31\u53ef\u4ee5\u4f5c\u4e3a\u88ab\u6ce8\u5165\u5bf9\u8c61\uff0c\u540c\u65f6\u4e5f\u80fd\u6ce8\u5165\u5176\u4ed6\u63a5\u53e3\u5bf9\u8c61\u3002"]}),"\n",(0,s.jsxs)(n.p,{children:["\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c",(0,s.jsx)(n.code,{children:"BusinessService"})," \u6ce8\u5165\u4e86 ",(0,s.jsx)(n.code,{children:"IRepository"})," \u4ed3\u50a8\u63a5\u53e3\uff0c\u540c\u65f6 ",(0,s.jsx)(n.code,{children:"PersonController"})," \u63a7\u5236\u5668\u6ce8\u5165\u4e86 ",(0,s.jsx)(n.code,{children:"IBusinessService"})," \u63a5\u53e3\u3002"]}),"\n",(0,s.jsxs)(n.p,{children:["\u8fd9\u6837 ",(0,s.jsx)(n.code,{children:"PersonController"})," \u548c ",(0,s.jsx)(n.code,{children:"BusinessService"})," \u4e4b\u95f4\u5c31\u5b9e\u73b0\u4e86\u89e3\u8026\uff0c\u4e0d\u518d\u4f9d\u8d56\u4e8e\u5177\u4f53\u7684 ",(0,s.jsx)(n.code,{children:"BusinessService"})," \u5b9e\u4f8b\u3002"]}),"\n",(0,s.jsx)(n.p,{children:"\u8fd9\u5c31\u662f\u4f9d\u8d56\u6ce8\u5165/\u63a7\u5236\u53cd\u8f6c\u6700\u7ecf\u5178\u7684\u4f8b\u5b50\u3002"}),"\n",(0,s.jsx)(n.h3,{id:"1272-\u6ce8\u518c\u6cdb\u578b\u5b9e\u4f8b",children:"12.7.2 \u6ce8\u518c\u6cdb\u578b\u5b9e\u4f8b"}),"\n",(0,s.jsxs)(n.p,{children:["\u521b\u5efa ",(0,s.jsx)(n.code,{children:"IBusinessService"})," \u63a5\u53e3\u548c ",(0,s.jsx)(n.code,{children:"BusinessService"})," \u5b9e\u73b0\u7c7b\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {7,12}",children:"using Furion.Core;\r\nusing Furion.DatabaseAccessor;\r\nusing Furion.DependencyInjection;\r\n\r\nnamespace Furion.Application\r\n{\r\n public interface IBusinessService\r\n {\r\n Person Get(int id);\r\n }\r\n\r\n public class BusinessService : IBusinessService, ITransient\r\n {\r\n private readonly IRepository _personRepository;\r\n\r\n public BusinessService(IRepository personRepository)\r\n {\r\n _personRepository = personRepository;\r\n }\r\n\r\n public Person Get(int id)\r\n {\r\n return _personRepository.Find(id);\r\n }\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(n.p,{children:["\u521b\u5efa ",(0,s.jsx)(n.code,{children:"PersonController"})," \u63a7\u5236\u5668\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {11,19}",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 [ApiController]\r\n public class PersonController : ControllerBase\r\n {\r\n private readonly IBusinessService _businessService;\r\n public PersonController(IBusinessService businessService)\r\n {\r\n _businessService = businessService;\r\n }\r\n\r\n [HttpGet]\r\n public IActionResult Get(int id)\r\n {\r\n var person = _businessService.Get(id);\r\n return new JsonResult(person);\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsx)(n.h3,{id:"1273-\u4e00\u4e2a\u63a5\u53e3\u591a\u4e2a\u5b9e\u73b0",children:"12.7.3 \u4e00\u4e2a\u63a5\u53e3\u591a\u4e2a\u5b9e\u73b0"}),"\n",(0,s.jsxs)(n.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4e00\u4e2a\u63a5\u53e3\u53ea\u5bf9\u5e94\u4e00\u4e2a\u5b9e\u73b0\u7c7b\uff0c\u4f46\u6709\u4e9b\u7279\u6b8a\u60c5\u51b5\uff0c\u9700\u8981\u591a\u4e2a\u5b9e\u73b0\u7c7b\u6ce8\u518c\u540c\u4e00\u4e2a\u63a5\u53e3\uff0c\u5982 ",(0,s.jsx)(n.code,{children:"DbContext"})," \u591a\u6570\u636e\u5e93\u60c5\u51b5\u3002"]}),"\n",(0,s.jsxs)(n.p,{children:["\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165 ",(0,s.jsx)(n.code,{children:"Func"})," \u59d4\u6258\u6765\u89e3\u6790\u591a\u4e2a\u5b9e\u4f8b\uff0c\u5176\u4e2d\u59d4\u6258\u7684\u53c2\u6570\u5206\u522b\u4e3a\uff1a"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\u53c2\u6570 1\uff1a",(0,s.jsx)(n.code,{children:"string"})," \u7c7b\u578b\uff0c\u4e0d\u540c\u5b9e\u73b0\u7c7b\u552f\u4e00\u6807\u8bc6\uff0c\u9ed8\u8ba4\u4e3a ",(0,s.jsx)(n.code,{children:"nameof(\u5b9e\u73b0\u7c7b)"})," \u540d\u79f0"]}),"\n",(0,s.jsxs)(n.li,{children:["\u53c2\u6570 2\uff1a",(0,s.jsx)(n.code,{children:"Type"})," \u7c7b\u578b\uff0c",(0,s.jsx)(n.code,{children:"IPrivateDependency"})," \u6d3e\u751f\u63a5\u53e3\uff0c\u4e5f\u5c31\u662f ",(0,s.jsx)(n.code,{children:"ITransient"}),"\u3001",(0,s.jsx)(n.code,{children:"IScoped"}),"\u3001",(0,s.jsx)(n.code,{children:"ISingleton"})]}),"\n",(0,s.jsxs)(n.li,{children:["\u8fd4\u56de\u503c\uff1a",(0,s.jsx)(n.code,{children:"object"})," \u7c7b\u578b\uff0c\u8fd4\u56de\u5177\u4f53\u7684\u5b9e\u73b0\u7c7b\u5b9e\u4f8b"]}),"\n"]}),"\n",(0,s.jsxs)(n.p,{children:["\u521b\u5efa ",(0,s.jsx)(n.code,{children:"IBusinessService"})," \u63a5\u53e3\u548c ",(0,s.jsx)(n.code,{children:"BusinessService"}),"\u3001",(0,s.jsx)(n.code,{children:"OtherBusinessService"})," \u4e24\u4e2a\u5b9e\u73b0\u7c7b\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {5,10,18}",children:'using Furion.DependencyInjection;\r\n\r\nnamespace Furion.Application\r\n{\r\n public interface IBusinessService\r\n {\r\n string GetName();\r\n }\r\n\r\n public class BusinessService : IBusinessService, ITransient\r\n {\r\n public string GetName()\r\n {\r\n return "\u6211\u662f\uff1a" + nameof(BusinessService);\r\n }\r\n }\r\n\r\n public class OtherBusinessService : IBusinessService, ITransient\r\n {\r\n public string GetName()\r\n {\r\n return "\u6211\u662f\uff1a" + nameof(OtherBusinessService);\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(n.admonition,{title:"\u65b0\u7248\u672c\uff0c\u63a8\u8350\u4f7f\u7528",type:"tip",children:[(0,s.jsxs)(n.p,{children:["\u5728 ",(0,s.jsx)(n.code,{children:"Furion 3.8.6+"})," \u7248\u672c\u4e4b\u540e\u65b0\u589e\u4e86 ",(0,s.jsx)(n.code,{children:"INamedServiceProvider"})," \u670d\u52a1\u63a5\u53e3\uff0c\u53ef\u66ff\u4ee3 ",(0,s.jsx)(n.code,{children:"Func"})," \u65b9\u5f0f\uff1a"]}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {8,15-17,19-23}",children:'using Furion.Application.Services;\r\n\r\nnamespace Furion.Application;\r\n\r\npublic class TestNamedServices : IDynamicApiController\r\n{\r\n private readonly INamedServiceProvider _namedServiceProvider;\r\n public TestNamedServices(INamedServiceProvider namedServiceProvider)\r\n {\r\n _namedServiceProvider = namedServiceProvider;\r\n }\r\n\r\n public string GetName()\r\n {\r\n // \u7b2c\u4e00\u79cd\u7528\u6cd5\uff0c\u901a\u8fc7\u53cd\u5c04\u89e3\u6790\u670d\u52a1\u5468\u671f\uff0c\u6027\u80fd\u6709\u635f\u8017\r\n var service1 = _namedServiceProvider.GetService(nameof(BusinessService));\r\n var service2 = _namedServiceProvider.GetService(nameof(OtherBusinessService));\r\n\r\n // \u7b2c\u4e8c\u79cd\u7528\u6cd5\uff0c\u65e0\u9700\u53cd\u5c04\uff0c\u6ce8\u610f\u4e0b\u9762\u7684\u6cdb\u578b\u53c2\u6570\u4f20\u5165\u7684\u662f\u751f\u547d\u5468\u671f\u4f9d\u8d56\u63a5\u53e3\uff0cITransient, IScoped, ISingleton\r\n var service3 = _namedServiceProvider.GetService(nameof(BusinessService));\r\n var service4 = _namedServiceProvider.GetService(nameof(OtherBusinessService));\r\n\r\n return service1.GetName() + "-" + service2.GetName() + "-" + service3.GetName() + "-" + service4.GetName();\r\n }\r\n}\n'})})]}),"\n",(0,s.jsxs)(n.admonition,{type:"important",children:[(0,s.jsxs)(n.mdxAdmonitionTitle,{children:["\u4e0d\u518d\u63a8\u8350 ",(0,s.jsx)(n.code,{children:"Func"})," \u65b9\u5f0f"]}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {15,17,18}",children:'using Furion.Application;\r\nusing Furion.DependencyInjection;\r\nusing Microsoft.AspNetCore.Mvc;\r\nusing System;\r\n\r\nnamespace Furion.Web.Entry.Controllers\r\n{\r\n [Route("api/[controller]")]\r\n [ApiController]\r\n public class ValueController : ControllerBase\r\n {\r\n private readonly IBusinessService _businessService;\r\n private readonly IBusinessService _otherBusinessService;\r\n\r\n public ValueController(Func resolveNamed)\r\n {\r\n _businessService = resolveNamed("BusinessService", default) as IBusinessService;\r\n _otherBusinessService = resolveNamed("OtherBusinessService", default) as IBusinessService;\r\n }\r\n\r\n [HttpGet]\r\n public string GetName()\r\n {\r\n return _businessService.GetName() + "----------" + _otherBusinessService.GetName();\r\n }\r\n }\r\n}\n'})})]}),"\n",(0,s.jsx)("img",{src:(0,c.Z)("img/di2.gif")}),"\n",(0,s.jsxs)(n.admonition,{title:"\u5c0f\u77e5\u8bc6",type:"tip",children:[(0,s.jsxs)(n.p,{children:["\u5982\u679c\u9700\u8981\u81ea\u5b9a\u4e49\u89e3\u6790\u540d\u79f0\uff0c\u53ea\u9700\u8981\u8d34 ",(0,s.jsx)(n.code,{children:'[Injection(Named = "\u540d\u79f0")]'})," \u5373\u53ef\uff0c\u5982\uff1a"]}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {5,11}",children:'using Furion.DependencyInjection;\r\n\r\nnamespace Furion.Application\r\n{\r\n [Injection(Named = "BusName1")]\r\n public class BusinessService : IBusinessService, ITransient\r\n {\r\n // ...\r\n }\r\n\r\n [Injection(Named = "BusName2")]\r\n public class OtherBusinessService : IBusinessService, ITransient\r\n {\r\n // ...\r\n }\r\n}\n'})}),(0,s.jsx)(n.p,{children:"\u89e3\u6790\u670d\u52a1\uff1a"}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'_businessService = resolveNamed("BusName1", default) as IBusinessService;\r\n_otherBusinessService = resolveNamed("BusName2", default) as IBusinessService;\n'})})]}),"\n",(0,s.jsx)(n.h3,{id:"1274-\u65e0\u63a5\u53e3\u65b9\u5f0f",children:"12.7.4 \u65e0\u63a5\u53e3\u65b9\u5f0f"}),"\n",(0,s.jsx)(n.p,{children:"\u6709\u4e9b\u65f6\u5019\uff0c\u6211\u4eec\u4e0d\u60f3\u5b9a\u4e49\u63a5\u53e3\uff0c\u800c\u662f\u60f3\u628a\u5b9e\u4f8b\u7c7b\u4f5c\u4e3a\u53ef\u4f9d\u8d56\u6ce8\u5165\u7684\u5bf9\u8c61\uff0c\u5982 MVC \u4e2d\u7684\u63a7\u5236\u5668\u3002"}),"\n",(0,s.jsxs)(n.p,{children:["\u521b\u5efa ",(0,s.jsx)(n.code,{children:"SelfService"})," \u5b9e\u4f8b\u7c7b\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {7,11}",children:"using Furion.Core;\r\nusing Furion.DatabaseAccessor;\r\nusing Furion.DependencyInjection;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class SelfService : ITransient\r\n {\r\n private readonly IRepository _personRepository;\r\n\r\n public SelfService(IRepository personRepository)\r\n {\r\n _personRepository = personRepository;\r\n }\r\n\r\n public Person Get(int id)\r\n {\r\n return _personRepository.Find(id);\r\n }\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(n.p,{children:["\u521b\u5efa ",(0,s.jsx)(n.code,{children:"ValueController"})," \u63a7\u5236\u5668\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {13,21}",children:'using Furion.Application;\r\nusing Furion.Core;\r\nusing Microsoft.AspNetCore.Mvc;\r\n\r\nnamespace Furion.Web.Entry.Controllers\r\n{\r\n [Route("api/[controller]")]\r\n [ApiController]\r\n public class ValueController : ControllerBase\r\n {\r\n private readonly SelfService _selfService;\r\n\r\n public ValueController(SelfService selfService)\r\n {\r\n _selfService = selfService;\r\n }\r\n\r\n [HttpGet]\r\n public Person Get(int id)\r\n {\r\n return _selfService.Get(id);\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(n.h2,{id:"128-injection-\u7279\u6027\u914d\u7f6e",children:["12.8 ",(0,s.jsx)(n.code,{children:"[Injection]"})," \u7279\u6027\u914d\u7f6e"]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b ",(0,s.jsx)(n.code,{children:"[Injection]"})," \u7279\u6027\u53ef\u4ee5\u6539\u53d8\u6ce8\u518c\u65b9\u5f0f\uff0c\u540c\u65f6\u8fd8\u80fd\u914d\u7f6e ",(0,s.jsx)(n.code,{children:"AOP"})," \u62e6\u622a\u3002"]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"[Injection]"})," \u63d0\u4f9b\u4ee5\u4e0b\u914d\u7f6e\u652f\u6301\uff1a"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Action"}),"\uff1a\u914d\u7f6e\u6ce8\u518c\u884c\u4e3a\uff0c",(0,s.jsx)(n.code,{children:"InjectionActions"})," \u7c7b\u578b\uff0c\u53ef\u9009\u503c\uff1a","\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Add"}),"\uff1a",(0,s.jsx)(n.strong,{children:"\u9ed8\u8ba4\u503c"}),"\uff0c\u8868\u793a\u65e0\u9650\u5236\u6dfb\u52a0\u6ce8\u518c\u670d\u52a1\uff0c\u8be5\u65b9\u5f0f\u652f\u6301\u4e00\u4e2a\u63a5\u53e3\u591a\u4e2a\u5b9e\u73b0"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"TryAdd"}),"\uff1a\u8868\u793a\u6ce8\u518c\u5df2\u5b58\u5728\u5219\u8df3\u8fc7\u6ce8\u518c"]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Pattern"}),"\uff1a\u914d\u7f6e\u6ce8\u518c\u9009\u9879\uff0c",(0,s.jsx)(n.code,{children:"InjectionPatterns"})," \u7c7b\u578b\uff0c\u53ef\u9009\u503c\uff1a","\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Self"}),"\uff1a\u53ea\u6ce8\u518c\u81ea\u5df1"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"FirstInterface"}),"\uff1a\u53ea\u6ce8\u518c\u7b2c\u4e00\u4e2a\u63a5\u53e3"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"SelfWithFirstInterface"}),"\uff1a\u6ce8\u518c\u81ea\u5df1\u548c\u7b2c\u4e00\u4e2a\u63a5\u53e3"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"ImplementedInterfaces"}),"\uff1a\u6ce8\u518c\u6240\u6709\u63a5\u53e3"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"All"}),"\uff1a\u6ce8\u518c\u81ea\u5df1\u5305\u62ec\u6240\u6709\u63a5\u53e3 \uff0c",(0,s.jsx)(n.strong,{children:"\u9ed8\u8ba4\u503c"})]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Named"}),"\uff1a\u914d\u7f6e\u5b9e\u4f8b\u522b\u540d\uff0c\u901a\u8fc7\u522b\u540d\u53ef\u4ee5\u89e3\u6790\u63a5\u53e3\uff0c\u5982\u540c\u4e00\u4e2a\u63a5\u53e3\u6709\u591a\u4e2a\u5b9e\u73b0\uff0c\u90a3\u4e48\u53ef\u4ee5\u901a\u8fc7\u522b\u540d\u89e3\u6790\u4e0d\u540c\u7684\u5b9e\u73b0\uff0c\u9ed8\u8ba4\u503c\u4e3a\u5b9e\u73b0\u7c7b\u7684\u7c7b\u540d"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Order"}),"\uff1a\u6ce8\u518c\u6392\u5e8f\uff0c\u6570\u5b57\u8d8a\u5927\uff0c\u5219\u8d8a\u5728\u6700\u540e\u6ce8\u518c\uff0c\u9ed8\u8ba4 ",(0,s.jsx)(n.code,{children:"0"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Proxy"}),"\uff1a\u914d\u7f6e\u4ee3\u7406\u62e6\u622a\u7c7b\u578b\uff0c\u4e5f\u5c31\u662f ",(0,s.jsx)(n.code,{children:"AOP"}),"\uff0c",(0,s.jsxs)(n.strong,{children:["\u4ee3\u7406\u7c7b\u578b\u5fc5\u987b\u7ee7\u627f ",(0,s.jsx)(n.code,{children:"AspectDispatchProxy"})," \u7c7b\u548c ",(0,s.jsx)(n.code,{children:"IDispatchProxy"})," \u63a5\u53e3"]}),"\uff0c\u65e0\u9ed8\u8ba4\u503c"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"ExceptInterfaces"}),"\uff1a\u914d\u7f6e\u5ffd\u7565\u6ce8\u518c\u7684\u63a5\u53e3\uff0c",(0,s.jsx)(n.code,{children:"Type[]"})," \u7c7b\u578b"]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"129-\u81ea\u5b9a\u4e49\u9ad8\u7ea7\u6ce8\u518c",children:"12.9 \u81ea\u5b9a\u4e49\u9ad8\u7ea7\u6ce8\u518c"}),"\n",(0,s.jsxs)(n.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c",(0,s.jsx)(n.code,{children:"Furion"})," \u63d0\u4f9b\u7684\u6ce8\u518c\u65b9\u5f0f\u53ef\u4ee5\u6ee1\u8db3\u5927\u591a\u6570\u4f9d\u8d56\u6ce8\u5165\u7684\u9700\u6c42\uff0c\u5982\u6709\u7279\u522b\u6ce8\u518c\u9700\u6c42\uff0c\u53ea\u9700\u8981\u5728 ",(0,s.jsx)(n.code,{children:"Startup"})," \u4e2d\u914d\u7f6e\u5373\u53ef\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"services.AddScoped(typeof(ISpecService), provider = > {\r\n // \u81ea\u5b9a\u4e49\u4efb\u4f55\u521b\u5efa\u5b9e\u4f8b\u7684\u65b9\u5f0f\r\n var instance = new SpecService(); // \u6216\u8005\u53ef\u4ee5\u901a\u8fc7 AOP\u63d2\u4ef6\u8fd4\u56de\u4ee3\u7406\u5b9e\u4f8b\r\n\r\n return instance;\r\n});\n"})}),"\n",(0,s.jsx)(n.admonition,{title:"\u8865\u5145\u8bf4\u660e",type:"note",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u4e2d\u7684 ",(0,s.jsx)(n.code,{children:"AppDbContext"})," \u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u8fd8\u6709 ",(0,s.jsx)(n.code,{children:"ISqlDispatchProxy"})," \u90fd\u662f\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u521b\u5efa\u7684\u3002"]})}),"\n",(0,s.jsx)(n.admonition,{title:"\u77e5\u8bc6\u5bfc\u822a",type:"tip",children:(0,s.jsxs)(n.p,{children:["\u60f3\u4e86\u89e3\u66f4\u591a\u81ea\u5b9a\u4e49\u9ad8\u7ea7\u4e2d\u6ce8\u518c\uff0c\u53ef\u67e5\u9605 \u3010",(0,s.jsx)(n.a,{href:"https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-5.0",children:"ASP.NET Core \u4f9d\u8d56\u6ce8\u5165"}),"\u3011 \u5b98\u65b9\u6587\u6863\u3002"]})}),"\n",(0,s.jsxs)(n.h2,{id:"1210-appsettingsjson-\u914d\u7f6e\u6ce8\u518c",children:["12.10 ",(0,s.jsx)(n.code,{children:"appsettings.json"})," \u914d\u7f6e\u6ce8\u518c"]}),"\n",(0,s.jsx)(n.p,{children:"\u9664\u4e86\u5728\u4ee3\u7801\u4e2d\u5b9e\u73b0\u4f9d\u8d56\u6ce8\u5165\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u4f9d\u8d56\u6ce8\u5165\uff0c\u65e0\u9700\u4fee\u6539\u4ee3\u7801\u6216\u91cd\u65b0\u7f16\u8bd1\u5373\u53ef\u5b9e\u73b0\u70ed\u63d2\u62d4\uff08\u63d2\u4ef6\uff09\u6548\u679c\u3002\u914d\u7f6e\u5982\u4e0b\uff1a"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",metastring:"showLineNumbers {2}",children:'{\r\n "DependencyInjectionSettings": {\r\n "Definitions": [\r\n {\r\n "Interface": "Furion.Application;Furion.Application.ITestService",\r\n "Service": "Furion.Application;Furion.Application.TestService",\r\n "RegisterType": "Transient",\r\n "Action": "Add",\r\n "Pattern": "SelfWithFirstInterface",\r\n "Named": "TestService",\r\n "Order": 1,\r\n "Proxy": "Furion.Application;Furion.Application.LogDispathProxy"\r\n }\r\n ]\r\n }\r\n}\n'})}),"\n",(0,s.jsx)(n.p,{children:"\u914d\u7f6e\u8bf4\u660e\uff1a"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"DependencyInjectionSettings"}),"\uff1a\u4f9d\u8d56\u6ce8\u5165\u914d\u7f6e\u6839\u8282\u70b9","\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Definitions"}),"\uff1a\u52a8\u6001\u4f9d\u8d56\u6ce8\u5165\u914d\u7f6e\u8282\u70b9\uff0c",(0,s.jsx)(n.code,{children:"ExternalService"})," \u6570\u7ec4\u7c7b\u578b","\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"ExternalService"}),"\uff1a\u914d\u7f6e\u5355\u4e2a\u4f9d\u8d56\u6ce8\u5165\u4fe1\u606f","\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Interface"}),"\uff1a\u914d\u7f6e\u4f9d\u8d56\u63a5\u53e3\u4fe1\u606f\uff0c\u683c\u5f0f\uff1a",(0,s.jsx)(n.code,{children:"\u7a0b\u5e8f\u96c6\u540d\u79f0;\u63a5\u53e3\u5b8c\u6574\u540d\u79f0"}),"\uff0c\u5982\uff1a",(0,s.jsx)(n.code,{children:"Furion.Application;Furion.Application.ITestService"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Service"}),"\uff1a\u914d\u7f6e\u63a5\u53e3\u5b9e\u73b0\u4fe1\u606f\uff0c\u683c\u5f0f\u540c\u4e0a"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"RegisterType"}),"\uff1a\u914d\u7f6e\u4f9d\u8d56\u6ce8\u5165\u7684\u5bf9\u8c61\u751f\u5b58\u671f\uff0c\u53d6\u503c\uff1a",(0,s.jsx)(n.code,{children:"Transient"}),"\uff0c",(0,s.jsx)(n.code,{children:"Scoped"}),"\uff0c",(0,s.jsx)(n.code,{children:"Singleton"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Action"}),"\uff1a\u6ce8\u518c\u884c\u4e3a\uff0c\u53ef\u9009\u503c\uff1a",(0,s.jsx)(n.code,{children:"Add"}),"\uff0c",(0,s.jsx)(n.code,{children:"TryAdd"}),"\uff0c\u53c2\u89c1 ",(0,s.jsx)(n.a,{href:"#128-injection-%E7%89%B9%E6%80%A7%E9%85%8D%E7%BD%AE",children:"#128-injection-\u7279\u6027\u914d\u7f6e"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Pattern"}),"\uff1a\u6ce8\u518c\u9009\u9879\uff0c\u53c2\u89c1 ",(0,s.jsx)(n.a,{href:"#128-injection-%E7%89%B9%E6%80%A7%E9%85%8D%E7%BD%AE",children:"#128-injection-\u7279\u6027\u914d\u7f6e"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Named"}),"\uff1a\u6ce8\u518c\u522b\u540d\uff0c\u53c2\u89c1 ",(0,s.jsx)(n.a,{href:"#128-injection-%E7%89%B9%E6%80%A7%E9%85%8D%E7%BD%AE",children:"#128-injection-\u7279\u6027\u914d\u7f6e"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Order"}),"\uff1a\u6ce8\u518c\u6392\u5e8f\uff0c\u53c2\u89c1 ",(0,s.jsx)(n.a,{href:"#128-injection-%E7%89%B9%E6%80%A7%E9%85%8D%E7%BD%AE",children:"#128-injection-\u7279\u6027\u914d\u7f6e"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Proxy"}),"\uff1a\u914d\u7f6e\u4ee3\u7406\u62e6\u622a\uff0c\u683c\u5f0f\uff1a",(0,s.jsx)(n.code,{children:"\u7a0b\u5e8f\u96c6\u540d\u79f0;\u4ee3\u7406\u7c7b\u5b8c\u6574\u540d\u79f0"}),"\uff0c\u53c2\u89c1 ",(0,s.jsx)(n.a,{href:"#128-injection-%E7%89%B9%E6%80%A7%E9%85%8D%E7%BD%AE",children:"#128-injection-\u7279\u6027\u914d\u7f6e"})]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.admonition,{title:"\u5173\u4e8e\u5916\u90e8\u7a0b\u5e8f\u96c6",type:"important",children:[(0,s.jsx)(n.p,{children:"\u5982\u679c\u52a8\u6001\u6ce8\u5165\u7684\u5bf9\u8c61\u662f\u5916\u90e8\u7a0b\u5e8f\u96c6\uff0c\u90a3\u4e48\u9996\u5148\u5148\u6ce8\u518c\u5916\u90e8\u7a0b\u5e8f\u96c6\uff1a"}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",metastring:"showLineNumbers",children:'{\r\n "AppSettings": {\r\n "ExternalAssemblies": ["\u5916\u90e8\u7a0b\u5e8f\u96c6\u540d\u79f0", "Taobao.Pay"] // \u652f\u6301\u591a\u4e2a\r\n }\r\n}\n'})})]}),"\n",(0,s.jsx)(n.h2,{id:"1211-\u6ce8\u518c\u987a\u5e8f\u548c\u4f18\u5148\u7ea7",children:"12.11 \u6ce8\u518c\u987a\u5e8f\u548c\u4f18\u5148\u7ea7"}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u4e2d\uff0c\u9ed8\u8ba4\u6ce8\u518c\u987a\u5e8f\u662f\u6309\u7167\u7a0b\u5e8f\u96c6\u626b\u63cf\u987a\u5e8f\u8fdb\u884c\u6ce8\u518c\uff0c\u5982\u679c\u9700\u8981\u6539\u53d8\u6ce8\u518c\u987a\u5e8f\uff0c\u53ef\u901a\u8fc7 ",(0,s.jsx)(n.code,{children:"[Injection(Order)]"})," \u7279\u6027\u6307\u5b9a\uff0c",(0,s.jsx)(n.code,{children:"Order"})," \u503c\u8d8a\u5927\uff0c\u5219\u8d8a\u5728\u6700\u540e\u6ce8\u518c\u3002"]}),"\n",(0,s.jsxs)(n.p,{children:["\u53e6\u5916 ",(0,s.jsx)(n.code,{children:"appsettings.json"})," \u914d\u7f6e\u7684\u4f18\u5148\u7ea7\u6700\u5927\uff0c",(0,s.jsx)(n.code,{children:"appsettings.json"})," \u914d\u7f6e\u7684\u6ce8\u518c\u4f1a\u8986\u76d6\u4e4b\u524d\u6240\u6709\u6ce8\u518c\u3002"]}),"\n",(0,s.jsxs)(n.h2,{id:"1212-aop-\u6ce8\u518c\u62e6\u622a",children:["12.12 ",(0,s.jsx)(n.code,{children:"Aop"})," \u6ce8\u518c\u62e6\u622a"]}),"\n",(0,s.jsx)(n.admonition,{title:"\u5173\u4e8e\u52a8\u6001 API \u548c\u670d\u52a1\u7684\u533a\u522b",type:"warning",children:(0,s.jsxs)(n.p,{children:["\u5982\u679c\u60a8\u7684\u670d\u52a1\u662f\u52a8\u6001 API\uff0c\u90a3\u4e48\u8bf7\u4f7f\u7528 ",(0,s.jsx)(n.a,{href:"/docs/dynamic-api-controller#511-%E5%85%B3%E4%BA%8E-aop-%E6%8B%A6%E6%88%AA",children:"\u52a8\u6001 API - AOP \u62e6\u622a"}),"\uff0c\u539f\u56e0\u662f\u52a8\u6001 API \u672c\u8d28\u662f\u63a7\u5236\u5668\uff0c\u6240\u4ee5\u91c7\u7528 ",(0,s.jsx)(n.code,{children:"Filter"})," \u65b9\u5f0f\u3002"]})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"AOP"})," \u662f\u975e\u5e38\u91cd\u8981\u7684\u601d\u60f3\u548c\u6280\u672f\uff0c\u4e5f\u5c31\u662f ",(0,s.jsx)(n.code,{children:"\u9762\u5411\u5207\u9762"})," \u7f16\u7a0b\uff0c\u53ef\u4ee5\u8ba9\u6211\u4eec\u5728\u4e0d\u6539\u52a8\u539f\u6765\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u8fdb\u884c\u52a8\u6001\u7be1\u6539\u4e1a\u52a1\u4ee3\u7801\u3002"]}),"\n",(0,s.jsxs)(n.p,{children:["\u5728 ",(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u4e2d\uff0c\u5b9e\u73b0 ",(0,s.jsx)(n.code,{children:"Aop"})," \u975e\u5e38\u7b80\u5355\uff0c\u5982\uff1a"]}),"\n",(0,s.jsxs)(n.p,{children:["\u5047\u8bbe\u6211\u4eec\u6709 ",(0,s.jsx)(n.code,{children:"ITestService"})," \u548c ",(0,s.jsx)(n.code,{children:"TestService"})," \u4e24\u4e2a\u7c7b\u578b\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"public interface ITestService\r\n{\r\n string SayHello(string word);\r\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'public class TestService: ITestService, ITransient\r\n{\r\n public string SayHello(string word)\r\n {\r\n return $"Hello {word}";\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(n.p,{children:["\u73b0\u5728\u6211\u4eec\u6709\u4e00\u4e2a\u9700\u6c42\uff0c\u6211\u4eec\u5e0c\u671b\u8c03\u7528 ",(0,s.jsx)(n.code,{children:"SayHello"})," \u7684\u65f6\u5019\u53ef\u4ee5\u8bb0\u5f55\u65e5\u5fd7\u548c\u6743\u9650\u63a7\u5236\uff08\u4e4b\u524d\u6ca1\u6709\u8003\u8651\u5230\u7684\u9700\u6c42\uff09\u3002"]}),"\n",(0,s.jsxs)(n.p,{children:["\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u53ea\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u4ee3\u7406\u7c7b\u5373\u53ef\uff0c\u5982 ",(0,s.jsx)(n.code,{children:"LogDispatchProxy"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {1,3,7,25,37,48}",children:'using Furion.DependencyInjection;\r\nusing System;\r\nusing System.Reflection;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class LogDispatchProxy : AspectDispatchProxy, IDispatchProxy\r\n {\r\n /// \r\n /// \u5f53\u524d\u670d\u52a1\u5b9e\u4f8b\r\n /// \r\n public object Target { get; set; }\r\n\r\n /// \r\n /// \u670d\u52a1\u63d0\u4f9b\u5668\uff0c\u53ef\u4ee5\u7528\u6765\u89e3\u6790\u670d\u52a1\uff0c\u5982\uff1aServices.GetService()\r\n /// \r\n public IServiceProvider Services { get; set; }\r\n\r\n /// \r\n /// \u62e6\u622a\u65b9\u6cd5\r\n /// \r\n /// \r\n /// \r\n /// \r\n public override object Invoke(MethodInfo method, object[] args)\r\n {\r\n Console.WriteLine("SayHello \u65b9\u6cd5\u88ab\u8c03\u7528\u4e86");\r\n\r\n var result = method.Invoke(Target, args);\r\n\r\n Console.WriteLine("SayHello \u65b9\u6cd5\u8fd4\u56de\u503c\uff1a" + result);\r\n\r\n return result;\r\n }\r\n\r\n // \u5f02\u6b65\u65e0\u8fd4\u56de\u503c\r\n public async override Task InvokeAsync(MethodInfo method, object[] args)\r\n {\r\n Console.WriteLine("SayHello \u65b9\u6cd5\u88ab\u8c03\u7528\u4e86");\r\n\r\n var task = method.Invoke(Target, args) as Task;\r\n await task;\r\n\r\n Console.WriteLine("SayHello \u65b9\u6cd5\u8c03\u7528\u5b8c\u6210");\r\n }\r\n\r\n // \u5f02\u6b65\u5e26\u8fd4\u56de\u503c\r\n public async override Task InvokeAsyncT(MethodInfo method, object[] args)\r\n {\r\n Console.WriteLine("SayHello \u65b9\u6cd5\u88ab\u8c03\u7528\u4e86");\r\n\r\n var taskT = method.Invoke(Target, args) as Task;\r\n var result = await taskT;\r\n\r\n Console.WriteLine("SayHello \u65b9\u6cd5\u8fd4\u56de\u503c\uff1a" + result);\r\n\r\n return result;\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsx)(n.admonition,{title:"\u83b7\u53d6\u7279\u6027",type:"important",children:(0,s.jsxs)(n.p,{children:["\u5982\u679c\u9700\u8981\u83b7\u53d6\u65b9\u6cd5\u7684\u7279\u6027\uff0c\u53ea\u9700\u8981\u901a\u8fc7 ",(0,s.jsx)(n.code,{children:"method.GetActualCustomAttribute()"})," \u5373\u53ef\u3002\u6240\u6709\u83b7\u53d6\u771f\u5b9e\u7684\u7279\u6027\u7edf\u4e00\u91c7\u7528 ",(0,s.jsx)(n.code,{children:"method.GetActual....()"})," \u65b9\u6cd5\u5f00\u5934\u3002"]})}),"\n",(0,s.jsxs)(n.p,{children:["\u4e4b\u540e\u6211\u4eec\u53ea\u9700\u8981\u4e3a ",(0,s.jsx)(n.code,{children:"TestService"})," \u589e\u52a0 ",(0,s.jsx)(n.code,{children:"[Injection]"})," \u7279\u6027\u5373\u53ef\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {1}",children:'[Injection(Proxy = typeof(LogDispatchProxy))]\r\npublic class TestService: ITestService, ITransient\r\n{\r\n public string SayHello(string word)\r\n {\r\n return $"Hello {word}";\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(n.p,{children:["\u4e4b\u540e ",(0,s.jsx)(n.code,{children:"SayHello"})," \u65b9\u6cd5\u88ab\u8c03\u7528\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u62e6\u622a\u4e86\uff0c\u6bd4\u5982\u8fd9\u91cc\u5199\u65e5\u5fd7\u3002"]}),"\n",(0,s.jsxs)(n.h3,{id:"12121-\u5168\u5c40aop\u62e6\u622a",children:["12.12.1 ",(0,s.jsx)(n.code,{children:"\u5168\u5c40Aop\u62e6\u622a"})]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u4e5f\u63d0\u4f9b\u4e86\u5168\u5c40\u62e6\u622a\u7684\u65b9\u5f0f\uff0c\u53ea\u9700\u8981\u5c06 ",(0,s.jsx)(n.code,{children:"IDispatchProxy"})," \u4fee\u6539\u4e3a ",(0,s.jsx)(n.code,{children:"IGlobalDispatchProxy"})," \u5373\u53ef\u3002"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"using Furion;\r\nusing System.Reflection;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class LogDispatchProxy : AspectDispatchProxy, IGlobalDispatchProxy\r\n {\r\n // ....\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(n.p,{children:["\u8fd9\u6837\u5c31\u4f1a\u62e6\u622a\u6240\u6709\u7684 ",(0,s.jsx)(n.code,{children:"Service"}),"\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u901a\u8fc7\u7ed9\u7279\u5b9a\u7c7b\u8d34 ",(0,s.jsx)(n.code,{children:"[SuppressProxy]"})," \u8df3\u8fc7\u5168\u5c40\u62e6\u622a\u64cd\u4f5c\u3002"]}),"\n",(0,s.jsx)(n.admonition,{title:"\u62e6\u622a\u4f18\u5148\u7ea7",type:"important",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"[SuppressProxy]"})," > ",(0,s.jsx)(n.code,{children:"[Injection(Proxy = typeof(LogDispatchProxy))]"})," > ",(0,s.jsx)(n.code,{children:"\u5168\u5c40\u62e6\u622a"}),"\u3002"]})}),"\n",(0,s.jsxs)(n.h3,{id:"12122-aop-\u6ce8\u5165\u89e3\u6790\u670d\u52a1",children:["12.12.2 ",(0,s.jsx)(n.code,{children:"AOP"})," \u6ce8\u5165\u89e3\u6790\u670d\u52a1"]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u672a\u63d0\u4f9b ",(0,s.jsx)(n.code,{children:"Proxy"})," \u6784\u9020\u51fd\u6570\u6ce8\u5165\u529f\u80fd\uff0c\u4f46\u662f\u63d0\u4f9b\u4e86 ",(0,s.jsx)(n.code,{children:"Services"})," \u5c5e\u6027\uff0c\u5982\u679c\u9700\u8981\u89e3\u6790\u670d\u52a1\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"var someServices = Services.GetService(); // \u63a8\u8350\u65b9\u5f0f\r\n// \u6216\r\nvar someServices = App.GetService();\n"})}),"\n",(0,s.jsxs)(n.h3,{id:"12123-aop-\u7684\u4f5c\u7528",children:["12.12.3 ",(0,s.jsx)(n.code,{children:"AOP"})," \u7684\u4f5c\u7528"]}),"\n",(0,s.jsx)(n.p,{children:"\u8fd9\u79cd\u9762\u5411\u5207\u9762\u7684\u80fd\u529b\uff08\u52a8\u6001\u62e6\u622a/\u4ee3\u7406\uff09\u53ef\u4ee5\u5b9e\u73b0\u5f88\u591a\u5f88\u591a\u529f\u80fd\uff0c\u5982\uff1a"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"\u52a8\u6001\u65e5\u5fd7\u8bb0\u5f55"}),"\n",(0,s.jsx)(n.li,{children:"\u52a8\u6001\u4fee\u6539\u53c2\u6570"}),"\n",(0,s.jsx)(n.li,{children:"\u52a8\u6001\u4fee\u6539\u8fd4\u56de\u503c"}),"\n",(0,s.jsx)(n.li,{children:"\u52a8\u6001\u65b9\u6cd5\u91cd\u5b9a\u5411"}),"\n",(0,s.jsx)(n.li,{children:"\u52a8\u6001\u4fee\u6539\u4ee3\u7801\u903b\u8f91"}),"\n",(0,s.jsx)(n.li,{children:"\u52a8\u6001\u5b9e\u73b0\u5f02\u5e38\u76d1\u542c"}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"\u8fd8\u53ef\u4ee5\u505a\u66f4\u591a\u66f4\u591a\u7684\u4e8b\u60c5\u3002"}),"\n",(0,s.jsxs)(n.h2,{id:"1213-\u5728\u975e-web-\u6216\u591a\u7ebf\u7a0b\u89e3\u6790\u670d\u52a1",children:["12.13 \u5728\u975e ",(0,s.jsx)(n.code,{children:"Web"})," \u6216\u591a\u7ebf\u7a0b\u89e3\u6790\u670d\u52a1"]}),"\n",(0,s.jsxs)(n.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5728 ",(0,s.jsx)(n.code,{children:"Web"})," \u8bf7\u6c42\u5f00\u59cb\u4e4b\u524d\u4f1a\u81ea\u52a8\u521b\u5efa\u8303\u56f4\u4f5c\u7528\u57df\uff0c\u8fd9\u4e2a\u4f5c\u7528\u57df\u7684\u751f\u5b58\u5468\u671f\u662f\u8bf7\u6c42\u4e4b\u524d\u548c\u54cd\u5e94\u4e4b\u540e\uff0c\u4e5f\u5c31\u662f\u5728\u8fd9\u4e2a\u4f5c\u7528\u57df\u5185\u7684\u6240\u6709\u670d\u52a1\u90fd\u5b9e\u73b0\u4e86\u81ea\u52a8\u7ba1\u7406\uff0c\u6bd4\u5982\u521b\u5efa\u670d\u52a1\u548c\u91ca\u653e\u670d\u52a1\u7684\u65f6\u673a\u3002"]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.strong,{children:["\u4f46\u5728\u975e ",(0,s.jsx)(n.code,{children:"Web"})," \u6216\u591a\u7ebf\u7a0b\u4e2d\uff0c\u6846\u67b6\u5e76\u4e0d\u4f1a\u505a\u8fd9\u6837\u7684\u4e8b\u60c5\uff0c\u4e5f\u5c31\u662f\u6846\u67b6\u53ea\u8d1f\u8d23\u4e86\u670d\u52a1\u7684\u521b\u5efa\uff0c\u4f46\u662f\u6ca1\u6709\u8d1f\u8d23\u9500\u6bc1\uff0c\u539f\u56e0\u662f\u6846\u67b6\u65e0\u6cd5\u5f97\u77e5\u5177\u4f53\u7684\u9500\u6bc1\u65f6\u673a\uff0c\u8fd9\u6837\u5c31\u5bfc\u81f4\u4e86\u5185\u5b58\u6ea2\u51fa\u3002"]})}),"\n",(0,s.jsxs)(n.p,{children:["\u89e3\u51b3\u65b9\u5f0f\u662f\uff1a\u5728\u975e ",(0,s.jsx)(n.code,{children:"Web"})," \u6216\u591a\u7ebf\u7a0b\u4e2d\u4f7f\u7528 ",(0,s.jsx)(n.strong,{children:"\u975e\u5355\u4f8b"})," \u670d\u52a1\uff0c\u5e94\u8be5\u4e3b\u52a8\u521b\u5efa\u4f5c\u7528\u57df\uff0c\u7c7b\u4f3c\u8fc7\u53bb\u7684 ",(0,s.jsx)(n.code,{children:"using"}),"\uff0c\u76ee\u524d\u6846\u67b6\u63d0\u4f9b\u4e86\u51e0\u79cd\u65b9\u5f0f\u3002"]}),"\n",(0,s.jsxs)(n.h3,{id:"12131-iserviceprovider-\u65b9\u5f0f",children:["12.13.1 ",(0,s.jsx)(n.code,{children:"IServiceProvider"})," \u65b9\u5f0f"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {1-2,5,8,11-12}",children:"using var scope = serviceProvider.CreateScope();\r\nvar services = scope.ServiceProvider;\r\n\r\n// \u83b7\u53d6\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\r\nvar dbContext = Db.GetDbContext(services);\r\n\r\n// \u83b7\u53d6\u4ed3\u50a8\r\nvar respository = Db.GetRepository(services);\r\n\r\n// \u89e3\u6790\u5176\u4ed6\u670d\u52a1\r\nvar otherService = services.GetService();\r\nvar otherService2 = App.GetService(services);\n"})}),"\n",(0,s.jsxs)(n.h3,{id:"12132-iservicescopefactory-\u65b9\u5f0f",children:["12.13.2 ",(0,s.jsx)(n.code,{children:"IServiceScopeFactory"})," \u65b9\u5f0f"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"using var scope = serviceScopeFactory.CreateScope();\r\nvar services = scope.ServiceProvider;\n"})}),"\n",(0,s.jsxs)(n.h3,{id:"12133-scoped-\u9759\u6001\u7c7b",children:["12.13.3 ",(0,s.jsx)(n.code,{children:"Scoped"})," \u9759\u6001\u7c7b"]}),"\n",(0,s.jsxs)(n.p,{children:["\u4e3a\u4e86\u65b9\u6cd5\u5feb\u901f\u521b\u5efa\u670d\u52a1\u4f5c\u7528\u57df\uff0c",(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e86 ",(0,s.jsx)(n.code,{children:"Scoped"})," \u9759\u6001\u7c7b\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {1-2}",children:"Scoped.Create((factory, scope) => {\r\n var services = scope.ServiceProvider;\r\n});\n"})}),"\n",(0,s.jsxs)(n.h2,{id:"1214-\u5728-winformwpf-\u4e2d\u4f7f\u7528",children:["12.14 \u5728 ",(0,s.jsx)(n.code,{children:"WinForm/WPF"})," \u4e2d\u4f7f\u7528"]}),"\n",(0,s.jsx)(n.admonition,{title:"\u7248\u672c\u8bf4\u660e",type:"important",children:(0,s.jsxs)(n.p,{children:["\u4ee5\u4e0b\u5185\u5bb9\u4ec5\u9650 ",(0,s.jsx)(n.code,{children:"Furion 4.8.7.23 +"})," \u7248\u672c\u4f7f\u7528\u3002"]})}),"\n",(0,s.jsxs)(n.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c",(0,s.jsx)(n.code,{children:"WinForm/WPF"})," \u4e0d\u652f\u6301\u4f9d\u8d56\u6ce8\u5165\u529f\u80fd\uff0c\u4f46 ",(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u652f\u6301\uff0c",(0,s.jsxs)(n.strong,{children:["\u53ea\u9700\u8981\u5c06\u6240\u6709 ",(0,s.jsx)(n.code,{children:"new Form()"})," \u6216 ",(0,s.jsx)(n.code,{children:"new Window()"})," \u66ff\u6362\u4e3a ",(0,s.jsx)(n.code,{children:"Native.CreateInstance