-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Return the instance when calling registerSingleton #242
Return the instance when calling registerSingleton #242
Conversation
Hi, sorry for not looking into this earlier, but I had some mental health problems the last half year. Why do you think this is better than
|
It's mostly for convenience, but it also lets you register a singleton like this: class Class {
final instance = GetIt.I.registerSingleton(Object());
} Which isn't possible otherwise |
I see, but why do you store the instance at all outside of get_it?
Am 3. Feb. 2022, 19:01 +0100 schrieb Rexios ***@***.***>:
… It's mostly for convenience, but it also lets you register a singleton like this:
class Class {
final instance = GetIt.I.registerSingleton(Object());
}
Which isn't possible otherwise
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you commented.Message ID: ***@***.***>
|
For myself I use it for more convenient initialization of the singleton: final instance = GetIt.I.registerSingleton(Object());
instance.setup();
instance.doOtherStuff(); Not a huge deal to split the first line into two, but again this is just for convenience. |
@esDotDev What do you think? |
I think darts chaining ability makes this a bit redundant.
On the other hand, it cant really hurt, and is a small quality of life thing, so why not? |
What I don't like is that it would break the format of the other registerFunctions. |
Couldn't we make those do the same thing? |
Unfortunately no, because all the registerFuncions that take a factoryfuncion return without creating an instance |
I think if it's lazy, it's obvious why it wouldn't return anything. Seems ok to me. |
If we did want to have similar functionality lazily, an |
Just a random thought: you can't await chained async calls |
I know this is a pretty old PR but I had to make a break over the last year |
Just a convenience feature so you can write code like this: