Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 1.4 KB

README.md

File metadata and controls

63 lines (43 loc) · 1.4 KB

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

// registering and resolving
@QuickSL(register: DummyService())
var dummyService: DummyServiceProtocol
// even
@QuickSL(register: DummyService())
var dummyTest2: DummyService
// only resolving
@QuickSL var dummyService: DummyServiceProtocol

or

// registering
QuickServiceLocator.register(DummyServiceProtocol.self, DummyService())
// resolving
let instance: DummyServiceProtocol = QuickServiceLocator.locate()

Unregister the service

QuickServiceLocator.unregister(DummyServiceProtocol.self)

Check the presence of the service

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.

@QuickSL(register: DummyService(), mode: .newInstance)
var dummyService: DummyServiceProtocol
// or
QuickServiceLocator.register(DummyServiceProtocol.self,
                                mode: .newInstance,
                                DummyService())