{"id":3066,"date":"2019-12-24T13:53:59","date_gmt":"2019-12-24T12:53:59","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=3066"},"modified":"2019-12-24T13:54:00","modified_gmt":"2019-12-24T12:54:00","slug":"ioc-resolve-vs-constructor-injection","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/ioc-resolve-vs-constructor-injection\/","title":{"rendered":"IoC.Resolve vs Constructor Injection"},"content":{"rendered":"\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/2176833\/ioc-resolve-vs-constructor-injection\">https:\/\/stackoverflow.com\/questions\/2176833\/ioc-resolve-vs-constructor-injection<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/a\/2179260\">https:\/\/stackoverflow.com\/a\/2179260<\/a><\/p>\n\n\n\n<p>Source: <a href=\"https:\/\/martinfowler.com\/articles\/injection.html#UsingAServiceLocator\">https:\/\/martinfowler.com\/articles\/injection.html#UsingAServiceLocator<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Concluding Thoughts<\/h2>\n\n\n\n<p>The current rush of lightweight containers all have a common\nunderlying pattern to how they do service assembly &#8211; the dependency\ninjector pattern. Dependency Injection is a useful alternative\nto Service Locator. When building application classes the two are\nroughly equivalent, but I think Service Locator has a slight edge due\nto its more straightforward behavior. However if you are building\nclasses to be used in multiple applications then Dependency Injection is a\nbetter choice.<\/p>\n\n\n\n<p>If you use Dependency Injection there are a number of styles to\nchoose between. I would suggest you follow constructor injection\nunless you run into one of the specific problems with that\napproach, in which case switch to setter injection. If you are\nchoosing to build or obtain a container, look for one that supports\nboth constructor and setter injection.<\/p>\n\n\n\n<p>The choice between Service Locator and Dependency Injection is less\nimportant than the principle of separating service configuration from\nthe use of services within an application. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/stackoverflow.com\/questions\/2176833\/ioc-resolve-vs-constructor-injection https:\/\/stackoverflow.com\/a\/2179260 Source: https:\/\/martinfowler.com\/articles\/injection.html#UsingAServiceLocator Concluding Thoughts The current rush of lightweight containers all have a common underlying pattern to how they do service assembly &#8211; the dependency injector pattern. Dependency Injection is a useful alternative to Service Locator. When building application classes the two are roughly equivalent, but I think Service Locator has a slight [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3066","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=3066"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3066\/revisions"}],"predecessor-version":[{"id":3067,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3066\/revisions\/3067"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=3066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=3066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=3066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}