java - GWT Deferred Binding and Dependency Injection -
assuming have so
interface
interface isinterface {}
implementation classes
public concreteclassa implements isinterface { injectora a, injectorb c, injectorc c; @inject concreteclassa(injectora a, injectorb b, injectorc c) { this.a = a; this.b = b; ..... } } public concreteclassb implements isinterface { injectora a, injectorb b, injectorc c; @inject concreteclassb(injectora a, injectorb b, injectorc c) { this.a = a; this.b = b; ..... } }
..and decide use gwt deferred binding in gwt module.gwt.xml
//pseudo xml configuration if (type isinterface) if toggle == use concreteclass else use concreteclassb
now, when try run this. won't work because gwt expected concrete class , b have default 0 constructor. so, tried following on concrete class
@inject injectora a; @inject injectorb b; @inject injectorc c; concreteclassa() { }
which bypass 0 constructor error gives me nullpointerexception when try use a, b or c. 1 way make work remove @inject , use gwt.create() so
injectora a, injectorb b, injectorc c; concreteclassa() { this.a = gwt.create(injectora.class); ..... ..... }
this work if injectora, injectorb , injectorc have none 0 constructor , depended heavily on @inject. dont want go through classes create 0 constructors , replace @inject gwt.create(). there has better way this. missing here?
found solution this
interface isinterface { @inject void init(injectora a, injectorb b, ...); } public concreteclassa implements isinterface { injectora a, injectorb c, injectorc c; concreteclassa() {} @override public void init(injectora a, injectorb b, ..) { this.a = a; this.b = b; .... } }
Comments
Post a Comment