Skip to content
This repository has been archived by the owner on Dec 6, 2017. It is now read-only.

Ability to inject parameterized type with non primitive #170

Open
jrote1 opened this issue Aug 18, 2014 · 7 comments
Open

Ability to inject parameterized type with non primitive #170

jrote1 opened this issue Aug 18, 2014 · 7 comments

Comments

@jrote1
Copy link

jrote1 commented Aug 18, 2014

Is it possible for the following to be made possible as currently i recieve the following error:

No provider found for GenericClass! (resolving IndexComponent -> IndexComponent -> GenericClass)

But it works if I use string instead of TestClass

My code:

@Injectable()
class GenericClass<T>{
    GenericClass();
}

class TestClass{


}

class Bootstrap extends Module {
    Bootstrap() {
        bind(new TypeLiteral<GenericClass<TestClass>>().type, inject: [], toFactory: ()=> new GenericClass<TestClass>());
        bind(IndexComponent);
    }
}

@Injectable()
class IndexComponent {
    GenericClass<TestClass> _test;

    IndexComponent(this._test);
}
@jrote1
Copy link
Author

jrote1 commented Aug 21, 2014

Any ideas?

@vicb
Copy link
Contributor

vicb commented Aug 21, 2014

Would it work better if your class really depends on the generic type ?

@jrote1
Copy link
Author

jrote1 commented Aug 21, 2014

What do you mean?

@jrote1
Copy link
Author

jrote1 commented Aug 21, 2014

I am depending on it

@vicb
Copy link
Contributor

vicb commented Aug 21, 2014

@Injectable()
class GenericClass<T>{
  T t;    
  GenericClass();
}

@jrote1
Copy link
Author

jrote1 commented Aug 21, 2014

Yes this example is a stripped down version of my example code but the main issue is if i depend on

GenericClass<string> 

it works
if i depend on

GenericClass<TestClass>

it does not

@vicb
Copy link
Contributor

vicb commented Aug 21, 2014

All the test cases use List or Map.
May be you can submit a PR with a test case that triggers the defect.

I'm not sure if this can be fixed for now, a more robust implementation depends on a bug being fixed in dart2js (see Allow injecting typedef'd dependencies #106)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants