Thanks a lot David, you have provided me with the keywords I needed to move on with this problem
On a side-note - In general it seems that my approach of using singletons to orchestrate my application is not recommended (I understand the problems with singletons!) but there seems to be a dearth of advice on the topic of orchestrating your rails services at run-time so Ill push ahead
My original problem is that I have a bunch of services that may or may not connect to each other (various services can be enabled/disabled in an in-database configuration)
For future reference, I have for now solved the problem by:
# config/initializers/my_application_config.rb
module MyApplication
class Application < Rails::Application
# was previously doing config.after_initialize, but to_prepare seems to be called every time a reload happens
config.to_prepare do
ServiceOrchestrator.prepare
end
end
end
# app/services/service_orchestrator.rb
class ServiceOrchestrator
def self.prepare
# clear because this seems to be invoked twice every reload for some reason
MyService1.clear_config
MyService2.clear_config
MyService2.configure_with_other_service(MyService1.instance)
end
end