Closed luiscoms closed 2 years ago
@luiscoms,
This behavior already exists. Try use @singleton
decorator available in the core
module. For example:
from config.spring import config_client
from config.core import singleton
@singleton
@config_client()
def foo(client):
return client
@config_client()
def bar(client):
return client
a = foo()
b = foo()
c = bar()
d = bar()
print(id(a))
print(id(b)) # a == b
print(id(c))
print(id(d)) # c != d
I'll keep this issue open until the documentation is updated.
I understood, my suggestion is create a library decorador, not create myself decorator.
Sorry I didn't understand this point: "create a decorator library, not create myself decorator"?
The decorator @singleton
is now available for use and is used in the lib. All you need to do is import the decorator and use it as in a stack.
Could you detail the issue request a little more?
Sure, my case is the same as I explained above.
import logging
from config.core import singleton
from config.spring import config_client
@singleton
@config_client()
def foo(client):
# do stuff with client
logging.debug(client.config)
return client
@singleton
@config_client()
def bar(client):
# do stuff with client
logging.debug(client.config)
return client
id(foo()) == id(bar()) # False
@luiscoms,
Sorry, as this issue is approximately for 1 year and a half without any change, I decided to close it with wontfix
status however if there is any change in the general interest we can reevaluate.
If I decorate two or more functions, it will call server both times. It would be great a decorator that return singleton instance.
Suggestion
Or