Restricted Generic Type (T Extends SomeClass) Problem
Problem
when generating the restricted generic type as follow, the dynamic will filled in and result in exceptions
Annotation
@injectable
class Repository<T extends Entity> {
...
}
Generated code
gh.factory<Repository<dynamic>>(() => Repository<dynamic>());
which will not compile...
@Peng-Qian I see. This should normally register without a type? how would you manually register it?
I think the problem here is that you cannot know what T is when registering and get_it does not provide a way to know either.
IMO the best workaround for this is to register a factory class instead.
@injectable
class RepositoryFactory {
Repository<T> getRepositoryFor<T>() => Repository<T>();
}
Which you can then use as GetIt.instance.get<RepositoryFactory>.getRepositoryFor<MyEntity>()
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions