Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Minimal dependency injection container for ruby.
Tested on the following Rubies: MRI 2.2.1, 2.0.0, 1.9.3
Add this line to your application's Gemfile:
gem 'ioc'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ioc
This example illustrates how to register a service/component with the container by passing a block to the register method.
require "ioc"
class AccountRepository
def initialize(database, logger)
@database = database
@logger = logger
end
# ... some store & finder methods here
end
class UserRepository
def initialize(database, logger)
@database = database
@logger = logger
end
# ... some store & finder methods here
end
class CreateAccountService
def initialize(account_repository, user_repository, logger)
@account_repository = account_repository
@user_repository = user_repository
@logger = logger
end
def call(req, res)
# ... create account code
end
end
# Register Services
container = IOC::Container.new
container.register(:create_account_service) do |c|
CreateAccountService.new(c.account_repository, c.user_repository, c.logger)
end
container.register(:user_repository) do |c|
UserRepository.new(c.database, c.logger)
end
container.register(:account_repository) do |c|
AccountRepository.new(c.database, c.logger)
end
container.register(:logger){|c| Logger.new}
container.register(:database){|c| DB}
# Resolve Service
container.resolve(:create_account_service).call(req, res)
# Release the object graph for garbage collection
container.release
Rather than assigning each service's dependencies manually like in the example above, we can allow the container to build and inject each service's dependencies automatically.
# Register Services
container = IOC::Container.new
container.register(:create_account_service, CreateAccountService)
container.register(:user_repository, UserRepository)
container.register(:account_repository, AccountRepository)
container.register(:logger){|c| Logger.new}
container.register(:database){|c| DB}
# Resolve Service
container.resolve(:create_account_service).call(req, res)
# Release the object graph for garbage collection
container.release
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that ioc demonstrated a not healthy version release cadence and project activity because the last version was released 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.