{"id":403,"date":"2023-08-03T06:26:31","date_gmt":"2023-08-03T06:26:31","guid":{"rendered":"http:\/\/192.168.0.142\/?p=403"},"modified":"2023-08-03T06:30:56","modified_gmt":"2023-08-03T06:30:56","slug":"dependency-injection","status":"publish","type":"post","link":"http:\/\/192.168.0.142\/dependency-injection\/","title":{"rendered":"Dependency Injection"},"content":{"rendered":"\n
public class Class1\r\n{\r\n public Class2 Class2 { get; set; }\r\n}\r\n \r\npublic class Class2\r\n{\r\n}\n<\/code><\/pre>\n\n\n\nThree types of DI<\/strong><\/h4>\n\n\n\nConstructor Injection<\/h5>\n\n\n\n\n- The dependencies are provided through a class constructor.<\/li>\n<\/ul>\n\n\n\n
Setter Injection<\/h5>\n\n\n\n\n- The client exposes a setter method that the injector uses to inject the dependency.<\/li>\n<\/ul>\n\n\n\n
Interface Injection<\/h5>\n\n\n\n\n- \u00a0The dependency provides an injector method that will inject the dependency into any client passed to it. <\/li>\n\n\n\n
- Clients must implement an interface that exposes a setter method that accepts the dependency\u00a0\u00a0\u00a0<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"
Three types of DI Constructor Injection Setter Injection Interface Injection<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[39],"_links":{"self":[{"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/posts\/403"}],"collection":[{"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/comments?post=403"}],"version-history":[{"count":4,"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/posts\/403\/revisions"}],"predecessor-version":[{"id":409,"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/posts\/403\/revisions\/409"}],"wp:attachment":[{"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/media?parent=403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/categories?post=403"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/192.168.0.142\/wp-json\/wp\/v2\/tags?post=403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}