{"id":357,"date":"2014-08-31T09:54:54","date_gmt":"2014-08-31T01:54:54","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=357"},"modified":"2014-09-04T14:02:27","modified_gmt":"2014-09-04T06:02:27","slug":"mybean-%e8%af%b4%e6%98%8e%e4%b9%a6%e5%85%b3%e4%ba%8e%e6%8f%92%e4%bb%b6%e7%9a%84%e5%8d%95%e4%bb%b6%e6%a8%a1%e5%bc%8fsingleton","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=357","title":{"rendered":"[MyBean-\u8bf4\u660e\u4e66]\u5173\u4e8e\u63d2\u4ef6\u7684\u5355\u4ef6\u6a21\u5f0f(singleton),\u63d2\u4ef6\u7684\u5171\u4eab\u6a21\u5f0f"},"content":{"rendered":"<p><font color=\"#0000ff\">\u3010\u8bf4\u660e\u3011<\/font><\/p>\n<p>\u5355\u4ef6\u6a21\u5f0f\u662f\u4e00\u79cd\u7528\u4e8e\u786e\u4fdd\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4e2d\u53ea\u6709\u4e00\u4e2a\u7c7b\u5b9e\u4f8b\u3002<\/p>\n<p>\u60f3\u60f3\u6211\u4eec\u7684\u7cfb\u7edf\u4e2d\u6709\u54ea\u4e9b\u65b9\u9762\u53ef\u4ee5\u5e94\u7528\u5230\u5355\u4ef6\u6a21\u5f0f\uff0c\u6bd4\u5982\u5927\u5bb6\u5e38\u8bf4\u7684\u8fde\u63a5(ADOConnection)\u5171\u4eab\uff0c\u5176\u5b9e\u5c31\u662f\u6307\u7684\u5355\u4ef6\u6a21\u5f0f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><font color=\"#0000ff\">\u3010MyBean\u4e2d\u7684\u5355\u4ef6\u6a21\u5f0f\u3011<\/font><\/p>\n<p>MyBean\u4e2d\u63d2\u4ef6\u4e00\u65e6\u6210\u4e3a\u5355\u4ef6\u6a21\u5f0f\uff0c\u6846\u67b6\u5c31\u4f1a\u5e2e\u4f60\u63a5\u7ba1\u5bf9\u8c61\u7684\u751f\u547d\u5468\u671f\u3002\u4f60\u6bcf\u6b21\u8c03\u7528getBean\u90fd\u53ea\u4f1a\u4ea7\u751f\u4e00\u4efd\u5b9e\u4f8b\uff0c\u4e5f\u5c31\u662f\u8bf4\u5bf9\u8c61\u53ea\u4f1a\u521b\u5efa\u4e00\u6b21\uff0c\u4e0d\u7ba1\u662f\u7a97\u4f53\u63d2\u4ef6\u8fd8\u662f\u65e0UI\u7684\u903b\u8f91\u63d2\u4ef6\u3002<\/p>\n<p>MyBean\u4e2d\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u65b9\u5f0f\u4f7f\u63d2\u4ef6\u6210\u4e3a\u5355\u4ef6\u6a21\u5f0f\u3002<\/p>\n<p>1.\u6700\u7b80\u5355\u7684\u4e00\u79cd\u662f\u6ce8\u518c\u7684\u65f6\u5019\uff0c\u53c2\u6570\u9009\u5b9a\u4e3a\u5355\u4ef6\u6a21\u5f0f\uff0c\u4e5f\u662f\u6700\u7b80\u5355\u660e\u4e86\u7684\u4e00\u79cd\u65b9\u5f0f\u3002<\/p>\n<p>&nbsp;<\/p>\n<div style=\"border-bottom: #cccccc 1px solid;border-left: #cccccc 1px solid;padding-bottom: 5px;background-color: #f5f5f5;padding-left: 5px;padding-right: 5px;border-top: #cccccc 1px solid;border-right: #cccccc 1px solid;padding-top: 5px\" class=\"cnblogs_code\">\n<pre><span style=\"color: #0000ff\">library<\/span><span style=\"color: #000000\"> diocp_bean;\n\n<\/span><span style=\"color: #0000ff\">uses<\/span><span style=\"color: #000000\">\n  SysUtils,\n  Classes,\n  mybean.core.beanFactory,\n  uRemoteServerDIOCPImpl <\/span><span style=\"color: #0000ff\">in<\/span> <span style=\"color: #800000\">'<\/span><span style=\"color: #800000\">..\\..\\Service\\uRemoteServerDIOCPImpl.pas<\/span><span style=\"color: #800000\">'<\/span><span style=\"color: #000000\">;\n\n<\/span><span style=\"color: #008000\">{<\/span><span style=\"color: #008000\">$R *.res<\/span><span style=\"color: #008000\">}<\/span>\n\n<span style=\"color: #0000ff\">begin<\/span><span style=\"color: #000000\">\n  beanFactory.RegisterBean(<\/span><span style=\"color: #800000\">'<\/span><span style=\"color: #800000\">diocpRemoteSvr<\/span><span style=\"color: #800000\">'<\/span>, TRemoteServerDIOCPImpl).Singleton :=<span style=\"color: #000000\"> true;\n<\/span><span style=\"color: #0000ff\">end<\/span>.<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>2.\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u914d\u7f6e\u63d2\u4ef6\u4e3a\u5355\u636e\u6a21\u5f0f\uff1a<\/p>\n<p>\u5047\u5982\u4e0a\u9762\u7684\u63d2\u4ef6\u6ce8\u518c\u7684\u662f\u666e\u901a\u7684\u6a21\u5f0f\uff0c\u800c\u4e14\u8fd9\u4e2a\u63d2\u4ef6\u4f60\u6ca1\u6709\u6e90\u7801\uff0c\u4f60\u60f3\u76f4\u63a5\u4f7f\u7528\uff0c\u53c8\u60f3\u662f\u5355\u4ef6\u6a21\u5f0f\u600e\u4e48\u529e\uff1f\u4f60\u53ef\u4ee5\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u8fbe\u5230<\/p>\n<div style=\"border-bottom: #cccccc 1px solid;border-left: #cccccc 1px solid;padding-bottom: 5px;background-color: #f5f5f5;padding-left: 5px;padding-right: 5px;border-top: #cccccc 1px solid;border-right: #cccccc 1px solid;padding-top: 5px\" class=\"cnblogs_code\">\n<pre>\/\/  \u5982\u679c\u6ce8\u518c\u662f\u8fd9\u6837\u7684, beanFactory.RegisterBean('diocpRemoteSvr', TRemoteServerDIOCPImpl)<\/pre>\n<pre><span style=\"color: #000000\">{\n   list:\n   [\n      {\n         <\/span>\"id\":\"dbSERVER\",              <span style=\"color: #008000\">\/\/<\/span><span style=\"color: #008000\">getBean\u7684\u65f6\u5019\u7684\u53c2\u6570<\/span>\n         \"pluginID\":\"diocpRemoteSvr\",  <span style=\"color: #008000\">\/\/<\/span><span style=\"color: #008000\">\u5982\u679c\u4e0eid\u4e00\u81f4\u53ef\u4ee5\u8fdb\u884c\u5ffd\u7565<\/span>\n         \"lib\":\"diocp_bean.dll\",       <span style=\"color: #008000\">\/\/<\/span><span style=\"color: #008000\">\u5bbf\u4e3b\u6587\u4ef6\u540d<\/span>\n         \"singleton\":<span style=\"color: #0000ff\">true<\/span>,             <span style=\"color: #008000\">\/\/<\/span><span style=\"color: #008000\">\u5355\u4ef6\u6a21\u5f0f<\/span>\n         \"config\"<span style=\"color: #000000\">:\n          {\n              <\/span>\"host\":\"127.0.0.1\"<span style=\"color: #000000\">,\n              <\/span>\"port\":9983<span style=\"color: #000000\">\n          }\n      },\n      {\n         <\/span>\"id\":\"imSERVER\",              <span style=\"color: #008000\">\/\/<\/span><span style=\"color: #008000\">getBean\u7684\u65f6\u5019\u7684\u53c2\u6570<\/span>\n         \"pluginID\":\"diocpRemoteSvr\",  <span style=\"color: #008000\">\/\/<\/span><span style=\"color: #008000\">\u5982\u679c\u4e0eid\u4e00\u81f4\u53ef\u4ee5\u8fdb\u884c\u5ffd\u7565<\/span>\n         \"lib\":\"diocp_bean.dll\",       <span style=\"color: #008000\">\/\/<\/span><span style=\"color: #008000\">\u5bbf\u4e3b\u6587\u4ef6\u540d<\/span>\n         \"singleton\":<span style=\"color: #0000ff\">true<\/span>,             <span style=\"color: #008000\">\/\/<\/span><span style=\"color: #008000\">\u5355\u4ef6\u6a21\u5f0f<\/span>\n         \"config\"<span style=\"color: #000000\">:\n          {\n              <\/span>\"host\":\"127.0.0.1\"<span style=\"color: #000000\">,\n              <\/span>\"port\":9985<span style=\"color: #000000\">\n          }\n      },\n   ]\n}<\/span><\/pre>\n<\/div>\n<p>\u53ef\u4ee5\u770b\u51fa\u4e0a\u9762\u8c03\u7528\u7684\u65f6\u5019\u53ef\u4ee5\u5b8c\u62102\u4e2a\u63d2\u4ef6\uff0c\u4ed6\u4eec\u4f7f\u7528\u7684\u5b9e\u73b0\u90fd\u662f\u4e00\u6837\u7684\uff0c\u60f3\u60f3\u5982\u679c\u6211\u4eec\u6709\u4e24\u4e2a\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u4e00\u4e2a\u8fde\u63a5\u4e1a\u52a1\u6570\u636e\u5e93\uff0c\u4e00\u4e2a\u8fde\u63a5\u914d\u7f6e\u6570\u636e\u5e93\uff0c\u5176\u5b9e\u4ed6\u4eec\u7684\u5b9e\u73b0\u662f\u4e00\u6837\u7684\uff0c\u53ea\u662f\u8fde\u63a5\u7684\u5730\u5740\u548c\u7aef\u53e3\u4e0d\u4e00\u6837\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u3010\u5355\u4ef6\u6a21\u5f0f\u7684\u5e94\u7528\u3011<\/p>\n<p>\u5355\u4ef6\u6a21\u5f0f\u5728MyBean\u53ef\u4ee5\u5f15\u7528\u6bd4\u8f83\u5e7f\u6cdb\uff0c\u7cfb\u7edf\u4e2d\u53ea\u9700\u8981\u4e00\u4e2a\u4e3b\u7a97\u4f53\uff0c\u6709\u7684\u9009\u53d6\u7a97\u4f53\u4e5f\u53ea\u9700\u8981\u4e00\u4e2a\u7b49\u7b49\u3002\u3002\u3002\u5927\u5bb6\u53ef\u4ee5\u60f3\u60f3\u4f60\u9879\u76ee\u4e2d\u7684\u5355\u4ef6\u6a21\u5f0f\uff0c\u4e4b\u524d\u662f\u600e\u4e48\u6837\u5904\u7406\u7684<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010\u8bf4\u660e\u3011 \u5355\u4ef6\u6a21\u5f0f\u662f\u4e00\u79cd\u7528\u4e8e\u786e\u4fdd\u6574\u4e2a\u5e94\u7528 [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[53],"tags":[],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-mybean"],"views":4021,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357"}],"version-history":[{"count":2,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":359,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions\/359"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}