Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frankois944/quickservicelocator
A simple service locator for Swift
https://github.com/frankois944/quickservicelocator
apple servicelocator swift
Last synced: 15 days ago
JSON representation
A simple service locator for Swift
- Host: GitHub
- URL: https://github.com/frankois944/quickservicelocator
- Owner: frankois944
- License: apache-2.0
- Created: 2024-08-18T11:00:01.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-19T13:03:24.000Z (4 months ago)
- Last Synced: 2024-08-19T15:08:45.007Z (4 months ago)
- Topics: apple, servicelocator, swift
- Language: Swift
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QuickServiceLocator
A quick service locator for the Apple platform, made to be the easiest and simplest way to use
## Installation
Swift package manager
`https://github.com/frankois944/QuickServiceLocator.git`
## The quick way
### Register/resolve from a property wrapper
```swift
// registering and resolving
@QuickSL(register: DummyService())
var dummyService: DummyServiceProtocol
// even
@QuickSL(register: DummyService())
var dummyTest2: DummyService
// only resolving
@QuickSL var dummyService: DummyServiceProtocol
```### or
```swift
// registering
QuickServiceLocator.register(DummyServiceProtocol.self, DummyService())
// resolving
let instance: DummyServiceProtocol = QuickServiceLocator.locate()
```### Unregister the service
```swift
QuickServiceLocator.unregister(DummyServiceProtocol.self)
```### Check the presence of the service
```swift
QuickServiceLocator.isRegister(DummyServiceProtocol.self)
```## Behavior
By default, every services are registered in a `lazySharedInstance` mode, it means the `DummyService` will be created during the resolving step as a singleton.
This behavior can be set during the registering step.
```swift
@QuickSL(register: DummyService(), mode: .newInstance)
var dummyService: DummyServiceProtocol
// or
QuickServiceLocator.register(DummyServiceProtocol.self,
mode: .newInstance,
DummyService())
```