
Security News
CISA’s 2025 SBOM Guidance Adds Hashes, Licenses, Tool Metadata, and Context
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
SmartIoC is a smart and really simple IoC container for Ruby applications.
gem install smart_ioc
Please install specific smart_ioc version, depending on Ruby version.
Ruby Version | SmartIoC Version |
---|---|
< 3.0 | 0.3.2 |
>= 3.0 | 0.4.0 |
Set package name and source package folder with beans. SmartIoC will parse source files and detect bean definitions automatically for you.
SmartIoC.find_package_beans(:PACKAGE_NAME, File.dirname(__FILE__))
If you have several packages in your application (like if you are using rdm package manager) you can run SmartIoC.find_package_beans several time pointing it to the source folder and setting a different package name.
class UsersRepository
include SmartIoC::Iocify
bean :users_repository
end
class Test::UsersRepository
include SmartIoC::Iocify
bean :users_repository, context: :test
end
:default
context with any other in the following way:SmartIoC::Container.get_instance.set_extra_context_for_package(:YOUR_PACKAGE_NAME, :test)
This allows to create test implementations for any package dependency.
In order to get a bean use SmartIoC::Container.get_bean(:BEAN_NAME, package: :PACKAGE_NAME, context: :default)
. package
and context
are optional arguments.
If you use the same bean name for different dependencies in different packages you will need to specify the package directly. You can do that by using from
parameter:
class UsersCreator
include SmartIoC::Iocify
bean :users_creator
inject :users_repository, from: :repositories
def create
user = User.new
users_repository.put(user)
end
end
ref
parameter.
In the following example we are injecting the :users_repository
dependency but refer to it as repo
locally.class UsersCreator
include SmartIoC::Iocify
bean :users_creator
inject :users_repository, ref: :repo, from: :repositories
def create
user = User.new
repo.put(user)
end
end
class RepositoryFactory
include SmartIoC::Iocify
bean :users_creator, factory_method: :get_bean
inject :config
inject :users_repository
inject :admins_repository
def get_bean
if config.admin_access?
admins_repository
else
users_repository
end
end
def create
user = User.new
repo.put(user)
end
end
instance: false
:class UsersCreator
include SmartIoC::Iocify
bean :users_creator, instance: false
inject :users_repository
end
FAQs
Unknown package
We found that smart_ioc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.