Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Add a way to bind a specific instance of a singleton #23

@TechnoPorg

Description

@TechnoPorg

Hi! I'm loving this crate so far, so thank you for all your hard work. There's one thing which it seems to be missing to fit my use case, though:

It would be nice to be able to bind a type to an existing singleton, like so:

let my_singleton = MySingleton::new();
my_singleton.configure(/*args*/);
my_singleton.do_something_else();

di_container.bind::<MySingleton>::().to_singleton(my_singleton);
// And now we can use the specific `my_singleton` instance when resolving dependencies with the container.

Otherwise, we either have to use the factory feature, which forces rust nightly, or depend solely on the dependency's new function, which would make it quite challenging to configure the service based on external information.

There's a tentative PoC here: https://github.com/TechnoPorg/Syrette/tree/explicit-singleton-binding/. But I'm not especially familiar with Syrette, so I'm sure there's much there that I left out. For one thing, the injectable derive macro still requires a new constructor on my branch, even though it technically isn't needed.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureA feature request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions