@@ -97,8 +97,8 @@ def setup(cls, param1: Any, param2: Any, foo: str) -> DynamicModule:
9797 return DynamicModule(cls, providers=[], controllers=[], routers=[])
9898
9999
100- def module_a_configuration_factory(module: Type[MyModule] , config: Config, foo: Foo):
101- return module.setup(param1=config.param1, param2=config.param2, foo=foo.foo)
100+ def module_a_configuration_factory(module_ref: ModuleRefBase , config: Config, foo: Foo):
101+ return module_ref. module.setup(param1=config.param1, param2=config.param2, foo=foo.foo)
102102
103103
104104 @Module(modules=[ModuleSetup(MyModule, inject=[Config, Foo], factory=module_a_configuration_factory), ])
@@ -162,39 +162,28 @@ def providers(self) -> t.Dict[t.Type, t.Type]:
162162 def is_ready (self ) -> bool :
163163 raise Exception (f"{ self .module } is not ready" )
164164
165- # @property
166- # def has_factory_function(self) -> bool:
167- # if self.factory is not None:
168- # # if we have a factory function, we need to check if the services to inject is just config
169- # # if so, then we can go ahead and have the configuration executed since at this level,
170- # # the config service is available to be injected.
171- # inject_size = len(self.inject)
172- # if inject_size == 0:
173- # return False
174- #
175- # if inject_size == 1 and self.inject[0] == Config:
176- # return False
177- # return True
178-
179- def get_module_ref (
180- self , config : "Config" , container : Container
181- ) -> t .Union ["ModuleRefBase" , "ModuleSetup" ]:
182- # if self.has_factory_function or self.ref_type == MODULE_REF_TYPES.APP_DEPENDENT:
183- # return self
184-
165+ def get_module_ref (self , config : "Config" , container : Container ) -> ModuleRefBase :
185166 if self .factory is not None :
186- ref = self .configure_with_factory (config , container )
167+ ref = self ._configure_with_factory (config , container )
187168 else :
188169 ref = create_module_ref_factor (
189170 self .module , config , container , ** self .init_kwargs
190171 )
191172
173+ assert isinstance (
174+ ref , ModuleRefBase
175+ ), f"{ ref .module } is not properly configured."
176+
192177 ref .initiate_module_build ()
193178 return ref
194179
195- def configure_with_factory (
180+ def _configure_with_factory (
196181 self , config : "Config" , container : Container
197182 ) -> "ModuleRefBase" :
183+ if self .ref_type == MODULE_REF_TYPES .APP_DEPENDENT :
184+ app = fail_silently (container .injector .get , interface = "App" )
185+ assert app , "Application is not ready"
186+
198187 services = self ._get_services (container .injector )
199188 init_kwargs = dict (self .init_kwargs )
200189
@@ -226,32 +215,12 @@ def _get_services(self, injector: EllarInjector) -> t.List:
226215 res .append (injector .get (service ))
227216 return res
228217
229- def build (
230- self ,
231- injector : EllarInjector ,
232- config : "Config" ,
233- ) -> "ModuleRefBase" :
234- # routes = []
235-
236- if self .ref_type == MODULE_REF_TYPES .APP_DEPENDENT :
237- app = fail_silently (injector .get , interface = "App" )
238- assert app , "Application is not ready"
239-
240- ref = self .get_module_ref (container = injector .container , config = config )
241- assert isinstance (
242- ref , ModuleRefBase
243- ), f"{ ref .module } is not properly configured."
244-
245- # ref.initiate_module_build()
246- # ref.build_modules(ref_type)
247- return ref
248-
249218 def build_and_get_routes (
250219 self ,
251220 injector : EllarInjector ,
252221 config : "Config" ,
253222 ) -> t .List [BaseRoute ]:
254- ref = self .build ( injector , config )
223+ ref = self .get_module_ref ( config , injector . container )
255224 ref .build_dependencies ()
256225
257226 return ref .get_routes ()
@@ -319,7 +288,7 @@ def get_module_dependency_by_type(
319288 )
320289 except Exception as ex :
321290 raise ImproperConfiguration (
322- f' Unable to import " { self .module } " registered in " { parent_module_ref .module } "'
291+ f" Unable to import ' { self .module } ' registered in ' { parent_module_ref .module } '"
323292 ) from ex
324293 else :
325294 module_cls = t .cast (t .Type ["ModuleBase" ], self .module )
@@ -328,8 +297,9 @@ def get_module_dependency_by_type(
328297
329298 if not node :
330299 raise ImproperConfiguration (
331- f"ForwardRefModule module='{ self .module_name } ' "
332- f"defined in { parent_module_ref .module } could not be found."
300+ f"ForwardRefModule module='{ self .module } ' "
301+ f"defined in { parent_module_ref .module } could not be found.\n "
302+ f"Please kindly ensure a { self .module } is decorated with @Module() is registered"
333303 )
334304
335305 return node .value .module
0 commit comments