Why @PetiteInject cannot inject service in DecoraManager?

46 views Asked by At

I have a DecoraManager implementation : AppDecoraManager, and want to inject a service e.g.: FooService as:

@PetiteInject
FooService fooService;

When resolveDecorator() is called I want to use fooService to determine some parameters, but it has null value.

What could be the reason for this, and how could I resolve it?

1

There are 1 answers

0
igr On BEST ANSWER

DecoraManager is created by the servlet container, in DecoraServletFilter.

At the moment, there is no integration with existing Petite IOC, so you have to do the following:

  • First, you need to have a public static reference to PetiteContainer. Store it during the creation of container, for example.
  • Override createDecoraManager() in your implementation
  • Use PetiteContainer.wire(this) in your implementation of DecoraManager.

That is the only way to do so, so far.

The alternative would be this:

  • Register DecoraManager as @PetiteBean.
  • Again, get the static reference to PetiteContainer
  • In createDecoraManager use PetiteContainer.get() to get the instance.

In the first example, DecoraManager gets just wired; in the second example, it gets stored in Petite container, too.