kdisneur/dependency_injection-ruby

Remove activesupport dependency?

Opened this issue · 2 comments

I feel that a dependency on activesupport may be unnecessary or overkill for the use case in dependency_injection/definition.rb.

Downsides:

  • Relatively large library, though only a small portion is being required in.
  • Monkey patches string, may conflict with application or other libraries (though probably not).

Instead, would one of the following work?:

  • Required helper methods (underscore and constantize) could be defined in the dependency_injection gem, or
  • An inflection-only gem could be used instead, such as https://github.com/mbj/inflecto, which is lighter weight, and does not monkey patch string. Usage would be along the lines of Inflecto.constantize(klass_name). Or
  • Gem could check for the existence of available constantize / underscore methods and throw an exception if they could not be found, or
  • Underscore and constantize strategies could be configurable and passed to the container or service as appropriate by the application in some way.

What are your thoughts?

Hi @Billiam

Thank a lot for the issue. You are right, this dependency is really unnecessary and could be a problem

Because some people have already developed and fixed #underscore and #constantize methods, so I prefer use an already existing implementation instead of (re)implement or copy/paste an existing implementation.

I'm not sure the idea to delegate #underscore and #constantize to the user is really useful. Do you have real life use cases ?

I didn't know the inflecto gem but that seems to be a really good replacement. 👍

PS : Sorry I'm in holidays, I can't answer or fix quickly for the moment.

I'm not sure the idea to delegate #underscore and #constantize to the user is really useful. Do you have real life use cases ?

The only use case I could see for this would be to accommodate both users who are using activesupport already, and those who are not. Those using activesupport might prefer to use the activesupport implementation over another gem dependency, while those not using activesupport would prefer a smaller/less intrusive dependency.

It would certainly complicate the interface, though, so a small underscore/constantize library might still be preferable.