Skip to content
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

Feature request: service lookup & Singleton #14

Closed
kcmvp opened this issue Sep 8, 2022 · 1 comment
Closed

Feature request: service lookup & Singleton #14

kcmvp opened this issue Sep 8, 2022 · 1 comment

Comments

@kcmvp
Copy link

kcmvp commented Sep 8, 2022

1: Does this framework ensure singleton instance?

2: Support service lookup:
There is scenario that we just want to get a service when in a function call but I dont want to new a new instance of the target service.

in java ecosystem the famous springboot support above features.

I am choosing a DI framework for my project and find I need above two features. the case is

** source code**

interface A {
  M1()
  M2()
}
var _ A = (*ImplA)(nil)
struct ImplA {
}

func NewImplaA() {
}
....

but right now I want to test another function which depends on the interface(ImplA) with Mock. if this framework can supply above features than I can inject a mocked implementation and then the tested method can looup the mock object.

@kcmvp kcmvp changed the title Feature request: service lookup Feature request: service lookup & SingleTon Sep 8, 2022
@kcmvp kcmvp changed the title Feature request: service lookup & SingleTon Feature request: service lookup & Singleton Sep 8, 2022
@samber
Copy link
Owner

samber commented Sep 11, 2022

1- You can call Invoke[ImplA](injector) many times, and the same instance will be returned (singleton)
2- See https://github.com/samber/do#cloning-injector

@samber samber closed this as completed Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants