Injection of extened classes [message #995903] |
Mon, 31 December 2012 08:17  |
Eclipse User |
|
|
|
Hi,
is there a reason why this
@Creatable
public class FileListViewer extends ListViewer{
FileNameList fileList;
@Inject
public FileListViewer(Composite parent) {
super(parent, SWT.NONE);
System.out.println("aaaa");
doesn't work if I try to inject the FileListViewer Class somewhere?
If I remove the extension and the 'super'-call it prints 'aaaa'.
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Injection of extened classes [message #999866 is a reply to message #999685] |
Sun, 13 January 2013 03:42  |
Eclipse User |
|
|
|
Yes, you got it! The only thing you need to make sure now it to dispose
the child context once, once MyClass is not needed anymore.
Tom
Am 12.01.13 22:47, schrieb Aljoscha Steffens:
> Okay, maybe I got it now:
> Say there is a Class MyClass which needs and Instance of NeededClass:
>
> Class MyClass
>
> @Inject
> public void MyClass(NeededClass neededClass){
> ...
> }
>
>
> So if an instance of MyClass should be created, the frameworks looks in
> the context of MyClass if it finds an instance of NeededClass.
> The way I did it was to mark the class NeededClass with @Creatable : the
> context would not find an instance of NeededClass, so it would create one.
> But I should rather create an context for the instance of MyClass where
> an instance of NeededClass is available.
> Like this
>
> ////.... in some other class I want to create an instance of MyClass
>
> @Inject
> public void foo(IEclipseContext ctx){
> NeededClass myNeededClass =
> ContextInjectionFactory.make(NeededClass.class, ctx);
> ctnx.set(NeededClass.class, myNeededClass);
> MyClass myClass = ContextInjectionFactory.make(MyClass.class, ctx);
>
> ...
> }
>
>
>
> Is this the correct way?
|
|
|
Powered by
FUDForum. Page generated in 0.05851 seconds