Skip to content

Feature: Return dependency as const when needed #110

@abeimler

Description

@abeimler

Is your feature request related to a problem? Please describe.
I'm trying to make a (const) getter with return m_container.service<di::RegistryService>(), but I get an Error: error: no matching function for call to ‘kgr::container::service<di::RegistryService>() const’

I also try something like this: return m_container.service<const di::RegistryService>()

Describe the solution you'd like
make a kgr::container::service() const method

Describe alternatives you've considered
Right now I'm trying this as a workaround: return std::as_const(m_container.service<di::RegistryService>())

Additional context

  [[nodiscard]] engine::Registry& registry() {
    return m_container.service<di::RegistryService>();
  }
  [[nodiscard]] const engine::Registry& registry() const {
    return m_container.service<di::RegistryService>();
  }

  [[nodiscard]] float getFrameTime() const {
    if (registry().ctx().contains<const GameContext>()) { // registry() needs to be const
      const auto& game_ctx = registry().ctx().get<const GameContext>();
      // ... 
    }
    return 0;
  }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions