fluttercommunity / get_it

Get It - Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App. Maintainer: @escamoteur
https://pub.dev/packages/get_it
MIT License
1.36k stars 149 forks source link

Scoped service per screen or page #372

Closed malabuyocfritz1984 closed 2 months ago

malabuyocfritz1984 commented 3 months ago

Hi,

I'm new to get_it so apologies in advance.

But Is there a way to create a scoped service per screen or page?

In .net we have like an AddScoped(MyService()), which registers the service with a scoped lifetime, Scoped Service are the same within an http request, but different across different http requests.

is that possible with get_it? a scope per screen and when the screen is closed, these scoped service will be disposed as well

escamoteur commented 3 months ago

In general scopes are organized in a stack. Each object registered in a lower scope is accessible from higher scopes unless you register the sane type in a higher scope than that instance will shadow the already registered one. As said you can use watch_it's pushScope function that will create a new scope when the widget is built the first time and Pop it when the widget gets destroyed. Am 1. Sept. 2024, 21:28 +0100 schrieb malabuyocfritz1984 @.***>:

Hi, I'm new to get_it so apologies in advance. But Is there a way to create a scoped service per screen or page without having to re-register the same service in another screen scope? In .net we have like an AddScoped(MyService()), which registers the service with a scoped lifetime, Scoped Service are the same within an http request, but different across different http requests. so I'm wondering if there is a way to do that in get_it? a scope per screen and when the screen is closed, these scoped service will be disposed as well — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>