https://github.com/peterprokop/bogracz
Bogracz is dependency injection manager with some desirable properties like thread safety and support for type-safe arguments
https://github.com/peterprokop/bogracz
Last synced: about 2 months ago
JSON representation
Bogracz is dependency injection manager with some desirable properties like thread safety and support for type-safe arguments
- Host: GitHub
- URL: https://github.com/peterprokop/bogracz
- Owner: peterprokop
- Created: 2019-11-12T13:37:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-25T15:21:46.000Z (over 5 years ago)
- Last Synced: 2025-03-24T01:35:26.648Z (2 months ago)
- Language: Swift
- Size: 15.6 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Bogracz
======# Intro
Bogracz is really small and nifty dependency injection (DI) framework.
Compared to Swinject it has some nice properties like thread safety
and type-safe arguments.# Installation
## Carthage
- `touch Cartfile`
- `nano Cartfile`
- Put `github "peterprokop/Bogracz" == 1.0.0` into Cartfile
- Save it: `ctrl-x`, `y`, `enter`
- Run `carthage update`
- Add `Bogracz.framework` to your carthage [copy-frameworks phase](https://github.com/Carthage/Carthage#quick-start)
- Add `import Bogracz` in files where you plan to use it# Usage
Do `import Bogracz`
Then create a container: `let container = DependencyContainer()`Then you can add dependencies as static (dependency will be created once and you are responsible for it):
```swift
let myService: MyServiceProviding = MyService()
container.add(MyServiceProviding.self, instance: myService)
```... dynamic (dependency will be created every time you get it):
```swift
container.add(MyServiceProviding.self, block: { _ in
return MyService()
})
```... or dynamic with config:
```swift
let config = MyServiceConfig(answer: 42)container.add(MyServiceProviding.self, block: { (r, config: MyServiceConfig) in
return MyService(config: config)
})
```Then you can get your dependency in following way:
For dependencies without config -
```swift
let myService = container.get(MyServiceProviding.self)
```For configurable dependencies -
```swift
let myService = container.get(MyServiceProviding.self, config: config)
```# Dependency Injection
Some useful articles about this topic:
- https://martinfowler.com/articles/injection.html
- https://www.martinfowler.com/articles/dipInTheWild.html
- https://www.martinfowler.com/bliki/InversionOfControl.html