dry-rb / dry-rails

The official dry-rb railtie

Home Page:https://dry-rb.org/gems/dry-rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Container constant to be configurable

jandudulski opened this issue · comments

In my current application, there is an ActiveRecord model named Container. This is unfortunately in conflict with dry-rails while booting and failed with undefined method features for Container since

app_namespace.const_get(:Container)
loads model class.

Examples

Dry::Rails.container do
  config.container_constant = 'MyContainer'
end

Sounds like a good feature to have, in line with #18

@solnic I can work on this one! 😃

@diegotoral OK grab it then :)

Hey @solnic, I am having problems to make the container name customizable. I was able to make the container created with a custom name but I don't know exactly how to access the container name later on other parts of the code.

For example, in lib/dry/rails/rails/railtie.rb file some methods reference :Container like in the container method and reloading?. How can I access the custom container name from that point in code, since the configuration is loaded for each container instance?

@diegotoral for consistency's sake, this should be a new config setting, defined in the container class. Then in places where :Container is referenced, you need to change it to use the config. This would have to be stored at the Railtie instance level too, otherwise you'll have a chicken-egg problem. So ie app_namespace.const_get(:Container, false) should become something like app_namespace.const_get(container_const_name, false) where container_const_name is a reader defined in the Railtie class.

In the Railtie#finalize! you could have something like self.container_const_name = container.config.const_name (so an attr reader).

That makes sense! I'll give it a try. Thanks @solnic