Service Inject For MVC
Project description
示例一:
- 单实例化
from BusyBox.ServiceBox import Box
class AppleService(object):
def name(self):
return 'test'
if __name__ == '__main__':
box = Box()
box.inject(AppleService)
box.apple_service.name()
示例二:
- 带参 多实例化
from BusyBox.ServiceBox import Box
class TestService(object):
def __init__(self, params1):
self.params1 = params1
def handle(self):
return self.params1
class RestService(object):
def __init__(self, params1):
self.params1 = params1
def handle(self):
return self.params1
if __name__ == '__main__':
box = Box()
box.inject(TestService, RestService, payload=dict(params1=1))
box.rest_service.handle()
box.test_service.handle()
示例三:
- 类命名中带实例
from BusyBox.ServiceBox import Box
class Bus1Service(object):
def name(self):
return 'test'
if __name__ == '__main__':
box = Box()
box.inject(Bus1Service)
box.bus1_service.name()
示例四:
- 类命名中带实例
from BusyBox.ServiceBox import Box
box = Box()
@box.depend()
class CowService(object):
@staticmethod
def name():
return 'test'
if __name__ == '__main__':
box = Box()
box.inject(CowService)
box.cow_service.name()
示例五:
- __init__方法带参实例
from BusyBox.ServiceBox import Box
box = Box()
@box.depend()
class EasyService(object):
def __init__(self, params1, *args, **kwargs):
self.args = args
self.kwargs = kwargs
self.params1 = params1
def name(self):
return self.params1, self.args, self.kwargs
if __name__ == '__main__':
box = Box()
box.invoke('easy_service', 1, 2, 3, a=4, b=5)
box.easy_service.name()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
BusyBox-0.7.0.tar.gz
(3.0 kB
view details)
File details
Details for the file BusyBox-0.7.0.tar.gz.
File metadata
- Download URL: BusyBox-0.7.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f5129e1e9b9ef9e5723ce810fedf06ba61f382b69193b4af1210b5eb2a3af5d
|
|
| MD5 |
4a71cd0a8d13e85087c8b168cf7739c6
|
|
| BLAKE2b-256 |
84d75cb45304da0ed6e74312ac8e32f86790b18681a2bbd742778dda9ca94e1e
|