Type compatibility pitfalls in TypeScript Dapper Extensions Reloaded: Version 3.1.2

good-injector: Version 0.2.0

Published on Sunday, February 25, 2018 12:00:00 PM UTC in Announcements & Tools

A new version of good-injector has been pushed to NPM. I've used the container in one of my private projects and decided to move forward with it, as it's working quite well and stays unobtrusively in the background - just as I like the tools I have to work with. The current release adds the following features:

  • Registering instances: This allows you to add objects to the container that you did not create yourself, i.e. because you received them from a third-party component or from another part of your application.
  • Registering a factory function: If creation of an object is more complex than just invoking the constructor (i.e. doing some initialization work), or if the lifetime logic is more complex than what the container could provide (transient/singleton), you can now use a factory function with basically any logic you want to plug in. See the unit tests for an example where every other call of a factory returns one of two possible instances - meaningless but demonstrates the possibilities quite well.
  • Registering a singleton factory: Similar to the factory function but is only called once (lazily), so you can have the same complex logic where required, but don't have to maintain the lifetime logic for the once created instance yourself.
  • Unregistering registrations: This opens up use cases where you temporarily add registrations to the container (typically an instance, or maybe a singleton) that you want to remove later. Example: you want to pass around some common data or features in a sub-system of your application, but want to remove it once the user moves on to a different sub-system, or once a particular workflow of your application has finished.

In addition to that, I've added some more checks to increase type safety and detect configuration errors at runtime also. Feel free to leave any feedback or suggestions.

Have fun! :)

Tags: Good-injector · TypeScript