runtime_injector icon indicating copy to clipboard operation
runtime_injector copied to clipboard

Add scoped providers

Open TehPers opened this issue 3 years ago • 0 comments

Add a way for providers to have a scope. For example, one way a scope might be implemented is this:

let scope = injector.scope(); // has Drop impl
let foo: Svc<Foo> = scope.get().unwrap();

Scoped providers don't guarantee the lifetime of the values that they provide. If a scope is dropped, there's no way to know if all references to the services it provided were dropped since they use reference-counted pointers or have been moved to outside of the injector (in the case of owned injection). Instead, scopes only would guarantee that scoped providers provide the same instances from the same scope, and different instances from different scopes.

TehPers avatar May 13 '21 22:05 TehPers