Skip to content

Registrering class with generics gives error #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lgLindstrom opened this issue Jun 28, 2021 · 3 comments
Closed

Registrering class with generics gives error #207

lgLindstrom opened this issue Jun 28, 2021 · 3 comments

Comments

@lgLindstrom
Copy link

I have different model classes that I would like to save to a database. For this
For example, one class is called Data Model.

class DataModel {}

I have defined a database interface class.

class DbInterface<T> {
...... 
}

Then I have my database class.

class Database<T> implements DbInterface<T> {
... 
} 

For a specific datamodel i register this within Getit

getit.instance.registerSingelton<DbInterface<DataModel>>(Database<DataModel>)

When trying to get a instance
Getit.instance.get<DbInterface<DataModel>>()

I get a error saying the DbInterface is not known within GetIt.

So, what Im I doing wrong?

@escamoteur
Copy link
Collaborator

On a first glance, this should work. I have to try to reproduce this

@escamoteur
Copy link
Collaborator

I now tried to replicate exactly what you are doing:

    GetIt.I.registerSingleton<TestBaseClassGeneric<TestBaseClass>>(
        TestClassGeneric<TestBaseClass>());

    final instance1 = GetIt.I.get<TestBaseClassGeneric<TestBaseClass>>();

    expect(instance1 is TestClassGeneric<TestBaseClass>, true);

which works without problems.

My class definitions look like:

class TestBaseClassGeneric<T> {
}

class TestClassGeneric<T> implements TestBaseClassGeneric<T> {
}

@escamoteur
Copy link
Collaborator

I close this for now. if you have more information, please comment.

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

No branches or pull requests

2 participants