Python Service Container
========================
This is a pretty trivial service container with the ability to register Services in it. On
retrieval of an registered service the class got instantiated and behaves as a singleton.
```
from servicecontainer import Service, Container, ServiceInterface
# This is a sample service
class ExampleService(object):
val = None
def __init__(self, param1):
self.val = param1
class ExampleService2(ServiceInterface):
val = None
def __init__(self, param1):
self.val = param1
@classmethod
def asService(cls, parameters):
return Service("testservice2", cls, parameters)
# Create the container
c = Container()
# build an service
s = Service("testservice", ExampleService, {"param1": "param1_value"})
# add the service to the container
c.add(s)
c.add(ExampleService2.asService({"param1": "param1_value"}))
# retrive the service from the container (gots instantiated at this point)
instance = c.get('testservice')
self.assertEqual('param1_value', instance.val)
# list all services
list = c.list()
self.assertEqual(2, len(list))
self.assertEqual(list[0], 'testservice')
# be sure its the same instance
instance2 = c.get('testservice')
assert instance is instance2
```
========================
This is a pretty trivial service container with the ability to register Services in it. On
retrieval of an registered service the class got instantiated and behaves as a singleton.
```
from servicecontainer import Service, Container, ServiceInterface
# This is a sample service
class ExampleService(object):
val = None
def __init__(self, param1):
self.val = param1
class ExampleService2(ServiceInterface):
val = None
def __init__(self, param1):
self.val = param1
@classmethod
def asService(cls, parameters):
return Service("testservice2", cls, parameters)
# Create the container
c = Container()
# build an service
s = Service("testservice", ExampleService, {"param1": "param1_value"})
# add the service to the container
c.add(s)
c.add(ExampleService2.asService({"param1": "param1_value"}))
# retrive the service from the container (gots instantiated at this point)
instance = c.get('testservice')
self.assertEqual('param1_value', instance.val)
# list all services
list = c.list()
self.assertEqual(2, len(list))
self.assertEqual(list[0], 'testservice')
# be sure its the same instance
instance2 = c.get('testservice')
assert instance is instance2
```
Metadata
Release files for python-servicecontainer 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python-servicecontainer-1.0.2.tar.gz | 3.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_servicecontainer-1.0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 8.2 kB
Release files / python-servicecontainer-1.0.2.tar.gz
| Download URL | python-servicecontainer-1.0.2.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f4224fd080b5a713205763b74a562332cb99bb9cacbf028e9b3094c0c71b82d
|
|
BLAKE2b-256 checksum How to use checksums |
59c3b06b6d8f597c0cef69db559211033ff619f225cf5b1069a0f35c801146dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / python_servicecontainer-1.0.2-py2.py3-none-any.whl
| Download URL | python_servicecontainer-1.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
dc630c696044e17ff94afd33d0aef4724d722247fdf9f9af7015478585e58efb
|
|
BLAKE2b-256 checksum How to use checksums |
e0e5c017efe05b5f387f52bd9e7fff35284d37731ec9e3e19f3a704917727a9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |