{"id":25540983,"url":"https://github.com/fdutey/shirinji-rails","last_synced_at":"2025-04-11T16:50:31.828Z","repository":{"id":29717591,"uuid":"122579181","full_name":"fdutey/shirinji-rails","owner":"fdutey","description":"Shirinji integration to rails","archived":false,"fork":false,"pushed_at":"2022-12-14T07:23:57.000Z","size":23,"stargazers_count":1,"open_issues_count":9,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T12:53:30.648Z","etag":null,"topics":["dependency-injection","inversion-of-control","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fdutey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-23T05:51:55.000Z","updated_at":"2019-08-23T04:10:19.000Z","dependencies_parsed_at":"2023-01-14T15:31:23.350Z","dependency_job_id":null,"html_url":"https://github.com/fdutey/shirinji-rails","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdutey%2Fshirinji-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdutey%2Fshirinji-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdutey%2Fshirinji-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdutey%2Fshirinji-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fdutey","download_url":"https://codeload.github.com/fdutey/shirinji-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994062,"owners_count":21030046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-injection","inversion-of-control","ruby","ruby-on-rails"],"created_at":"2025-02-20T06:22:34.548Z","updated_at":"2025-04-11T16:50:31.793Z","avatar_url":"https://github.com/fdutey.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shirinji-Rails\n\nIntegration of [Shirinji](https://github.com/fdutey/shirinji) in rails\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'shirinji-rails'\n```\n\nAnd then execute:\n\n    $ bundle\n\n## General usage\n\nAdd this file in `config/dependencies.rb`\n\n```ruby\nShirinji::Map.new do\n  # declare your dependencies here\nend\n```\n\nDependency resolver can be accessed through\n\n```ruby\nRails.application.config.shirinji.resolver\n```\n\nI suggest to use a helper to make your life easier. \n\n```ruby\n# lib/my_app.rb\n\nmodule MyApp\n  module_function\n  \n  def bean(name)\n    ::Rails.application.config.shirinji.resolver.resolve(name)\n  end\nend\n\n# moments later, in controllers / job / rake tasks\nservice = MyApp.bean(:user_sign_up_service)\nservice.call(user) \n```\n\n## Rails entities DSL\n\nSince controllers and jobs (and maybe other rails entities) are not under \nShirinji's control, they can not receive dependencies through their constructors.\n\nOne solution is to manually create a method for each dependency but it's painful \nand make the code harder to read. \n\nRails integration actually provides a simple DSL to express dependencies.\n\n```ruby\n# application_controller.rb\n\nclass ApplicationController \u003c ActionController::Base \n  include ShirinjiRails::ResolverBinding\nend\n\n# in any controller\n\nclass FooController \u003c ApplicationController\n  dependency :config\n  # Alias\n  dependency foo_create_service: :create_service\n  \n  def index\n    config #=\u003e `config` dependency\n    create_service # =\u003e `foo_create_service` dependency \n  end\nend\n\nclass FooJob \u003c ActiveJob::Base\n  include ShirinjiRails::ResolverBinding\n\n  dependency :config\n \n  def perform\n    config #=\u003e `config` dependency\n  end\nend\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/fdutey/shirinji-rails.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdutey%2Fshirinji-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffdutey%2Fshirinji-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdutey%2Fshirinji-rails/lists"}