how to retrieve the Injector [message #655053] |
Fri, 18 February 2011 02:33  |
Eclipse User |
|
|
|
Hi
what is the right way of retrieving the google guice injector of a DSL?
in junit tests you can do this like that
Injector injector =
new MyStandaloneSetup().createInjectorAndDoEMFRegistration();
but I wanted to retrieve it for junit PLUGIN tests, (I need to retrieve
IDocumentEditor, see my other post)... the documentation says
Injector injector = Guice.createInjector(new MyDslRuntimeModule());
but the ui module wants a plugin to be passed as an argument...
I noted that in the ui plugin you get a generated activator in src-gen,
in an ".internal" package... with that one I can retrieve the Injector:
Injector injector = MyDSLActivator.getInstance().getInjector(
"org.mydsl.MyDsl");
but is that the correct way? I'm asking because this way I need to
access an .internal package (which usually is not advised), and since I
need it in junit plugin test, I need to export that internal package in
the ui dsl plugin...
thus, in general, which is the right way to retrieve the Injector?
thanks in advance
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
|
|
|
|
Re: how to retrieve the Injector [message #656743 is a reply to message #655325] |
Mon, 28 February 2011 06:57   |
Eclipse User |
|
|
|
On 02/19/2011 01:17 PM, Sebastian Zarnekow wrote:
> Hi Lorenzo,
>
>> Injector injector = MyDSLActivator.getInstance().getInjector(
>> "org.mydsl.MyDsl");
>>
>> but is that the correct way? I'm asking because this way I need to
>> access an .internal package (which usually is not advised), and since I
>> need it in junit plugin test, I need to export that internal package in
>> the ui dsl plugin...
>>
>> thus, in general, which is the right way to retrieve the Injector?
>
> Yes, it is. You may want to export the internal package only for the
> test project by means of the x-friends directive:
> http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/misc/bundle_manifest.html
Thanks, I'll try that!
I noted that the way to retrieve the Injector from the ui plugin is not
documented in Xtext documentation, is it?
I think it would be good to document it, since it might not be clear...
I also have another question about retrieving the Injector: what is the
right way to retrieve the injector from the NON ui plugin?
thanks again
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
|
|
|
Re: how to retrieve the Injector [message #656755 is a reply to message #656743] |
Mon, 28 February 2011 07:48   |
Eclipse User |
|
|
|
Accessing the injector from the Activator is indeed not documented.
There are only a few occasions where you have to do that, e.g. when
reusing Xtext components in other frameworks. In any case you should
limit direct access to the injector to a minimum, as this is quite
against the paradigm of DI.
OTOH, using the search facility of the Eclipse documentation, I found 3
places in the docs where we describe how to obtain the Injector in the
non-Eclipse runtime scenario :-) Hint: Search "injector" or have a look
at your language's standalone setup.
Am 28.02.11 12:57, schrieb Lorenzo Bettini:
> On 02/19/2011 01:17 PM, Sebastian Zarnekow wrote:
>> Hi Lorenzo,
>>
>>> Injector injector = MyDSLActivator.getInstance().getInjector(
>>> "org.mydsl.MyDsl");
>>>
>>> but is that the correct way? I'm asking because this way I need to
>>> access an .internal package (which usually is not advised), and since I
>>> need it in junit plugin test, I need to export that internal package in
>>> the ui dsl plugin...
>>>
>>> thus, in general, which is the right way to retrieve the Injector?
>>
>> Yes, it is. You may want to export the internal package only for the
>> test project by means of the x-friends directive:
>> http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/misc/bundle_manifest.html
>>
>
> Thanks, I'll try that!
>
> I noted that the way to retrieve the Injector from the ui plugin is not
> documented in Xtext documentation, is it?
>
> I think it would be good to document it, since it might not be clear...
>
> I also have another question about retrieving the Injector: what is the
> right way to retrieve the injector from the NON ui plugin?
>
> thanks again
> Lorenzo
>
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.54814 seconds