0

As far as I know GIN automatically uses GWT.create() fallback when there is no binding specified. It works perfect when a dependency is injected in a constructor.

@Inject
public PresenterImpl(ResourceManager manager) {...}

Is it possible to initialize the same object using assisted factory? I have tried, but GIN fails to find proper "implementation". In other words I want to define a factory module builder with interface that returns ResourceManager and initialize this object using factory.

xRomZak
  • 176
  • 3
  • 10

1 Answers1

0

I suppose I'm not quite understanding what you want to do:

For an otherwise unspecified binding of, say, ResourceManager, GWT.create will be used, as you mentioned. However, you want to use a factory to perhaps customize the ResourceManager instance before being returned (e.g.: take a raw GWT.create'd ResourceManager, call some methods, and return it for use).

Here's what I might suggest in your Gin Module, instead of a factory:

@Provides
@MyCustomizedResourceManager
ResourceManager provideCustomResourceManager(ResourceManager basicResourceManager, Foo foo, Bar bar) {
  basicResourceManager.setFoo(foo);
  basicResourceManager.setBar(bar);
  return basicResourceManager;
}

The key difference is the customized binding: your provider method relying on the regular GWT.create call for the ResourceManager (and perhaps for Foo and Bar too), but the client (@Inject MyClass(@MyCustomizedResourceManager ResourceManager manager) relies on the binding you've set up explicitly.