@travetto/di 3.0.3 → 3.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/registry.ts +12 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/di",
3
- "version": "3.0.3",
3
+ "version": "3.1.0-rc.1",
4
4
  "description": "Dependency registration/management and injection support.",
5
5
  "keywords": [
6
6
  "ast-transformations",
@@ -27,10 +27,10 @@
27
27
  "directory": "module/di"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/registry": "^3.0.3"
30
+ "@travetto/registry": "^3.1.0-rc.1"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/transformer": "^3.0.3"
33
+ "@travetto/transformer": "^3.1.0-rc.2"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@travetto/transformer": {
package/src/registry.ts CHANGED
@@ -561,6 +561,18 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
561
561
  // Compute fields to be auto-wired
562
562
  return await this.resolveFieldDependencies(this.get(cls), o);
563
563
  }
564
+
565
+ /**
566
+ * Execute the run method of a given class
567
+ */
568
+ async runInstance<T extends { run(..._args: unknown[]): unknown }>(
569
+ cls: Class<T>, ...args: Parameters<T['run']>
570
+ ): Promise<Awaited<ReturnType<T['run']>>> {
571
+ await RootRegistry.init();
572
+ const inst = await this.getInstance<T>(cls);
573
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
574
+ return inst.run(...args) as Awaited<ReturnType<T['run']>>;
575
+ }
564
576
  }
565
577
 
566
578
  export const DependencyRegistry = new $DependencyRegistry();