I would like to figure how to inject a dependency into a
Dry::Struct descendant class.
Here’s the code:
require 'dry-struct' module Types include Dry::Types.module end class User < Dry::Struct attribute :name, Types::Strict::String attribute :age, Types::Strict::Int.constrained(gteq: 18) end
Now I want to inject a logger in the simplest way possible. I would not like to use
dry-container partly because I didn’t grasp it yet, and partly because I still adhere to ‘you don’t need a dependency injection framework for dependency injection’ opinion. I’d like to keep it simple.
dry-struct, I’d go with:
class User def initialize logger @logger = logger end end User.new(Logger.new(STDOUT))
But sure enough, this approach doesn’t work for