java - Dependency Injection with Guice: Something that isn't covered by any tutorial -


I just tie around with dependency injection and started integrating it into my existing application. So far, so good. I have a lot of squares that are needed, next to their dependence, strings, datacons, etc. I know that there are naming bindings, but I really do not want to create an annotation for every simple string, so I have to give constructor for every class. After that, there is one thing called Assisted Inject, factory implementation for me. Wow, but I still have to define the factory interface. Regarding the classes which are okay for those classes, but about the class of this example:

  public class FooBarClass {public FooBarClass (string name, string one other) {// some stuff}}  

In cases where I suspect how to use Guice or, more commonly, di correctly. "I've often heard: XYZ Framework is new new ." But it is underlying that I have made a every example with the D framework.

Only one instance is required

What if I want only one example of this class? Absolutely no strings have two dependencies in this class. Think about the shutdown hook which will be instanciated only once and passed to the JVM as my shutdown hook. Should I make this example with Geis? It looks pretty dumb for me, because there is nothing to inject, but I have to write both the guide to pass the parameters to write the factory interface and use the DI to create an interface for my Fubar class.

Many examples are necessary

The same thing applies to cases where I need many examples of this class. There is no dependency, but I do not have to get anything out of it to make a bunch of boilerplate code. This is wrong for me.

So, how should I use DI and / or GUICE?

Thanks a lot!

< data can help to break the dependencies .

  • UserAuthenticator , PaymentHandler , and email gateway .
  • The data is simply this: a date , a map & lt; String, InetAddress & gt; or even a customer . These are simple, in-memory domain objects.

D naturally the dependence of things is most suitable for the side. You should continue to use the new for your data model classes.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -