ivandotv / pumpit

PumpIt is a small (<2KB) dependency injection container without the decorators, suitable for the browser.
MIT License
25 stars 2 forks source link

validate dependencies #80

Closed ivandotv closed 3 months ago

ivandotv commented 3 months ago

This PR implements two new methods on the pumpit class validate and validateSafe. These methods check if dependency keys that are used for injection are present in the container. It will not instantiate any classes or run factory functions.

given this example:

    class TestA {
      constructor() {
        throw new Error("Class should not be instantiated")
      }
    }

    class TestB {
      static inject = [TestA]

      constructor(public a: TestA) {
        throw new Error("Class should not be instantiated")
      }
    }

    pumpIt.bindClass(TestA, TestA).bindClass(TestB, TestB)

  pumpIt.validate()

It will check if class TestA is registered with the container, because class TestB has it as a dependency.