# DI not available in Repos

**URL:** <https://discourse.hanakai.org/t/di-not-available-in-repos/1224>\
**Category:** issues\
**Created:** [June 3, 2025, 11:24am UTC](https://discourse.hanakai.org/t/di-not-available-in-repos/1224 "2025-06-03T11:24:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wuarmin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/wuarmin/32/548_2.png) [@wuarmin](https://discourse.hanakai.org/u/wuarmin)\
**Post date:** [June 3, 2025, 11:24am UTC](https://discourse.hanakai.org/t/di-not-available-in-repos/1224/1 "2025-06-03T11:24:54Z")

</div>

Hey 👋

the great dependency injection feature is not available in Repos out of the box. Following does not work:

```ruby

module Documents
  module Repos
    class DocumentRepo < Documents::DB::Repo
      include Deps["utils.now"]

      def create(hash)
         puts now.inspect # now: nil
      end
    end
  end
end

```

@timriley Should we fix this? The only workaround, if found, is to use the dependencies via the container:

```ruby
def create(hash)
  Documents::Slice["utils.now"]
end

```

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/timriley/32/621_2.png) [@timriley](https://discourse.hanakai.org/u/timriley)\
**Post date:** [June 3, 2025, 11:26am UTC](https://discourse.hanakai.org/t/di-not-available-in-repos/1224/2 "2025-06-03T11:26:18Z")

</div>

Repos should absolutely be able to work with DI, so I definitely consider this a bug! Probably an issue with the constructor methods we’ve implemented on Hanami::DB::Repo.

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/timriley/32/621_2.png) [@timriley](https://discourse.hanakai.org/u/timriley)\
**Post date:** [June 3, 2025, 11:27am UTC](https://discourse.hanakai.org/t/di-not-available-in-repos/1224/3 "2025-06-03T11:27:44Z")

</div>

Ah, here’s an issue I already created: [Deps included within repos are not made available · Issue #1483 · hanami/hanami · GitHub](https://github.com/hanami/hanami/issues/1483)

This has a hint about how to fix it. It should be a simple one.

---

<div class="post-metadata">

**Author:** ![wuarmin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/wuarmin/32/548_2.png) [@wuarmin](https://discourse.hanakai.org/u/wuarmin)\
**Post date:** [June 3, 2025, 11:40am UTC](https://discourse.hanakai.org/t/di-not-available-in-repos/1224/4 "2025-06-03T11:40:34Z")

</div>

Oh, great.  
I can confirm. Changing `define_new` to

```ruby
def define_new
  resolve_rom = method(:resolve_rom)

  define_method(:new) do |**kwargs|
    super(container: kwargs.fetch(:container) { resolve_rom.() }, **kwargs.except(:container))
  end
end

```

solves the issue.

---

<div class="post-metadata">

**Author:** ![wuarmin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/wuarmin/32/548_2.png) [@wuarmin](https://discourse.hanakai.org/u/wuarmin)\
**Post date:** [June 4, 2025, 8:14am UTC](https://discourse.hanakai.org/t/di-not-available-in-repos/1224/5 "2025-06-04T08:14:41Z")

</div>

@timriley Do you want me to prepare a PR? Or do you have any further thoughts here?

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/timriley/32/621_2.png) [@timriley](https://discourse.hanakai.org/u/timriley)\
**Post date:** [June 4, 2025, 8:20am UTC](https://discourse.hanakai.org/t/di-not-available-in-repos/1224/6 "2025-06-04T08:20:36Z")

</div>

If you could prepare a PR, that would be amazing, thank you!

Having a simple test to verify this behavior would be good too.
