shaku icon indicating copy to clipboard operation
shaku copied to clipboard

Suggestion: renaming Component to Singleton

Open leinardi opened this issue 3 years ago • 2 comments

Having used other popular dependency injection libraries for other languages, I find the use of the name Component a little misleading. My understanding is that, what is annotated with #[derive(Component)] will survive for the rest of the application runtime, with no other scope, which is what a singleton does and would match the javax.inject.Singleton behavior.

Dagger uses the name Component for something very different, that is way similar to what the shaku's module! macro does: https://developer.android.com/training/dependency-injection/dagger-basics#dagger-components

leinardi avatar Dec 09 '20 09:12 leinardi

I based the naming of "component" on how Spring and Autofac name the "service" classes "components". Dagger's naming in general seems to be a bit different than the rest of the DI libraries, so maybe a better name would be "Service", as that seems to be one thing all of the libraries have in common.

I think this issue should also include the name for what are currently called "providers". Some other possible names include "factories" and "scoped services" (scoping is another topic, but maybe better handled in a separate issue).

AzureMarker avatar Dec 09 '20 21:12 AzureMarker

FYI calling it a Service will conflict with the naming conventions of the axum crate, which uses that word for its transitive dependency crate, tower-service, and uses it as part of its own Router APIs.

wanderrful avatar Jun 22 '23 19:06 wanderrful