RomainEndelin / dry_auto_inject_active_record_incompatibility

Minimal Working Example - Illustrating incompatibility between ActiveRecord and Dry-Auto_inject

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dry Auto-Inject and ActiveRecord compatibility issue

Important files:

  • app/initializers/dependency_manager.rb
module DependencyManager
  Container = Dry::Container.new

  Container.register(:hello) { 'world' }

  Import = Dry::AutoInject(Container)
end
  • app/models/user.rb
class User < ApplicationRecord
  include DependencyManager::Import[:hello]
end

How to reproduce:

irb(main):001:0> User.new.hello
=> "world"
irb(main):002:0> User.first.hello
  User Load (0.2ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ?  [["LIMIT", 1]]
=> nil

About

Minimal Working Example - Illustrating incompatibility between ActiveRecord and Dry-Auto_inject


Languages

Language:Ruby 79.3%Language:HTML 15.6%Language:JavaScript 3.2%Language:CSS 1.9%