Reputation: 99
When I create a new instance by
MyObject obj = new MyObject();
the injections never happen.
The example source for MyObject could be...
@Stateless
public class MyObject{
@Inject
Injection inj;
public MyObject() {
}
...
}
do the injections just work in injected objects? Is there no way of the using injection when I explicitly create a new instance?
I want to create a Class menu that creates instances dynamically (using reflection... the reflection is not the problem... I have tried using the new
syntax).
I don't want to inject each View class in my menu or main class.
Upvotes: 1
Views: 1525
Reputation: 735
You need to annotate the class with @Named so that it is instantiated by the IoC, otherwise it will never get to see the @Inject.
Upvotes: 0
Reputation: 32936
Injections will only work in objects which the container is controlling the lifetime of. If you are just creating new objects how is the container going to know that the object has been created.
Usually the solution to your problem is one of the following:
Upvotes: 2