File tree 3 files changed +14
-5
lines changed
3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -26,12 +26,15 @@ def get_service(self, cls):
26
26
self .service_instances [fqdn ] = cls (self )
27
27
return self .service_instances [fqdn ]
28
28
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
+
29
35
def get_components (self , cls ):
30
36
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 )
35
38
36
39
37
40
def service (cls ):
@@ -155,6 +158,11 @@ def decorator(cls):
155
158
)
156
159
)
157
160
iface .implementations .append (cls )
161
+
162
+ def get (cls , context ):
163
+ return context .get_component (cls )
164
+ cls .get = get .__get__ (cls )
165
+
158
166
return cls
159
167
160
168
return decorator
Original file line number Diff line number Diff line change 5
5
6
6
setup (
7
7
name = 'jadi' ,
8
- version = '1.0.0 ' ,
8
+ version = '1.0.1 ' ,
9
9
install_requires = [],
10
10
description = 'Minimalistic IoC for Python' ,
11
11
author = 'Eugeny Pankov' ,
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ def component_test():
63
63
assert isinstance (all [1 ], TestComponent2 )
64
64
any = TestInterface .any (ctx )
65
65
assert isinstance (any , TestComponent )
66
+ assert isinstance (TestComponent .get (ctx ), TestComponent )
66
67
67
68
68
69
@raises (NoImplementationError )
You can’t perform that action at this time.
0 commit comments