radbas-container
Version, currently 0.3.12 versions
- 0.3.1latestJan 23, 2025
- 0.3.0not indexedJan 23, 2025
github.com/radbas/container.cr
DI container for Crystal.
0 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
radbas-container:
github: radbas/container.cr
version: ~> 0.3.1Then run:
shards installshard.yml
- Crystal
1.8.2- License
- MIT
- Author
- Johannes Rabausch
Dependencies
Development Dependencies
- ameba*github: crystal-ameba/amebadev
README
Container.cr
Simple and small DI Container.
Installation
-
Add the dependency to your
shard.yml:dependencies: radbas-container: github: radbas/container.cr -
Run
shards install
Usage
Extend the abstract Radbas::Container class and register/autowire your services:
require "radbas-container"
class MyService
def initialize(
@dep: DependencyService
); end
end
class MyContainer < Radbas::Container
# autowire does let you register namespaces
# from which classes get resolved automatically
autowire(MyApp, CustomNamespace)
# softmap registers all subclasses of a given abstract class
softmap(MyAbstractClass, params: {}, public: false)
# register a single service
register(DependencyService)
# a factory can be used for setup
register(MyService, factory: ->{
# you can call get inside a factory to resolve dependencies
MyService.new(get(DependencyService))
}, public: true)
# params can be used to configure constructor params
register(MyService, params: { dep: get(DependencyService) })
end
By default, all registered services are private. Normally you would register a single class as a public entrypoint and call get on the container:
class MyContainer < Radbas::Container
register(MyApplication, public: true)
end
container = MyContainer.new
app = container.get(MyApplication)
app.run
# ...
Contributing
- Fork it (https://github.com/radbas/container/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Johannes Rabausch - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.3.1- Tagged
- Jan 23, 2025
- Commit
cc93023ad722- Crystal
1.8.2- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/radbas/container.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 17, 2026
- Synced
- Aug 17, 2026
- Versions
- 2