Skip to main content
improved formatting and language
Source Link
gnat
  • 20.5k
  • 29
  • 117
  • 310

Ok, those are many questions you have and I guess some of the points can be approached in more than one way.

Creating the injector is not cheap. Guice will do some analysis to detect errors as well as create all singletons. So you should create the injector at startup.

I usually have a single injector for my application.

ReagardingRegarding your question 1.:

Yes the injector can be injected. But I see it as a bad practice. Reason for this is that calls to injector.getInstance() and injector.injectMembers() make it hard to reason about the dependencies of a class.

  • if you need to create more than one instance or you need to control the time when an instance is created inject a Provider instead of X.
  • if the object you want to create needs both runtime parameters and dependencies use assisted inject.
  • for many kinds of objects (like DTO, POJO and alike) its absolutely ok to create them by calling new or a conventional factory.

In this sense the injector is implicitly available to any instance created by Guice this includes the API user.

And finally AOP. Aspects are a powerful feature but also can hide some of the business logic I suggest to use them only for very repetitive tasks which all developers know well.

Also take into account that aspects only work on:

  • instances created by Guice
  • non private, non static, non private methods

Finally, Guice won't inform you if you add an annotation to either of the above. Your aspect will silently be ignored

Ok, those are many questions you have and I guess some of the points can be approached in more than one way.

Creating the injector is not cheap. Guice will do some analysis to detect errors as well as create all singletons. So you should create the injector at startup.

I usually have a single injector for my application.

Reagarding your question 1.:

Yes the injector can be injected. But I see it as a bad practice. Reason for this is that calls to injector.getInstance() and injector.injectMembers() make it hard to reason about the dependencies of a class.

  • if you need to create more than one instance or you need to control the time when an instance is created inject a Provider instead of X.
  • if the object you want to create needs both runtime parameters and dependencies use assisted inject.
  • for many kinds of objects (like DTO, POJO and alike) its absolutely ok to create them by calling new or a conventional factory.

In this sense the injector is implicitly available to any instance created by Guice this includes the API user.

And finally AOP. Aspects are a powerful feature but also can hide some of the business logic I suggest to use them only for very repetitive tasks which all developers know well.

Also take into account that aspects only work on:

  • instances created by Guice
  • non private, non static, non private methods

Finally, Guice won't inform you if you add an annotation to either of the above. Your aspect will silently be ignored

Ok, those are many questions you have and I guess some of the points can be approached in more than one way.

Creating the injector is not cheap. Guice will do some analysis to detect errors as well as create all singletons. So you should create the injector at startup.

I usually have a single injector for my application.

Regarding your question 1.:

Yes the injector can be injected. But I see it as a bad practice. Reason for this is that calls to injector.getInstance() and injector.injectMembers() make it hard to reason about the dependencies of a class.

  • if you need to create more than one instance or you need to control the time when an instance is created inject a Provider instead of X.
  • if the object you want to create needs both runtime parameters and dependencies use assisted inject.
  • for many kinds of objects (like DTO, POJO and alike) its absolutely ok to create them by calling new or a conventional factory.

In this sense the injector is implicitly available to any instance created by Guice this includes the API user.

And finally AOP. Aspects are a powerful feature but also can hide some of the business logic I suggest to use them only for very repetitive tasks which all developers know well.

Also take into account that aspects only work on:

  • instances created by Guice
  • non private, non static, non private methods

Finally, Guice won't inform you if you add an annotation to either of the above. Your aspect will silently be ignored

Ok, those are many questions you have and I guess some of the points can be approached in more than one way.

Creating the injector is not cheap. Guice will do some analysis to detect errors as well as create all singletons. So you should create the injector at startup.

I usually have a single injector for my application.

Reagarding your question 1.: Yes

Yes the injector can be injected. But I see it as a bad practice. Reason fotfor this is that calls to injector.getInstance()injector.getInstance() and injector.injectMembers()injector.injectMembers() make it hard to reason about the dependencies of a class.

  • if you need to create more than one instance or you need to controllcontrol the time when an instance is created inject a Provider instead of X.
  • if the object you want to create needs both runtime parameters and dependencies use asisstedassisted inject.
  • foryfor many kinds of objects (like DTO, POJO and alike) its absolutely ok to create them by calling new or a conventional factory.

In this sense the injector is implicitly available to any instance created by guiceGuice this includes the API user.

And finally AOP. Aspects are a powerfullpowerful feature but also can hide some of the business logic I suggest to use them only for very repetitive tasks which all developers know well. Also

Also take into account that aspects only work on -instances created by guice:

  • instances created by Guice
  • non private, non static, non private methods And guice wont inform you if you add an annotation to either of the above. Your aspect will silently be ignored

Finally, Guice won't inform you if you add an annotation to either of the above. Your aspect will silently be ignored

Ok, those are many questions you have and I guess some of the points can be approached in more than one way.

Creating the injector is not cheap. Guice will do some analysis to detect errors as well as create all singletons. So you should create the injector at startup.

I usually have a single injector for my application.

Reagarding your question 1.: Yes the injector can be injected. But I see it as a bad practice. Reason fot this is that calls to injector.getInstance() and injector.injectMembers() make it hard to reason about the dependencies of a class.

  • if you need to create more than one instance or you need to controll the time when an instance is created inject a Provider instead of X.
  • if the object you want to create needs both runtime parameters and dependencies use asissted inject.
  • fory many kinds of objects (like DTO, POJO and alike) its absolutely ok to create them by calling new or a conventional factory.

In this sense the injector is implicitly available to any instance created by guice this includes the API user.

And finally AOP. Aspects are a powerfull feature but also can hide some of the business logic I suggest to use them only for very repetitive tasks which all developers know well. Also take into account that aspects only work on -instances created by guice

  • non private, non static, non private methods And guice wont inform you if you add an annotation to either of the above. Your aspect will silently be ignored

Ok, those are many questions you have and I guess some of the points can be approached in more than one way.

Creating the injector is not cheap. Guice will do some analysis to detect errors as well as create all singletons. So you should create the injector at startup.

I usually have a single injector for my application.

Reagarding your question 1.:

Yes the injector can be injected. But I see it as a bad practice. Reason for this is that calls to injector.getInstance() and injector.injectMembers() make it hard to reason about the dependencies of a class.

  • if you need to create more than one instance or you need to control the time when an instance is created inject a Provider instead of X.
  • if the object you want to create needs both runtime parameters and dependencies use assisted inject.
  • for many kinds of objects (like DTO, POJO and alike) its absolutely ok to create them by calling new or a conventional factory.

In this sense the injector is implicitly available to any instance created by Guice this includes the API user.

And finally AOP. Aspects are a powerful feature but also can hide some of the business logic I suggest to use them only for very repetitive tasks which all developers know well.

Also take into account that aspects only work on:

  • instances created by Guice
  • non private, non static, non private methods

Finally, Guice won't inform you if you add an annotation to either of the above. Your aspect will silently be ignored

added part about DTO, POJO, and alike
Source Link

Ok, those are many questions you have and I guess some of the points can be approached in more than one way.

Creating the injector is not cheap. Guice will do some analysis to detect errors as well as create all singletons. So you should create the injector at startup.

I usually have a single injector for my application.

Reagarding your question 1.: Yes the injector can be injected. But I see it as a bad practice. Reason fot this is that calls to injector.getInstance() and injector.injectMembers() make it hard to reason about the dependencies of a class.

  • if you need to create more than one instance or you need to controll the time when an instance is created inject a Provider instead of X.
  • if the object you want to create needs both runtime parameters and dependencies use asissted inject.
  • fory many kinds of objects (like DTO, POJO and alike) its absolutely ok to create them by calling new or a conventional factory.

In this sense the injector is implicitly available to any instance created by guice this includes the API user.

And finally AOP. Aspects are a powerfull feature but also can hide some of the business logic I suggest to use them only for very repetitive tasks which all developers know well. Also take into account that aspects only work on -instances created by guice

  • non private, non static, non private methods And guice wont inform you if you add an annotation to either of the above. Your aspect will silently be ignored

Ok, those are many questions you have and I guess some of the points can be approached in more than one way.

Creating the injector is not cheap. Guice will do some analysis to detect errors as well as create all singletons. So you should create the injector at startup.

I usually have a single injector for my application.

Reagarding your question 1.: Yes the injector can be injected. But I see it as a bad practice. Reason fot this is that calls to injector.getInstance() and injector.injectMembers() make it hard to reason about the dependencies of a class.

  • if you need to create more than one instance or you need to controll the time when an instance is created inject a Provider instead of X.
  • if the object you want to create needs both runtime parameters and dependencies use asissted inject.

In this sense the injector is implicitly available to any instance created by guice this includes the API user.

And finally AOP. Aspects are a powerfull feature but also can hide some of the business logic I suggest to use them only for very repetitive tasks which all developers know well. Also take into account that aspects only work on -instances created by guice

  • non private, non static, non private methods And guice wont inform you if you add an annotation to either of the above. Your aspect will silently be ignored

Ok, those are many questions you have and I guess some of the points can be approached in more than one way.

Creating the injector is not cheap. Guice will do some analysis to detect errors as well as create all singletons. So you should create the injector at startup.

I usually have a single injector for my application.

Reagarding your question 1.: Yes the injector can be injected. But I see it as a bad practice. Reason fot this is that calls to injector.getInstance() and injector.injectMembers() make it hard to reason about the dependencies of a class.

  • if you need to create more than one instance or you need to controll the time when an instance is created inject a Provider instead of X.
  • if the object you want to create needs both runtime parameters and dependencies use asissted inject.
  • fory many kinds of objects (like DTO, POJO and alike) its absolutely ok to create them by calling new or a conventional factory.

In this sense the injector is implicitly available to any instance created by guice this includes the API user.

And finally AOP. Aspects are a powerfull feature but also can hide some of the business logic I suggest to use them only for very repetitive tasks which all developers know well. Also take into account that aspects only work on -instances created by guice

  • non private, non static, non private methods And guice wont inform you if you add an annotation to either of the above. Your aspect will silently be ignored
Source Link
Loading