Showing posts with label Dependency Injection. Show all posts
Showing posts with label Dependency Injection. Show all posts

Monday, August 8, 2016

When to use 'new'

Now, this isn't to say that you can never use new manually -- but you should reserve that for value-type objects that don't have external dependencies. (And in those cases, I'd argue that you're often better off with a static factory method than a public constructor anyway, but that's beside the point.)
http://stackoverflow.com/a/28749192

Sunday, July 17, 2016

Abstract Factory and "DI Explosion"

On the problem of creating objects from both stateless services and runtime values, Mark Seemann suggests the standard Abstract Factory pattern while seeming to acknowledge that it may be overkill for simple cases (i.e. say we have a lot of these objects to create, e.g. subclasses of say HystrixCommand, do we really want to create a Factory implementation for each subclass?)

Yes I know this, though in my case I hesitate because for simple cases it's overkill to duplicate constructor with interface, factory, factory's constructor, Create method, etc. While good for complex cases, it's too "DI explosion" for simple things I think. And the question remains about automatic registration DI container. – queen3 Nov 6 '09 at 11:16 @queen3: I understand what you mean, but I'm not aware of any DI Containers that can do what you ask.
http://stackoverflow.com/questions/1686760/which-di-container-will-satisfy-this/1686887#1686887

Sunday, August 2, 2015

DI Required for Declarative Transactions

[D]ependency injection is the only way that declarative transactions work. You will not get a transactional service if you use the new operator such as new BookService()
http://grails.github.io/grails-doc/2.3.11/guide/services.html