claro-lang icon indicating copy to clipboard operation
claro-lang copied to clipboard

Implement Some Sort of `inject` Semantics

Open JasonSteving99 opened this issue 2 years ago • 0 comments

Currently Claro's dep injection only works by somewhat abusing scoping rules to allow injected procedures to be called directly from within a using-block because the procedure was defined in the same file. However, looking forward to the future when Claro supports multiple files, Claro's dep injection would actually not be extensible to calling procedures defined in other files even if bindings are provided for them in a module, because their names will not be present in scope. This applies to non-procedure bindings as well. Claro should support an inject keyword to direct Claro to provide the bound instance indicated by the modules in use.

Maybe can look something like:

using (FooModule) {
  # The type annotation may be omitted from the left side.
  var myVar = inject foo:FooType;
}

This would also allow Claro to be lazy and only initialize the bindings that are explicitly requested for injection. This would be a very useful optimization to reduce the cost of using a Module, so that the performance penalty of using a Module doesn't silently grow as bindings are added to the Module unless more bindings from the module are actually injected (directly or indirectly).

JasonSteving99 avatar May 03 '22 00:05 JasonSteving99