How to do ContextInjectionFactory.make with paramatrized constructor? [message #1002456] |
Fri, 18 January 2013 11:10  |
Eclipse User |
|
|
|
I have a widget named TableToolbar which has a parametrized constructor.
class TableToolbar{
@Inject
MyData data;
public TableToolbar(Composite parentComposite) {
func(data);
...
}
I would like to Inject the data from IEclipseContext into it, before starting the constructor.
This I usually do with
ContextInjectionFactory.make(TableToolbar, eclipseContext);
Now I have a specific Composite, which I need to pass a specific Composite to the TableToolbar constructor.
Is it possible?
P.S.
I can not inject the data later by
TableToolbar tableToolbar= new TableToolbar(composite);
ContextInjectionFactory.inject(tableToolbar, context);
because the injected data are needed inside the constructor.
|
|
|
|
|
|
|
|
Re: How to do ContextInjectionFactory.make with paramatrized constructor? [message #1003557 is a reply to message #1003461] |
Mon, 21 January 2013 09:10  |
Eclipse User |
|
|
|
Thnx Sopot, now my code looks as following:
class TableToolbar{
@Inject
MyData data;
public TableToolbar(Composite parentComposite) {}
@PostConstruct
public void init(){
func(data);
...
}
TableToolbar toolbar = new TableToolbar(containerTop);
ContextInjectionFactory.inject(toolbar, context); //calls @PostConstruct annotated method
I still have to inject manually, because I would like to create the TableToolbar myselfe. It makes the code more understandable, than using Tom's version, with a child container:
c2 = context.createChild();
c2.set( Composite.class, myParentComposite );
ContextInjectionFactory.make(TableToolbar.class, c2);
|
|
|
Powered by
FUDForum. Page generated in 0.15138 seconds