Dry-system: auto import with component identifiers

Hey,
I’m studying the guides of dry-system and I am very excited about the progress regarding Hanami 2.0. Thank you for this.

I have a question about the component identifiers section (dry-rb - dry-system master - Auto-Import) regarding the persistence boot example, where the persistence dep is started for every repo. Does that mean the db connects on every repo instantiation? If yes, is it possible to boot the persistence dep just once, using this auto import feature?

Thanks

Bootable components are started only once, because everything that happens within each lifecycle blocks is executed just once. Lazy-loading is based on the identifier, which can include anything that’s nested under it. For example, if you have db.connection and you have include Deps['db.connection'] then db will be started automatically and it’s assumed that this should result in db.connection becoming available.

1 Like

@solnic Many thanks for your answer. This is crystal-clear!

I’ve figured it out myself with the help of this clear code (dry-system/container.rb at d01c78cf68c05a1ab71356b739f9a35bae52e6a1 · dry-rb/dry-system · GitHub). But you got ahead of me :wink:

1 Like

@wuarmin ah fantastic :slightly_smiling_face: Tim has been making the code oh-so-much-better recently!

1 Like