Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » use XText RunTimeModule for custom class(cuctomize injection)
use XText RunTimeModule for custom class [message #1728909] Fri, 08 April 2016 12:38 Go to next message
Alex Gor is currently offline Alex GorFriend
Messages: 145
Registered: November 2014
Location: Russia
Senior Member
Hello

I have couple of questions regarding injection mechanizm in XText.
I would like to use Dependency Injection in process of code generation.
So I add in MyDslRuntimeModule the following code
public class MyDSLRuntimeModule extends AbstractMyDSLRuntimeModule {
	
	
	public void configureMyService(Binder binder) {
		binder.bind(IService.class).annotatedWith(Names.named("ServiceName").to(ServiceImpl.class);
	}
	
}



and I would like to use the following code in client class

class a_client_class {
    @Inject
    @Named("ServiceName")
    private IService service_provider;

   public void method() {
        this.service_provider.do_something();
    }
}


I understood that in clinet class should know about injection functionality that generated by XText. I don't know how to explain to client class about this mechanizm. This is my first question.

My second question is Using generated by XText injection modules for custom class is good idea or not?

May be I schould create my owner Injector and use itfor my private purposes.

Could you please clarify this problem?

Thanks in advance
Alex
Re: use XText RunTimeModule for custom class [message #1728919 is a reply to message #1728909] Fri, 08 April 2016 13:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
yes you can use this for your own code as well.

to get this running you have to create the client class via @Inject or via Injector i = ....; i.getInstance(Client.class)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: use XText RunTimeModule for custom class [message #1728924 is a reply to message #1728919] Fri, 08 April 2016 13:32 Go to previous messageGo to next message
Alex Gor is currently offline Alex GorFriend
Messages: 145
Registered: November 2014
Location: Russia
Senior Member
Thanks for answer on the first question.


but about the second question

As I understand correctly XText infrastructure the XText injection feature is created in class MyDSLStandaloneSetup that use his parent for main work.

From other hand the way of getting injector that created by XText is not clear
I see method createInjectorAndDoEMFRegistration in parent class of MyDSLStandalonesetup, but this class creating Injector from scratch, i think this is long procedure. Also I see in test project a class like MyDSLInjectorProvider.

I can create class like this in production project, I don't know how guarantee a calling of this method on apllication startup

[Updated on: Fri, 08 April 2016 14:03]

Report message to a moderator

Re: use XText RunTimeModule for custom class [message #1728944 is a reply to message #1728924] Fri, 08 April 2016 14:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
Hi i dont get that. Bindings are done in the modules. Thus you can either
add your bindings to the existing modules or you need to use your own
module in your standalone setup (And/or activator)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: use XText RunTimeModule for custom class [message #1729127 is a reply to message #1728944] Mon, 11 April 2016 11:31 Go to previous messageGo to next message
Alex Gor is currently offline Alex GorFriend
Messages: 145
Registered: November 2014
Location: Russia
Senior Member
Hallo Christian,

Thank you for support. Could you clarify my last question. I need to get instance of Injector object in Generator implementaion. Plugin with suffix ui(I mean org.xtext.example.ui) has activator that generated by XText and in this plugin I can easy get instance of Injector using something like Activator.getInstance().getInjector.
But plugin like org.xtext.example does not has generated activator. It has Standalone setup class. But user schould not use this class inside Eclipse.

I understand that I can use @Inject annotation and inject field in class, but sometimes more convinient get instnces of set of objects of an object via createInstance method. For example I have interface IService and several implemantations of this service. I need to get a few implemantations of this service during code genaration process.
So is there way to get instance of Injector in Generator implementation

Thanks
Alex


Re: use XText RunTimeModule for custom class [message #1729132 is a reply to message #1729127] Mon, 11 April 2016 11:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
@Inject Injector injector?

or

@Inject
Provider<MyService> myServiceProvider

???


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: use XText RunTimeModule for custom class [message #1729238 is a reply to message #1729132] Tue, 12 April 2016 10:59 Go to previous message
Alex Gor is currently offline Alex GorFriend
Messages: 145
Registered: November 2014
Location: Russia
Senior Member
Thank you support.

I resolved my problem. Also I found out that RuntimeModule has root interface Module, not abstract class AbstractModule. In this case we cannot use install method and AssistgedInjection. It is pity
Previous Topic:Ultra giga slow editor for big Xbase DSL model
Next Topic:Initialize a ResourceSet with some library models
Goto Forum:
  


Current Time: Fri Nov 22 05:01:04 GMT 2019

Powered by FUDForum. Page generated in 0.02460 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top