Skip to content

Get by superclass/subclass? #231

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
fzyzcjy opened this issue Nov 9, 2021 · 2 comments
Closed

Get by superclass/subclass? #231

fzyzcjy opened this issue Nov 9, 2021 · 2 comments

Comments

@fzyzcjy
Copy link
Contributor

fzyzcjy commented Nov 9, 2021

Hi thanks for the lib! Consider this simplified example:

class SuperClass {}
class SubClass extends SuperClass {}

GetIt.I.registerSingleton<SubClass>(SubClass());
GetIt.I.get<SubClass>(); // ok
GetIt.I.get<SuperClass>(); // error!

Can we allow the last line to return the SubClass? Currently I workaround by registering twice, but I hope I can register once and make it work.

@escamoteur
Copy link
Collaborator

Hi, sorry for not looking into this earlier, but I had some mental health problems the last half year.

Why don't you register it with the SuperClass? Can you elaborate on the usecase?

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Feb 2, 2022

but I had some mental health problems the last half year.

Sorry to hear that :( Hope you get better now!

Why don't you register it with the SuperClass? Can you elaborate on the usecase?

Indeed I have forgotten why I needed it (months have passed). Currently I think (normally) I can register with the superclass; if I find out why I made this issue I will reopen it. Thanks!

@fzyzcjy fzyzcjy closed this as completed Feb 2, 2022
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