|
|
|
|
|
|
|
|
|
|
|
Re: Injection of extened classes [message #999866 is a reply to message #999685] |
Sun, 13 January 2013 08:42 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
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.04061 seconds