denali-js / core

An opinionated, ORM agnostic framework for building robust JSON APIs in Node
http://denalijs.org
Apache License 2.0
73 stars 14 forks source link

Apply container as injection rather than constructor arg #408

Closed davewasmer closed 6 years ago

davewasmer commented 6 years ago

Right now, the container's buildFactory method constructs an instance by passing the container as the constructor arg. This is how the newly created instance is expected to get it's container reference. This assumes that the class inherits from DenaliObject, which does this assignment in the constructor.

We should revert this to the old approach of the container being a default injection. This fixes the fact that right now, pre-instantiated singletons don't get a container reference: https://github.com/denali-js/denali/blob/master/lib/metal/container.ts#L253.

It also allows users to containerize any class, not just subclasses of DenaliObject. Since DenaliObject isn't really required for container interop, there's no reason to force it. We should then drop DenaliObject's constructor since that assignment is no longer needed.

davewasmer commented 6 years ago

Obsolete after bundler refactor