{"id":76495,"date":"2026-02-22T15:58:25","date_gmt":"2026-02-22T07:58:25","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/76495.html"},"modified":"2026-02-22T15:58:25","modified_gmt":"2026-02-22T07:58:25","slug":"go-%e8%af%ad%e8%a8%80%e4%be%9d%e8%b5%96%e6%b3%a8%e5%85%a5%e6%a1%86%e6%9e%b6-wire-%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/76495.html","title":{"rendered":"Go \u8bed\u8a00\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6 Wire \u8be6\u89e3"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80%E3%80%81Wire%C2%A0%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F-toc\" style=\"margin-left:40px\">\u4e00\u3001Wire\u00a0\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<p id=\"%E6%A0%B8%E5%BF%83%E7%89%B9%E7%82%B9-toc\" style=\"margin-left:80px\">\u6838\u5fc3\u7279\u70b9<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:40px\">\u4e8c\u3001\u57fa\u672c\u6982\u5ff5<\/p>\n<p id=\"1.%C2%A0Provider%EF%BC%88%E6%8F%90%E4%BE%9B%E8%80%85%EF%BC%89-toc\" style=\"margin-left:80px\">1.\u00a0Provider&#xff08;\u63d0\u4f9b\u8005&#xff09;<\/p>\n<p id=\"2.%C2%A0Injector%EF%BC%88%E6%B3%A8%E5%85%A5%E5%99%A8%EF%BC%89-toc\" style=\"margin-left:80px\">2.\u00a0Injector&#xff08;\u6ce8\u5165\u5668&#xff09;<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E5%AE%89%E8%A3%85%E4%B8%8E%E4%BD%BF%E7%94%A8-toc\" style=\"margin-left:40px\">\u4e09\u3001\u5b89\u88c5\u4e0e\u4f7f\u7528<\/p>\n<p id=\"1.%C2%A0%E5%AE%89%E8%A3%85-toc\" style=\"margin-left:80px\">1.\u00a0\u5b89\u88c5<\/p>\n<p id=\"2.%C2%A0%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84-toc\" style=\"margin-left:80px\">2.\u00a0\u9879\u76ee\u7ed3\u6784<\/p>\n<p id=\"3.%C2%A0%E5%AE%8C%E6%95%B4%E7%A4%BA%E4%BE%8B-toc\" style=\"margin-left:80px\">3.\u00a0\u5b8c\u6574\u793a\u4f8b<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E9%AB%98%E7%BA%A7%E7%89%B9%E6%80%A7-toc\" style=\"margin-left:40px\">\u56db\u3001\u9ad8\u7ea7\u7279\u6027<\/p>\n<p id=\"1.%C2%A0Provider%20Set%EF%BC%88%E6%8F%90%E4%BE%9B%E8%80%85%E9%9B%86%E5%90%88%EF%BC%89-toc\" style=\"margin-left:80px\">1.\u00a0Provider Set&#xff08;\u63d0\u4f9b\u8005\u96c6\u5408&#xff09;<\/p>\n<p id=\"2.%C2%A0%E6%8E%A5%E5%8F%A3%E7%BB%91%E5%AE%9A-toc\" style=\"margin-left:80px\">2.\u00a0\u63a5\u53e3\u7ed1\u5b9a<\/p>\n<p id=\"3.%C2%A0%E7%BB%93%E6%9E%84%E4%BD%93%E6%8F%90%E4%BE%9B%E8%80%85-toc\" style=\"margin-left:80px\">3.\u00a0\u7ed3\u6784\u4f53\u63d0\u4f9b\u8005<\/p>\n<p id=\"4.%C2%A0%E5%80%BC%E7%BB%91%E5%AE%9A-toc\" style=\"margin-left:80px\">4.\u00a0\u503c\u7ed1\u5b9a<\/p>\n<p id=\"5.%C2%A0%E6%B8%85%E7%90%86%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:80px\">5.\u00a0\u6e05\u7406\u51fd\u6570<\/p>\n<p id=\"6.%C2%A0%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86-toc\" style=\"margin-left:80px\">6.\u00a0\u9519\u8bef\u5904\u7406<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5-toc\" style=\"margin-left:40px\">\u4e94\u3001\u6700\u4f73\u5b9e\u8df5<\/p>\n<p id=\"1.%C2%A0%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84%E5%BB%BA%E8%AE%AE-toc\" style=\"margin-left:80px\">1.\u00a0\u9879\u76ee\u7ed3\u6784\u5efa\u8bae<\/p>\n<p id=\"2.%C2%A0%E4%BB%A3%E7%A0%81%E7%BB%84%E7%BB%87-toc\" style=\"margin-left:80px\">2.\u00a0\u4ee3\u7801\u7ec4\u7ec7<\/p>\n<p id=\"3.%C2%A0%E6%B5%8B%E8%AF%95%E4%B8%AD%E4%BD%BF%E7%94%A8%C2%A0Wire-toc\" style=\"margin-left:80px\">3.\u00a0\u6d4b\u8bd5\u4e2d\u4f7f\u7528\u00a0Wire<\/p>\n<p id=\"4.%C2%A0%E5%B8%B8%E8%A7%81%E9%94%99%E8%AF%AF%E6%A8%A1%E5%BC%8F-toc\" style=\"margin-left:80px\">4.\u00a0\u5e38\u89c1\u9519\u8bef\u6a21\u5f0f<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E4%B8%8E%E5%85%B6%E4%BB%96%C2%A0DI%C2%A0%E6%A1%86%E6%9E%B6%E5%AF%B9%E6%AF%94-toc\" style=\"margin-left:40px\">\u516d\u3001\u4e0e\u5176\u4ed6\u00a0DI\u00a0\u6846\u67b6\u5bf9\u6bd4<\/p>\n<p id=\"%E4%B8%83%E3%80%81%E5%AE%9E%E6%88%98%E7%A4%BA%E4%BE%8B%EF%BC%9AWeb%C2%A0%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:40px\">\u4e03\u3001\u5b9e\u6218\u793a\u4f8b&#xff1a;Web\u00a0\u670d\u52a1\u5668<\/p>\n<p id=\"%E5%85%AB%E3%80%81%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:40px\">\u516b\u3001\u603b\u7ed3<\/p>\n<p id=\"Wire%C2%A0%E4%BC%98%E5%8A%BF-toc\" style=\"margin-left:80px\">Wire\u00a0\u4f18\u52bf<\/p>\n<p id=\"%E9%80%82%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:80px\">\u9002\u7528\u573a\u666f<\/p>\n<p id=\"%E4%B8%8D%E9%80%82%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:80px\">\u4e0d\u9002\u7528\u573a\u666f<\/p>\n<p id=\"%E6%8E%A8%E8%8D%90%E4%BD%BF%E7%94%A8%E6%97%B6%E6%9C%BA-toc\" style=\"margin-left:80px\">\u63a8\u8350\u4f7f\u7528\u65f6\u673a<\/p>\n<hr id=\"hr-toc\" \/>\n<h3 id=\"%E4%B8%80%E3%80%81Wire%C2%A0%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\" style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u4e00\u3001<\/span><span style=\"color:#0f1115\">Wire\u00a0<\/span><span style=\"color:#0f1115\">\u662f\u4ec0\u4e48&#xff1f;<\/span><\/span><\/span><\/h3>\n<p style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">Wire\u00a0<\/span><span style=\"color:#0f1115\">\u662f<\/span><span style=\"color:#0f1115\">\u00a0Google\u00a0<\/span><span style=\"color:#0f1115\">\u5f00\u6e90\u7684<\/span><span style=\"color:#0f1115\">\u00a0Go\u00a0<\/span><span style=\"color:#0f1115\">\u8bed\u8a00\u7f16\u8bd1\u65f6\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6&#xff0c;\u5b83\u901a\u8fc7\u4ee3\u7801\u751f\u6210\u7684\u65b9\u5f0f\u5b9e\u73b0\u4f9d\u8d56\u6ce8\u5165&#xff0c;\u800c\u4e0d\u662f\u4f7f\u7528\u53cd\u5c04\u3002<\/span><\/span><\/span><\/p>\n<h4 id=\"%E6%A0%B8%E5%BF%83%E7%89%B9%E7%82%B9\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u6838\u5fc3\u7279\u70b9<\/span><\/span><\/span><\/h4>\n<ul>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u2705<\/span>\u00a0<span style=\"color:#0f1115\">\u7f16\u8bd1\u65f6\u4f9d\u8d56\u6ce8\u5165<\/span><span style=\"color:#0f1115\">&#xff1a;\u5728\u7f16\u8bd1\u65f6\u53d1\u73b0\u95ee\u9898&#xff0c;\u800c\u4e0d\u662f\u8fd0\u884c\u65f6<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u2705<\/span>\u00a0<span style=\"color:#0f1115\">\u4ee3\u7801\u751f\u6210<\/span><span style=\"color:#0f1115\">&#xff1a;\u751f\u6210\u660e\u786e\u7684<\/span><span style=\"color:#0f1115\">\u00a0Go\u00a0<\/span><span style=\"color:#0f1115\">\u4ee3\u7801&#xff0c;\u6613\u4e8e\u8c03\u8bd5\u548c\u7406\u89e3<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u2705<\/span>\u00a0<span style=\"color:#0f1115\">\u7c7b\u578b\u5b89\u5168<\/span><span style=\"color:#0f1115\">&#xff1a;\u5b8c\u5168\u7c7b\u578b\u5b89\u5168\u7684\u4f9d\u8d56\u5173\u7cfb<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u2705<\/span>\u00a0<span style=\"color:#0f1115\">\u65e0\u8fd0\u884c\u65f6\u5f00\u9500<\/span><span style=\"color:#0f1115\">&#xff1a;\u4e0d\u4f9d\u8d56\u53cd\u5c04&#xff0c;\u6027\u80fd\u63a5\u8fd1\u624b\u5199\u4ee3\u7801<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u2705<\/span>\u00a0<span style=\"color:#0f1115\">\u7b80\u5355\u6613\u7528<\/span><span style=\"color:#0f1115\">&#xff1a;\u63a5\u53e3\u7b80\u6d01&#xff0c;\u5b66\u4e60\u6210\u672c\u4f4e<\/span><\/span><\/li>\n<\/ul>\n<hr \/>\n<h3 id=\"%E4%BA%8C%E3%80%81%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u4e8c\u3001\u57fa\u672c\u6982\u5ff5<\/span><\/span><\/span><\/h3>\n<h4 id=\"1.%C2%A0Provider%EF%BC%88%E6%8F%90%E4%BE%9B%E8%80%85%EF%BC%89\" style=\"background-color:transparent;margin-left:0px;margin-right:0px;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">1.\u00a0Provider<\/span><span style=\"color:#0f1115\">&#xff08;\u63d0\u4f9b\u8005&#xff09;<\/span><\/span><\/span><\/h4>\n<p style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u5b9a\u4e49\u5982\u4f55\u521b\u5efa\u4f9d\u8d56\u7684\u51fd\u6570&#xff1a;<\/span><\/span><\/span><\/p>\n<p>\/\/ \u7b80\u5355 Provider<br \/>\nfunc NewDatabase(conn string) (*sql.DB, error) {<br \/>\n\u00a0\u00a0\u00a0 return sql.Open(&#034;mysql&#034;, conn)<br \/>\n}<\/p>\n<p>\/\/ \u5e26\u4f9d\u8d56\u7684 Provider<br \/>\nfunc NewUserService(db *sql.DB, logger *log.Logger) *UserService {<br \/>\n\u00a0\u00a0\u00a0 return &amp;UserService{db: db, logger: logger}<br \/>\n} <\/p>\n<h4 id=\"2.%C2%A0Injector%EF%BC%88%E6%B3%A8%E5%85%A5%E5%99%A8%EF%BC%89\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">2.\u00a0Injector<\/span><span style=\"color:#0f1115\">&#xff08;\u6ce8\u5165\u5668&#xff09;<\/span><\/span><\/span><\/h4>\n<p style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u63cf\u8ff0\u5982\u4f55\u7ec4\u88c5\u4f9d\u8d56\u7684\u51fd\u6570&#xff08;\u901a\u8fc7<\/span>\u00a0<span style=\"color:#0f1115\">\/\/go:generate<\/span>\u00a0<span style=\"color:#0f1115\">\u751f\u6210&#xff09;&#xff1a;<\/span><\/span><\/span><\/p>\n<p>\/\/ wire.go \u6587\u4ef6<br \/>\n\/\/go:build wireinject<br \/>\n\/\/ &#043;build wireinject<br \/>\nfunc InitializeUserService(conn string) (*UserService, error) {<br \/>\n\u00a0\u00a0\u00a0 wire.Build(<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NewDatabase,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NewLogger,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NewUserService,<br \/>\n\u00a0\u00a0\u00a0 )<br \/>\n\u00a0\u00a0\u00a0 return nil, nil\u00a0 \/\/ \u8fd9\u884c\u4f1a\u88ab\u751f\u6210\u7684\u4ee3\u7801\u66ff\u6362<br \/>\n} <\/p>\n<h3 id=\"%E4%B8%89%E3%80%81%E5%AE%89%E8%A3%85%E4%B8%8E%E4%BD%BF%E7%94%A8\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u4e09\u3001\u5b89\u88c5\u4e0e\u4f7f\u7528<\/span><\/span><\/span><\/h3>\n<h4 id=\"1.%C2%A0%E5%AE%89%E8%A3%85\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">1.\u00a0<\/span><span style=\"color:#0f1115\">\u5b89\u88c5<\/span><\/span><\/span><\/h4>\n<p># \u5b89\u88c5 wire \u547d\u4ee4<br \/>\ngo install github.com\/google\/wire\/cmd\/wire&#064;latest<br \/>\n# \u68c0\u67e5\u5b89\u88c5<br \/>\nwire version <\/p>\n<h4 id=\"2.%C2%A0%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">2.\u00a0<\/span><span style=\"color:#0f1115\">\u9879\u76ee\u7ed3\u6784<\/span><\/span><\/span><\/h4>\n<p>project\/<br \/>\n\u251c\u2500\u2500 cmd\/<br \/>\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 main.go\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # \u5165\u53e3\u6587\u4ef6<br \/>\n\u251c\u2500\u2500 internal\/<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 service\/<br \/>\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 user.go\u00a0\u00a0\u00a0\u00a0\u00a0 # UserService<br \/>\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 repo\/<br \/>\n\u2502\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u2514\u2500\u2500 user.go\u00a0\u00a0\u00a0\u00a0\u00a0 # UserRepository<br \/>\n\u251c\u2500\u2500 wire.go\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # \u6ce8\u5165\u5668\u5b9a\u4e49&#xff08;&#043;wireinject tag&#xff09;<br \/>\n\u251c\u2500\u2500 wire_gen.go\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # wire \u751f\u6210\u7684\u4ee3\u7801<br \/>\n\u2514\u2500\u2500 go.mod <\/p>\n<h4 id=\"3.%C2%A0%E5%AE%8C%E6%95%B4%E7%A4%BA%E4%BE%8B\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">3.\u00a0<\/span><span style=\"color:#0f1115\">\u5b8c\u6574\u793a\u4f8b<\/span><\/span><\/span><\/h4>\n<p style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"color:#000000\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u6b65\u9aa4<\/span><span style=\"color:#0f1115\">\u00a01<\/span><span style=\"color:#0f1115\">&#xff1a;\u5b9a\u4e49<\/span><span style=\"color:#0f1115\">\u00a0Provider<\/span><\/span><\/span><\/p>\n<p>\/\/ internal\/repo\/user.go<br \/>\npackage repo<br \/>\ntype UserRepository interface {<br \/>\n\u00a0\u00a0\u00a0 FindByID(id int) (*User, error)<br \/>\n}<\/p>\n<p>type userRepo struct {<br \/>\n\u00a0\u00a0\u00a0 db *sql.DB<br \/>\n}<\/p>\n<p>func NewUserRepository(db *sql.DB) UserRepository {<br \/>\n\u00a0\u00a0\u00a0 return &amp;userRepo{db: db}<br \/>\n}<\/p>\n<p>\/\/ internal\/service\/user.go<br \/>\npackage service<br \/>\ntype UserService struct {<br \/>\n\u00a0\u00a0\u00a0 repo UserRepository<br \/>\n\u00a0\u00a0\u00a0 logger *log.Logger<br \/>\n}<\/p>\n<p>func NewUserService(repo UserRepository, logger *log.Logger) *UserService {<br \/>\n\u00a0\u00a0\u00a0 return &amp;UserService{<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 repo: repo,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 logger: logger,<br \/>\n\u00a0\u00a0\u00a0 }<br \/>\n} <\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u6b65\u9aa4<\/span><span style=\"color:#0f1115\">\u00a02<\/span><span style=\"color:#0f1115\">&#xff1a;\u521b\u5efa<\/span><span style=\"color:#0f1115\">\u00a0wire.go<\/span><\/span><\/p>\n<p>\/\/ wire.go<br \/>\n\/\/go:build wireinject<br \/>\n\/\/ &#043;build wireinject<br \/>\npackage main<br \/>\nimport (<br \/>\n\u00a0\u00a0\u00a0 &#034;database\/sql&#034;<br \/>\n\u00a0\u00a0\u00a0 &#034;log&#034;\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0&#034;github.com\/google\/wire&#034;<br \/>\n\u00a0\u00a0\u00a0 &#034;yourproject\/internal\/repo&#034;<br \/>\n\u00a0\u00a0\u00a0 &#034;yourproject\/internal\/service&#034;<br \/>\n)<\/p>\n<p>func InitializeUserService(conn string) (*service.UserService, func(), error) {<br \/>\n\u00a0\u00a0\u00a0 wire.Build(<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ \u6570\u636e\u5e93\u8fde\u63a5<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideDatabase,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u4ed3\u5e93\u5c42<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 repo.NewUserRepository,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u670d\u52a1\u5c42<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 service.NewUserService,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u5de5\u5177\u4f9d\u8d56<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideLogger,<br \/>\n\u00a0\u00a0\u00a0 )<br \/>\n\u00a0\u00a0\u00a0 return nil, nil, nil<br \/>\n}<\/p>\n<p>\/\/ \u72ec\u7acb\u7684 Provider \u51fd\u6570<br \/>\nfunc provideDatabase(conn string) (*sql.DB, func(), error) {<br \/>\n\u00a0\u00a0\u00a0 db, err :&#061; sql.Open(&#034;mysql&#034;, conn)<br \/>\n\u00a0\u00a0\u00a0 if err !&#061; nil {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return nil, nil, err<br \/>\n\u00a0\u00a0\u00a0 }<br \/>\n\u00a0\u00a0\u00a0 cleanup :&#061; func() {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 db.Close()<br \/>\n\u00a0\u00a0\u00a0 }<br \/>\n\u00a0\u00a0\u00a0 return db, cleanup, nil<br \/>\n}<\/p>\n<p>func provideLogger() *log.Logger {<br \/>\n\u00a0\u00a0\u00a0 return log.New(os.Stdout, &#034;INFO: &#034;, log.Ldate|log.Ltime|log.Lshortfile)<br \/>\n} <\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u6b65\u9aa4<\/span><span style=\"color:#0f1115\">\u00a03<\/span><span style=\"color:#0f1115\">&#xff1a;\u751f\u6210\u4ee3\u7801<\/span><\/span><\/p>\n<p># \u5728\u9879\u76ee\u6839\u76ee\u5f55\u6267\u884c<br \/>\nwire<br \/>\n# \u6216\u4f7f\u7528 go generate<br \/>\n# \u5728 wire.go \u4e2d\u6dfb\u52a0 \/\/go:generate wire<br \/>\ngo generate .\/&#8230; <\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u6b65\u9aa4<\/span><span style=\"color:#0f1115\">\u00a04<\/span><span style=\"color:#0f1115\">&#xff1a;\u4f7f\u7528\u751f\u6210\u7684\u4ee3\u7801<\/span><\/span><\/p>\n<p>\/\/ main.go<br \/>\npackage main<br \/>\nfunc main() {<br \/>\n\u00a0\u00a0\u00a0 \/\/ \u4f7f\u7528 wire \u751f\u6210\u7684\u521d\u59cb\u5316\u51fd\u6570<br \/>\n\u00a0\u00a0\u00a0 userService, cleanup, err :&#061; InitializeUserService(&#034;user:pass&#064;\/dbname&#034;)<br \/>\n\u00a0\u00a0\u00a0 if err !&#061; nil {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 log.Fatal(err)<br \/>\n\u00a0\u00a0\u00a0 }<br \/>\n\u00a0\u00a0\u00a0 defer cleanup()<br \/>\n\u00a0\u00a0\u00a0\u00a0\/\/ \u4f7f\u7528 userService&#8230;<br \/>\n} <\/p>\n<h3 id=\"%E5%9B%9B%E3%80%81%E9%AB%98%E7%BA%A7%E7%89%B9%E6%80%A7\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u56db\u3001\u9ad8\u7ea7\u7279\u6027<\/span><\/span><\/h3>\n<h4 id=\"1.%C2%A0Provider%20Set%EF%BC%88%E6%8F%90%E4%BE%9B%E8%80%85%E9%9B%86%E5%90%88%EF%BC%89\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">1.\u00a0Provider Set<\/span><span style=\"color:#0f1115\">&#xff08;\u63d0\u4f9b\u8005\u96c6\u5408&#xff09;<\/span><\/span><\/h4>\n<p>\/\/ \u5b9a\u4e49 Provider Set<br \/>\nvar DatabaseSet &#061; wire.NewSet(<br \/>\n\u00a0\u00a0\u00a0 provideDatabase,<br \/>\n\u00a0\u00a0\u00a0 repo.NewUserRepository,<br \/>\n\u00a0\u00a0\u00a0 repo.NewOrderRepository,<br \/>\n)<\/p>\n<p>var ServiceSet &#061; wire.NewSet(<br \/>\n\u00a0\u00a0\u00a0 service.NewUserService,<br \/>\n\u00a0\u00a0\u00a0 service.NewOrderService,<br \/>\n)<\/p>\n<p>\/\/ \u5728 wire.Build \u4e2d\u4f7f\u7528<br \/>\nwire.Build(<br \/>\n\u00a0\u00a0\u00a0 DatabaseSet,<br \/>\n\u00a0\u00a0\u00a0 ServiceSet,<br \/>\n\u00a0\u00a0\u00a0 provideLogger,<br \/>\n) <\/p>\n<h4 id=\"2.%C2%A0%E6%8E%A5%E5%8F%A3%E7%BB%91%E5%AE%9A\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">2.\u00a0<\/span><span style=\"color:#0f1115\">\u63a5\u53e3\u7ed1\u5b9a<\/span><\/span><\/h4>\n<p>\/\/ \u5b9a\u4e49\u63a5\u53e3\u548c\u5b9e\u73b0<br \/>\ntype UserRepo interface {<br \/>\n\u00a0\u00a0\u00a0 FindByID(id int) (*User, error)<br \/>\n}<\/p>\n<p>type mysqlUserRepo struct {<br \/>\n\u00a0\u00a0\u00a0 db *sql.DB<br \/>\n}<\/p>\n<p>\/\/ \u5728 wire.go \u4e2d\u7ed1\u5b9a\u63a5\u53e3<br \/>\nvar repoSet &#061; wire.NewSet(<br \/>\n\u00a0\u00a0\u00a0 NewMySQLUserRepo,<br \/>\n\u00a0\u00a0\u00a0 wire.Bind(new(UserRepo), new(*mysqlUserRepo)),\u00a0 \/\/ \u7ed1\u5b9a\u63a5\u53e3<br \/>\n) <\/p>\n<h4 id=\"3.%C2%A0%E7%BB%93%E6%9E%84%E4%BD%93%E6%8F%90%E4%BE%9B%E8%80%85\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">3.\u00a0<\/span><span style=\"color:#0f1115\">\u7ed3\u6784\u4f53\u63d0\u4f9b\u8005<\/span><\/span><\/h4>\n<p>\/\/ \u81ea\u52a8\u586b\u5145\u7ed3\u6784\u4f53\u5b57\u6bb5<br \/>\ntype Config struct {<br \/>\n\u00a0\u00a0\u00a0 Host string<br \/>\n\u00a0\u00a0\u00a0 Port int<br \/>\n}<\/p>\n<p>type Server struct {<br \/>\n\u00a0\u00a0\u00a0 Config Config<br \/>\n\u00a0\u00a0\u00a0 Logger *log.Logger<br \/>\n}<\/p>\n<p>\/\/ wire.go<br \/>\nvar serverSet &#061; wire.NewSet(<br \/>\n\u00a0\u00a0\u00a0 wire.Struct(new(Server), &#034;*&#034;),\u00a0 \/\/ \u6ce8\u5165\u6240\u6709\u5b57\u6bb5<br \/>\n\u00a0\u00a0\u00a0 \/\/ wire.Struct(new(Server), &#034;Config&#034;),\u00a0 \/\/ \u53ea\u6ce8\u5165 Config \u5b57\u6bb5<br \/>\n\u00a0\u00a0\u00a0 provideConfig,<br \/>\n\u00a0\u00a0\u00a0 provideLogger,<br \/>\n) <\/p>\n<h4 id=\"4.%C2%A0%E5%80%BC%E7%BB%91%E5%AE%9A\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">4.\u00a0<\/span><span style=\"color:#0f1115\">\u503c\u7ed1\u5b9a<\/span><\/span><\/h4>\n<p>\/\/ \u7ed1\u5b9a\u5e38\u91cf\u548c\u914d\u7f6e\u503c<br \/>\nvar configSet &#061; wire.NewSet(<br \/>\n\u00a0\u00a0\u00a0 wire.Value(&#034;localhost:8080&#034;),\u00a0 \/\/ \u7ed1\u5b9a\u5b57\u7b26\u4e32\u503c<br \/>\n\u00a0\u00a0\u00a0 wire.InterfaceValue((*io.Writer)(nil), os.Stdout),<br \/>\n) <\/p>\n<h4 id=\"5.%C2%A0%E6%B8%85%E7%90%86%E5%87%BD%E6%95%B0\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">5.\u00a0<\/span><span style=\"color:#0f1115\">\u6e05\u7406\u51fd\u6570<\/span><\/span><\/h4>\n<p>func provideResource() (*Resource, func(), error) {<br \/>\n\u00a0\u00a0\u00a0 r, err :&#061; newResource()<br \/>\n\u00a0\u00a0 \u00a0if err !&#061; nil {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return nil, nil, err<br \/>\n\u00a0\u00a0\u00a0 }<br \/>\n\u00a0\u00a0\u00a0 cleanup :&#061; func() {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 r.Close()<br \/>\n\u00a0\u00a0\u00a0 }<br \/>\n\u00a0\u00a0\u00a0 return r, cleanup, nil<br \/>\n} <\/p>\n<h4 id=\"6.%C2%A0%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">6.\u00a0<\/span><span style=\"color:#0f1115\">\u9519\u8bef\u5904\u7406<\/span><\/span><\/h4>\n<p>\/\/ Provider \u53ef\u4ee5\u8fd4\u56de\u9519\u8bef<br \/>\nfunc provideConfig() (*Config, error) {<br \/>\n\u00a0\u00a0\u00a0 \/\/ \u8bfb\u53d6\u914d\u7f6e&#xff0c;\u53ef\u80fd\u5931\u8d25<br \/>\n}<\/p>\n<p>\/\/ wire \u4f1a\u81ea\u52a8\u4f20\u9012\u9519\u8bef<br \/>\nwire.Build(<br \/>\n\u00a0\u00a0 \u00a0provideConfig,\u00a0 \/\/ \u8fd4\u56de (*Config, error)<br \/>\n\u00a0\u00a0\u00a0 provideService, \/\/ \u4f9d\u8d56 *Config<br \/>\n) <\/p>\n<h3 id=\"%E4%BA%94%E3%80%81%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u4e94\u3001\u6700\u4f73\u5b9e\u8df5<\/span><\/span><\/h3>\n<h4 id=\"1.%C2%A0%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84%E5%BB%BA%E8%AE%AE\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">1.\u00a0<\/span><span style=\"color:#0f1115\">\u9879\u76ee\u7ed3\u6784\u5efa\u8bae<\/span><\/span><\/h4>\n<p>project\/<br \/>\n\u251c\u2500\u2500 cmd\/<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 server\/<br \/>\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 main.go<br \/>\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 wire.go\u00a0\u00a0\u00a0\u00a0\u00a0 # \u6ce8\u5165\u5668\u5b9a\u4e49<br \/>\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 wire_gen.go\u00a0 # \u751f\u6210\u7684\u4ee3\u7801<br \/>\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 cli\/<br \/>\n\u2502\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u251c\u2500\u2500 main.go<br \/>\n\u2502\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u251c\u2500\u2500 wire.go<br \/>\n\u2502\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u2514\u2500\u2500 wire_gen.go<br \/>\n\u251c\u2500\u2500 internal\/<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 config\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # \u914d\u7f6e\u76f8\u5173 Provider<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 database\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # \u6570\u636e\u5e93\u76f8\u5173 Provider<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 provider\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # \u516c\u5171 Provider \u5b9a\u4e49<br \/>\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 sets.go\u00a0\u00a0\u00a0\u00a0\u00a0 # Provider Set \u5b9a\u4e49<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 service\/<br \/>\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 repo\/<br \/>\n\u2514\u2500\u2500 pkg\/<br \/>\n\u00a0\u00a0\u00a0 \u2514\u2500\u2500 di\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # \u4f9d\u8d56\u6ce8\u5165\u76f8\u5173&#xff08;\u53ef\u9009&#xff09; <\/p>\n<h4 id=\"2.%C2%A0%E4%BB%A3%E7%A0%81%E7%BB%84%E7%BB%87\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">2.\u00a0<\/span><span style=\"color:#0f1115\">\u4ee3\u7801\u7ec4\u7ec7<\/span><\/span><\/h4>\n<p>\/\/ internal\/provider\/sets.go<br \/>\npackage provider<\/p>\n<p>import &#034;github.com\/google\/wire&#034;<\/p>\n<p>\/\/ \u6570\u636e\u5e93\u76f8\u5173 Provider Set<br \/>\nvar DatabaseSet &#061; wire.NewSet(<br \/>\n\u00a0\u00a0\u00a0 NewDatabaseConfig,<br \/>\n\u00a0\u00a0\u00a0 NewDatabase,<br \/>\n\u00a0\u00a0\u00a0 NewUserRepository,<br \/>\n\u00a0\u00a0\u00a0 NewOrderRepository,<br \/>\n)<\/p>\n<p>\/\/ \u4e1a\u52a1\u670d\u52a1 Provider Set<br \/>\nvar ServiceSet &#061; wire.NewSet(<br \/>\n\u00a0\u00a0\u00a0 NewUserService,<br \/>\n\u00a0\u00a0\u00a0 NewOrderService,<br \/>\n)<\/p>\n<p>\/\/ \u57fa\u7840\u8bbe\u65bd Provider Set<br \/>\nvar InfrastructureSet &#061; wire.NewSet(<br \/>\n\u00a0\u00a0\u00a0 NewLogger,<br \/>\n\u00a0\u00a0\u00a0 NewMetrics,<br \/>\n\u00a0\u00a0\u00a0 NewTracer,<br \/>\n) <\/p>\n<h4 id=\"3.%C2%A0%E6%B5%8B%E8%AF%95%E4%B8%AD%E4%BD%BF%E7%94%A8%C2%A0Wire\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">3.\u00a0<\/span><span style=\"color:#0f1115\">\u6d4b\u8bd5\u4e2d\u4f7f\u7528<\/span><span style=\"color:#0f1115\">\u00a0Wire<\/span><\/span><\/h4>\n<p>\/\/ \u6d4b\u8bd5\u4e13\u7528\u7684 Provider Set<br \/>\nvar TestSet &#061; wire.NewSet(<br \/>\n\u00a0\u00a0\u00a0 \/\/ \u4f7f\u7528\u5185\u5b58\u6570\u636e\u5e93\u4ee3\u66ff\u771f\u5b9e\u6570\u636e\u5e93<br \/>\n\u00a0\u00a0\u00a0 NewTestDatabase,<br \/>\n\u00a0\u00a0\u00a0 \/\/ \u4f7f\u7528\u6d4b\u8bd5 logger<br \/>\n\u00a0\u00a0\u00a0 NewTestLogger,<br \/>\n\u00a0\u00a0\u00a0 \/\/ \u4e1a\u52a1 Provider \u4e0d\u53d8<br \/>\n\u00a0\u00a0\u00a0 ServiceSet,<br \/>\n)<\/p>\n<p>\/\/ \u6d4b\u8bd5\u521d\u59cb\u5316\u51fd\u6570<br \/>\nfunc InitializeTestUserService() (*service.UserService, func(), error) {<br \/>\n\u00a0\u00a0\u00a0 wire.Build(<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TestSet,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 service.NewUserService,<br \/>\n\u00a0\u00a0\u00a0 )<br \/>\n\u00a0\u00a0\u00a0 return nil, nil, nil<br \/>\n} <\/p>\n<h4 id=\"4.%C2%A0%E5%B8%B8%E8%A7%81%E9%94%99%E8%AF%AF%E6%A8%A1%E5%BC%8F\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">4.\u00a0<\/span><span style=\"color:#0f1115\">\u5e38\u89c1\u9519\u8bef\u6a21\u5f0f<\/span><\/span><\/h4>\n<p>\/ \u274c \u9519\u8bef&#xff1a;\u5faa\u73af\u4f9d\u8d56<br \/>\n\/\/ A \u4f9d\u8d56 B&#xff0c;B \u53c8\u4f9d\u8d56 A<br \/>\n\/\/ \u89e3\u51b3\u65b9\u6848&#xff1a;\u91cd\u6784\u4ee3\u7801&#xff0c;\u5f15\u5165\u63a5\u53e3\u6216\u4e2d\u95f4\u5c42<br \/>\n\/\/ \u274c \u9519\u8bef&#xff1a;\u7f3a\u5c11 Provider<br \/>\n\/\/ wire: \u6ca1\u6709\u4e3a *sql.DB \u63d0\u4f9b Provider<br \/>\n\/\/ \u89e3\u51b3\u65b9\u6848&#xff1a;\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u90fd\u6709\u5bf9\u5e94\u7684 Provider<br \/>\n\/\/ \u274c \u9519\u8bef&#xff1a;\u591a\u4e2a\u76f8\u540c\u7c7b\u578b\u7684 Provider<br \/>\n\/\/ wire: \u4e3a *log.Logger \u63d0\u4f9b\u4e86\u591a\u4e2a Provider<br \/>\n\/\/ \u89e3\u51b3\u65b9\u6848&#xff1a;\u4f7f\u7528\u63a5\u53e3\u533a\u5206&#xff0c;\u6216\u4f7f\u7528\u547d\u540d\u53c2\u6570 <\/p>\n<h3 id=\"%E5%85%AD%E3%80%81%E4%B8%8E%E5%85%B6%E4%BB%96%C2%A0DI%C2%A0%E6%A1%86%E6%9E%B6%E5%AF%B9%E6%AF%94\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u516d\u3001\u4e0e\u5176\u4ed6<\/span><span style=\"color:#0f1115\">\u00a0DI\u00a0<\/span><span style=\"color:#0f1115\">\u6846\u67b6\u5bf9\u6bd4<\/span><\/span><\/h3>\n<table cellspacing=\"0\" style=\"width:max-content\">\n<tr>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u7279\u6027<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">Wire<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">dig (Uber)<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">fx (Uber)<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">Go-Spring<\/p>\n<\/td>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u6ce8\u5165\u65f6\u673a<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u7f16\u8bd1\u65f6<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u8fd0\u884c\u65f6<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u8fd0\u884c\u65f6<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u8fd0\u884c\u65f6<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u6027\u80fd<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u2b50\u2b50\u2b50\u2b50\u2b50<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u2b50\u2b50\u2b50<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u2b50\u2b50\u2b50<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u2b50\u2b50\u2b50<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u7c7b\u578b\u5b89\u5168<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u2b50\u2b50\u2b50\u2b50\u2b50<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u2b50\u2b50\u2b50\u2b50<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u2b50\u2b50\u2b50\u2b50<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u2b50\u2b50\u2b50\u2b50<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u5b66\u4e60\u66f2\u7ebf<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u7b80\u5355<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u4e2d\u7b49<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u4e2d\u7b49<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u8f83\u9661<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u8c03\u8bd5<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u5bb9\u6613&#xff08;\u751f\u6210\u7684\u00a0Go\u00a0\u4ee3\u7801&#xff09;<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u56f0\u96be&#xff08;\u4f9d\u8d56\u53cd\u5c04&#xff09;<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u56f0\u96be<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u4e2d\u7b49<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u4ee3\u7801\u751f\u6210<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u2705\u00a0\u751f\u6210\u00a0Go\u00a0\u4ee3\u7801<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u274c<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u274c<\/p>\n<\/td>\n<td>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u274c<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5728Java\u751f\u6001\u4e2d&#xff0c;Google\u5f00\u6e90\u7684\u00a0Google Guice\u00a0\u6846\u67b6\u4e0eGo\u8bed\u8a00\u7684Wire\u5728\u8bbe\u8ba1\u7406\u5ff5\u4e0a\u6700\u4e3a\u63a5\u8fd1&#xff0c;\u56e0\u4e3a\u5b83\u4eec\u90fd\u5f3a\u8c03\u6ce8\u89e3\/\u6807\u8bb0\u9a71\u52a8\u548c\u8f7b\u91cf\u7ea7\u3002\u800c\u6700\u4e3b\u6d41\u7684\u00a0Spring Framework\u00a0\u5219\u662f\u529f\u80fd\u6700\u5168\u9762\u7684\u4f9d\u8d56\u6ce8\u5165\u5b9e\u73b0\u3002<\/p>\n<p>\u4e3a\u4e86\u5e2e\u52a9\u4f60\u66f4\u6e05\u6670\u5730\u7406\u89e3&#xff0c;\u6211\u5c06\u8fd9\u4e09\u4e2a\u6846\u67b6\u653e\u5728\u4e00\u8d77\u505a\u4e86\u4e00\u4e2a\u5bf9\u6bd4&#xff1a;<\/p>\n<table>\n<tr>\u5bf9\u6bd4\u7ef4\u5ea6Google Wire (Go)Google Guice (Java)Spring Framework (Java)<\/tr>\n<tbody>\n<tr>\n<td>\u6838\u5fc3\u673a\u5236<\/td>\n<td>\u7f16\u8bd1\u65f6\u4ee3\u7801\u751f\u6210&#xff1a;\u901a\u8fc7\u751f\u6210\u4ee3\u7801\u6765\u8fde\u63a5\u7ec4\u4ef6&#xff0c;\u65e0\u8fd0\u884c\u65f6\u53cd\u5c04-4\u3002<\/td>\n<td>\u8fd0\u884c\u65f6\u4f9d\u8d56\u6ce8\u5165&#xff1a;\u901a\u8fc7\u5728\u8fd0\u884c\u65f6\u8bfb\u53d6\u6ce8\u89e3\u548c\u7ed1\u5b9a\u6765\u89e3\u6790\u4f9d\u8d56-7\u3002<\/td>\n<td>\u8fd0\u884c\u65f6\u4f9d\u8d56\u6ce8\u5165&#xff1a;\u901a\u8fc7\u5728\u8fd0\u884c\u65f6\u8bfb\u53d6\u6ce8\u89e3\u3001XML\u6216Java\u914d\u7f6e\u6765\u521b\u5efa\u548c\u7ba1\u7406Bean-1-4\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u914d\u7f6e\u65b9\u5f0f<\/td>\n<td>Go\u4ee3\u7801&#xff1a;\u5728\u00a0wire.go\u00a0\u4e2d\u4f7f\u7528\u00a0wire.Build\u00a0\u58f0\u660e\u4f9d\u8d56\u5173\u7cfb-4\u3002<\/td>\n<td>Java\u6ce8\u89e3\u4e0e\u6a21\u5757\u4ee3\u7801&#xff1a;\u4f7f\u7528\u00a0&#064;Inject\u00a0\u6ce8\u89e3&#xff0c;\u5e76\u5728Module\u4e2d\u901a\u8fc7\u4ee3\u7801\u7ed1\u5b9a\u63a5\u53e3\u4e0e\u5b9e\u73b0-1-7\u3002<\/td>\n<td>XML\/\u6ce8\u89e3\/Java\u914d\u7f6e\u7c7b&#xff1a;\u63d0\u4f9b\u591a\u79cd\u914d\u7f6e\u65b9\u5f0f&#xff0c;\u6700\u5e38\u7528\u7684\u662f\u00a0&#064;Autowired\u00a0\u6ce8\u89e3\u548c\u00a0&#064;Configuration\u00a0\u7c7b-1-4\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u5bf9\u8c61\u8bc6\u522b<\/td>\n<td>\u7c7b\u578b&#xff1a;\u6839\u636e\u7c7b\u578b\u8fdb\u884c\u7ec4\u88c5\u3002<\/td>\n<td>\u7c7b\u578b &#043; \u6ce8\u89e3&#xff1a;\u6838\u5fc3\u662f\u57fa\u4e8e\u7c7b\u578b\u7684\u00a0Map&lt;Class&lt;?&gt;, Object&gt;&#xff0c;\u5e76\u652f\u6301\u901a\u8fc7&#064;Named\u7b49\u6ce8\u89e3\u6765\u533a\u5206\u540c\u4e00\u4e2a\u63a5\u53e3\u7684\u4e0d\u540c\u5b9e\u73b0-1\u3002<\/td>\n<td>\u540d\u79f0 &#043; \u7c7b\u578b&#xff1a;\u6838\u5fc3\u662f\u57fa\u4e8e\u540d\u79f0\u7684\u00a0Map&lt;String, Object&gt;&#xff0c;\u4f46\u4e5f\u652f\u6301\u6309\u7c7b\u578b\u6ce8\u5165-1\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6027\u80fd\u7279\u70b9<\/td>\n<td>\u65e0\u8fd0\u884c\u65f6\u5f00\u9500&#xff1a;\u6240\u6709\u4f9d\u8d56\u7ec4\u88c5\u5728\u7f16\u8bd1\u671f\u5b8c\u6210&#xff0c;\u5bf9\u5e94\u7528\u8fd0\u884c\u65f6\u6027\u80fd\u65e0\u5f71\u54cd-4\u3002<\/td>\n<td>\u8f7b\u91cf\u9ad8\u6548&#xff1a;\u4e0d\u4f9d\u8d56XML\u89e3\u6790&#xff0c;\u8fd0\u884c\u6548\u7387\u6bd4\u65e9\u671f\u7684Spring\u9ad8&#xff0c;\u4f46\u4ecd\u6709\u8fd0\u884c\u65f6\u6ce8\u89e3\u5904\u7406-7\u3002<\/td>\n<td>\u529f\u80fd\u5168\u9762&#xff1a;\u529f\u80fd\u6781\u5176\u4e30\u5bcc&#xff0c;\u4f46\u8fd0\u884c\u65f6\u5f00\u9500&#xff08;\u5982\u53cd\u5c04\u3001\u4ee3\u7406\u3001\u4e0a\u4e0b\u6587\u7ba1\u7406&#xff09;\u4e5f\u76f8\u5bf9\u66f4\u5927\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7b80\u5355\u6765\u8bf4&#xff0c;\u5982\u679c\u4f60\u662fJava\u5f00\u53d1\u8005\u4e14\u8ffd\u6c42\u4e0eWire\u7c7b\u4f3c\u7684\u6781\u7b80\u3001\u9ad8\u6548\u3001\u65e0\u4fb5\u5165\u7684\u4f53\u9a8c&#xff0c;Guice\u00a0\u662f\u4f60\u7684\u4e0d\u4e8c\u4e4b\u9009\u3002\u800c\u5982\u679c\u4f60\u9700\u8981\u7684\u662f\u4e00\u4e2a\u4e00\u7ad9\u5f0f\u3001\u751f\u6001\u5b8c\u5584\u7684\u4f01\u4e1a\u7ea7\u5f00\u53d1\u89e3\u51b3\u65b9\u6848&#xff0c;\u90a3\u4e48\u00a0Spring Framework\u00a0\u4f1a\u662f\u66f4\u5e38\u89c1\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<hr \/>\n<h3 id=\"%E4%B8%83%E3%80%81%E5%AE%9E%E6%88%98%E7%A4%BA%E4%BE%8B%EF%BC%9AWeb%C2%A0%E6%9C%8D%E5%8A%A1%E5%99%A8\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u4e03\u3001\u5b9e\u6218\u793a\u4f8b&#xff1a;<\/span><span style=\"color:#0f1115\">Web\u00a0<\/span><span style=\"color:#0f1115\">\u670d\u52a1\u5668<\/span><\/span><\/h3>\n<p>\/\/ wire.go<br \/>\n\/\/go:build wireinject<br \/>\n\/\/ &#043;build wireinject<br \/>\npackage main<br \/>\nimport (<br \/>\n\u00a0\u00a0\u00a0 &#034;net\/http&#034;\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0&#034;github.com\/google\/wire&#034;<br \/>\n\u00a0\u00a0\u00a0 &#034;yourproject\/internal\/handler&#034;<br \/>\n\u00a0 \u00a0\u00a0&#034;yourproject\/internal\/middleware&#034;<br \/>\n\u00a0\u00a0\u00a0 &#034;yourproject\/internal\/service&#034;<br \/>\n)<\/p>\n<p>func InitializeServer(config *Config) (*http.Server, func(), error) {<br \/>\n\u00a0\u00a0\u00a0 wire.Build(<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ \u914d\u7f6e<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideConfig,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u6570\u636e\u5e93<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideDatabase,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u4ed3\u5e93\u5c42<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideRepositories,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u670d\u52a1\u5c42<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideServices,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u5904\u7406\u5668\u5c42<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideHandlers,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u4e2d\u95f4\u4ef6<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideMiddleware,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u8def\u7531<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideRouter,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ HTTP \u670d\u52a1\u5668<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 provideHTTPServer,<br \/>\n\u00a0\u00a0\u00a0 )<br \/>\n\u00a0\u00a0\u00a0 return nil, nil, nil<br \/>\n} <\/p>\n<h3 id=\"%E5%85%AB%E3%80%81%E6%80%BB%E7%BB%93\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u516b\u3001\u603b\u7ed3<\/span><\/span><\/h3>\n<h4 id=\"Wire%C2%A0%E4%BC%98%E5%8A%BF\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">Wire\u00a0<\/span><span style=\"color:#0f1115\">\u4f18\u52bf<\/span><\/span><\/h4>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u7f16\u8bd1\u65f6\u5b89\u5168<\/span><span style=\"color:#0f1115\">&#xff1a;\u4f9d\u8d56\u95ee\u9898\u5728\u7f16\u8bd1\u65f6\u66b4\u9732<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u6027\u80fd\u4f18\u5f02<\/span><span style=\"color:#0f1115\">&#xff1a;\u65e0\u53cd\u5c04\u5f00\u9500&#xff0c;\u4ee3\u7801\u5373\u6587\u6863<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u6613\u4e8e\u8c03\u8bd5<\/span><span style=\"color:#0f1115\">&#xff1a;\u751f\u6210\u7684\u662f\u666e\u901a<\/span><span style=\"color:#0f1115\">\u00a0Go\u00a0<\/span><span style=\"color:#0f1115\">\u4ee3\u7801<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u7b80\u6d01\u6e05\u6670<\/span><span style=\"color:#0f1115\">&#xff1a;\u663e\u5f0f\u58f0\u660e\u4f9d\u8d56\u5173\u7cfb<\/span><\/span><\/li>\n<h4 id=\"%E9%80%82%E7%94%A8%E5%9C%BA%E6%99%AF\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u9002\u7528\u573a\u666f<\/span><\/span><\/h4>\n<ul>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u2705<\/span>\u00a0<span style=\"color:#0f1115\">\u4e2d\u5c0f\u5230\u5927\u578b\u9879\u76ee<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u2705<\/span>\u00a0<span style=\"color:#0f1115\">\u9700\u8981\u9ad8\u6027\u80fd\u7684\u5e94\u7528<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u2705<\/span>\u00a0<span style=\"color:#0f1115\">\u5e0c\u671b\u4f9d\u8d56\u5173\u7cfb\u660e\u786e\u53ef\u89c1<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u2705<\/span>\u00a0<span style=\"color:#0f1115\">\u56e2\u961f\u91cd\u89c6\u7f16\u8bd1\u65f6\u68c0\u67e5<\/span><\/span><\/li>\n<\/ul>\n<h4 id=\"%E4%B8%8D%E9%80%82%E7%94%A8%E5%9C%BA%E6%99%AF\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u4e0d\u9002\u7528\u573a\u666f<\/span><\/span><\/h4>\n<ul>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u274c<\/span>\u00a0<span style=\"color:#0f1115\">\u9700\u8981\u52a8\u6001\u52a0\u8f7d\u6a21\u5757\u7684\u63d2\u4ef6\u7cfb\u7edf<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u274c<\/span>\u00a0<span style=\"color:#0f1115\">\u5927\u91cf\u4f7f\u7528\u52a8\u6001\u914d\u7f6e\u7684\u5e94\u7528<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u274c<\/span>\u00a0<span style=\"color:#0f1115\">\u5e0c\u671b\u5b8c\u5168\u96f6\u914d\u7f6e\u7684\u7b80\u5355\u9879\u76ee<\/span><\/span><\/li>\n<\/ul>\n<h4 id=\"%E6%8E%A8%E8%8D%90%E4%BD%BF%E7%94%A8%E6%97%B6%E6%9C%BA\" style=\"margin-left:0;margin-right:0;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u63a8\u8350\u4f7f\u7528\u65f6\u673a<\/span><\/span><\/h4>\n<ul>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u9879\u76ee\u6a21\u5757\u8d85\u8fc7<\/span><span style=\"color:#0f1115\">\u00a010\u00a0<\/span><span style=\"color:#0f1115\">\u4e2a<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u4f9d\u8d56\u5173\u7cfb\u5f00\u59cb\u53d8\u5f97\u590d\u6742<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u56e2\u961f\u89c4\u6a21\u6269\u5927&#xff0c;\u9700\u8981\u66f4\u597d\u7684\u67b6\u6784\u7ea6\u675f<\/span><\/span><\/li>\n<li><span style=\"background-color:white\"><span style=\"color:#0f1115\">\u9700\u8981\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5\u9694\u79bb<\/span><\/span><\/li>\n<\/ul>\n<hr \/>\n<p style=\"margin-left:0cm;margin-right:0cm;text-align:start\"><span style=\"background-color:white\"><span style=\"color:#0f1115\">Wire\u00a0<\/span><span style=\"color:#0f1115\">\u662f<\/span><span style=\"color:#0f1115\">\u00a0Go\u00a0<\/span><span style=\"color:#0f1115\">\u751f\u6001\u4e2d\u6700\u4f18\u96c5\u3001\u9ad8\u6548\u7684\u4f9d\u8d56\u6ce8\u5165\u89e3\u51b3\u65b9\u6848\u4e4b\u4e00&#xff0c;\u7279\u522b\u9002\u5408\u8ffd\u6c42\u4ee3\u7801\u8d28\u91cf\u548c\u6027\u80fd\u7684\u56e2\u961f\u3002\u901a\u8fc7\u7f16\u8bd1\u65f6\u4f9d\u8d56\u6ce8\u5165&#xff0c;\u5b83\u5728\u4fdd\u6301<\/span><span style=\"color:#0f1115\">\u00a0Go\u00a0<\/span><span style=\"color:#0f1115\">\u8bed\u8a00\u7b80\u6d01\u6027\u7684\u540c\u65f6&#xff0c;\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u4f9d\u8d56\u7ba1\u7406\u80fd\u529b\u3002<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n\u4e00\u3001Wire\u00a0\u662f\u4ec0\u4e48&#xff1f;<br \/>\n\u6838\u5fc3\u7279\u70b9<br \/>\n\u4e8c\u3001\u57fa\u672c\u6982\u5ff5<br \/>\n1.\u00a0Provider&#xff08;\u63d0\u4f9b\u8005&#xff09;<br \/>\n2.\u00a0Injector&#xff08;\u6ce8\u5165\u5668&#xff09;<br \/>\n\u4e09\u3001\u5b89\u88c5\u4e0e\u4f7f\u7528<br \/>\n1.\u00a0\u5b89\u88c5<br \/>\n2.\u00a0\u9879\u76ee\u7ed3\u6784<br \/>\n3.\u00a0\u5b8c\u6574\u793a\u4f8b<br \/>\n\u56db\u3001\u9ad8\u7ea7\u7279\u6027<br \/>\n1.\u00a0Provider Set&#xff08;\u63d0\u4f9b\u8005\u96c6\u5408&#xff09;<br \/>\n2.\u00a0\u63a5\u53e3\u7ed1\u5b9a<br \/>\n3.\u00a0\u7ed3\u6784\u4f53\u63d0\u4f9b\u8005<br \/>\n4.\u00a0\u503c\u7ed1\u5b9a<br \/>\n5.\u00a0\u6e05\u7406\u51fd\u6570<br \/>\n6.\u00a0\u9519\u8bef\u5904\u7406<br \/>\n\u4e94\u3001\u6700\u4f73\u5b9e\u8df5<br \/>\n1.\u00a0\u9879<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[746,190],"topic":[],"class_list":["post-76495","post","type-post","status-publish","format-standard","hentry","category-server","tag-golang","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Go \u8bed\u8a00\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6 Wire \u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/76495.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go \u8bed\u8a00\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6 Wire \u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u4e00\u3001Wire\u00a0\u662f\u4ec0\u4e48&#xff1f; \u6838\u5fc3\u7279\u70b9 \u4e8c\u3001\u57fa\u672c\u6982\u5ff5 1.\u00a0Provider&#xff08;\u63d0\u4f9b\u8005&#xff09; 2.\u00a0Injector&#xff08;\u6ce8\u5165\u5668&#xff09; \u4e09\u3001\u5b89\u88c5\u4e0e\u4f7f\u7528 1.\u00a0\u5b89\u88c5 2.\u00a0\u9879\u76ee\u7ed3\u6784 3.\u00a0\u5b8c\u6574\u793a\u4f8b \u56db\u3001\u9ad8\u7ea7\u7279\u6027 1.\u00a0Provider Set&#xff08;\u63d0\u4f9b\u8005\u96c6\u5408&#xff09; 2.\u00a0\u63a5\u53e3\u7ed1\u5b9a 3.\u00a0\u7ed3\u6784\u4f53\u63d0\u4f9b\u8005 4.\u00a0\u503c\u7ed1\u5b9a 5.\u00a0\u6e05\u7406\u51fd\u6570 6.\u00a0\u9519\u8bef\u5904\u7406 \u4e94\u3001\u6700\u4f73\u5b9e\u8df5 1.\u00a0\u9879\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/76495.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-22T07:58:25+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76495.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/76495.html\",\"name\":\"Go \u8bed\u8a00\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6 Wire \u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-22T07:58:25+00:00\",\"dateModified\":\"2026-02-22T07:58:25+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/76495.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/76495.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76495.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go \u8bed\u8a00\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6 Wire \u8be6\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go \u8bed\u8a00\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6 Wire \u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/76495.html","og_locale":"zh_CN","og_type":"article","og_title":"Go \u8bed\u8a00\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6 Wire \u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u4e00\u3001Wire\u00a0\u662f\u4ec0\u4e48&#xff1f; \u6838\u5fc3\u7279\u70b9 \u4e8c\u3001\u57fa\u672c\u6982\u5ff5 1.\u00a0Provider&#xff08;\u63d0\u4f9b\u8005&#xff09; 2.\u00a0Injector&#xff08;\u6ce8\u5165\u5668&#xff09; \u4e09\u3001\u5b89\u88c5\u4e0e\u4f7f\u7528 1.\u00a0\u5b89\u88c5 2.\u00a0\u9879\u76ee\u7ed3\u6784 3.\u00a0\u5b8c\u6574\u793a\u4f8b \u56db\u3001\u9ad8\u7ea7\u7279\u6027 1.\u00a0Provider Set&#xff08;\u63d0\u4f9b\u8005\u96c6\u5408&#xff09; 2.\u00a0\u63a5\u53e3\u7ed1\u5b9a 3.\u00a0\u7ed3\u6784\u4f53\u63d0\u4f9b\u8005 4.\u00a0\u503c\u7ed1\u5b9a 5.\u00a0\u6e05\u7406\u51fd\u6570 6.\u00a0\u9519\u8bef\u5904\u7406 \u4e94\u3001\u6700\u4f73\u5b9e\u8df5 1.\u00a0\u9879","og_url":"https:\/\/www.wsisp.com\/helps\/76495.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-22T07:58:25+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/76495.html","url":"https:\/\/www.wsisp.com\/helps\/76495.html","name":"Go \u8bed\u8a00\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6 Wire \u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-22T07:58:25+00:00","dateModified":"2026-02-22T07:58:25+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/76495.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/76495.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/76495.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Go \u8bed\u8a00\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6 Wire \u8be6\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=76495"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76495\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=76495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=76495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=76495"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=76495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}