Hey,
I have a global orm-provider
# config/providers/orm.rb
Hanami.app.register_provider(:orm) do
prepare do
require "sequel"
end
start do
register("orm.database", Sequel.connect(target["settings"].database_url))
end
end
Furthermore I have a slice with a repo and I want to include the orm.database
module MySlice
module Repositories
class UsersRepo
include Deps["orm.database"]
end
end
end
This fails with a
Dry::Core::Container::KeyError:
key not found: "orm.database"
It is clear to me that this is the expected behavior, because slices have their own container, but what is the right way to make the “orm.database” key available to the slice?
I tried something like this:
module MySlice
class Slice < Hanami::Slice
import keys: ["orm.database"] from: :main # does not work
MySlice::Slice.register("orm.database", Hanami.app["orm.database"]) # seems to work, but is this the right way
end
end
The second approach seems to work, but is this the right way?
And what’s the reason do not make global keys available to all slices?
Thanks