Skip to content

Commit 4c91a11

Browse files
committed
allow getting components
1 parent 170b54c commit 4c91a11

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

Diff for: jadi/jadi.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ def get_service(self, cls):
2626
self.service_instances[fqdn] = cls(self)
2727
return self.service_instances[fqdn]
2828

29+
def get_component(self, cls):
30+
fqdn = get_fqdn(cls)
31+
if fqdn not in self.component_instances:
32+
self.component_instances[fqdn] = cls(self)
33+
return self.component_instances[fqdn]
34+
2935
def get_components(self, cls):
3036
for comp in cls.implementations:
31-
fqdn = get_fqdn(comp)
32-
if fqdn not in self.component_instances:
33-
self.component_instances[fqdn] = comp(self)
34-
yield self.component_instances[fqdn]
37+
yield self.get_component(comp)
3538

3639

3740
def service(cls):
@@ -155,6 +158,11 @@ def decorator(cls):
155158
)
156159
)
157160
iface.implementations.append(cls)
161+
162+
def get(cls, context):
163+
return context.get_component(cls)
164+
cls.get = get.__get__(cls)
165+
158166
return cls
159167

160168
return decorator

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='jadi',
8-
version='1.0.0',
8+
version='1.0.1',
99
install_requires=[],
1010
description='Minimalistic IoC for Python',
1111
author='Eugeny Pankov',

Diff for: tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def component_test():
6363
assert isinstance(all[1], TestComponent2)
6464
any = TestInterface.any(ctx)
6565
assert isinstance(any, TestComponent)
66+
assert isinstance(TestComponent.get(ctx), TestComponent)
6667

6768

6869
@raises(NoImplementationError)

0 commit comments

Comments
 (0)