GitXplorerGitXplorer
s

SkyResolver

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
3fc7fa616611d2b77eafef19c38765bc1f1fa25b

Explicitly check for the `.circularDependency` error.

ssoberman committed 2 years ago
Unverified
c1b140daaf3e839692d6a859c2ddb10b2480f5f8

Readme editing.

ssoberman committed 2 years ago
Unverified
c006c8099808b900fab009e13ca3c791572d9053

Update readme formatting.

ssoberman committed 2 years ago
Unverified
2944c5607797f620f6e5dc4a86af246bfa4e46eb

Update README.md file with some little documentation.

ssoberman committed 2 years ago
Unverified
9a41abac28a827fbb96fb34e6a58813c2830568d

Change names of the files and add README.md file

ssoberman committed 2 years ago
Unverified
a6edb426543d893a26cc2f7dd578f563c13a4ecf

Fix unit tests after object rename.

ssoberman committed 2 years ago

README

The README file for this repository.

SkyResolver

A lightweight dependency resolution library.

Dependency registration

To register your dependencies, use the following command:

SkyContainer.shared.register { A() as TestSubject }

Be aware that subsequent registration of the same type would lead to an error as a return value. If you wish to overwrite already registered types use the override parameter on the register method:

SkyContainer.shared.register(override: true) {
    B() as TestSubject
}

register method returns a Result<Void, SkyRegistrationError>, which you can check for the failure of the particular type registration, if any.

Dependency resolution

Resolving dependencies is similar to registration:

let classA: A = try! SkyContainer.shared.resolve()

SkyContainer is going to automatically resolve the correct type and initialize the class.

It also works with nested dependencies, where a class initializer depends on another class, like this:

SkyContainer.shared.register { A() as TestSubject }
SkyContainer.shared.register { B(testSubject: try! SkyContainer.shared.resolve()) }

let classB: B = try! SkyContainer.shared.resolve()

resolve() might throw a possible error in case some conditions have not been met. Check the error's failureReason and recoverySuggestion for help.

Circular dependency resolution

SkyResolver does not support circular initializer dependency resolution. Upon having

SkyContainer.shared.register { Egg(chicken: try! SkyContainer.shared.resolve()) }
SkyContainer.shared.register { Chicken(egg: try! SkyContainer.shared.resolve()) }

expect the resolver to throw an error. Try structuring your dependencies with another pattern.