Skip to content

`GlobalEnvironment` and dependency aliases

Compare
Choose a tag to compare
@tgrapperon tgrapperon released this 27 Dec 21:37
· 19 commits to main since this release
581b34f

GlobalEnvironment

The library is now split into two mutually exclusive modules:

  • ComposableEnvironment, when you need to update a dependency value mid-chain
  • GlobalEnvironment, when your dependencies are shared among all your environments with the same values.

Requirements for both modules are different. GlobalEnvironment is the simplest one to implement and should fit most cases.
If your project doesn't require mid-chain overrides of dependencies, we recommend adopting GlobalEnvironment, which can be as simple as conforming your environment type to a marker protocol.

The API is kept as similar as possible, so you can migrate a project from one to another without having to change much code.

Dependency aliases

You can now identify dependencies defined with different names in different domains. For example, if you defined main for the main queue in one domain and mainQueue in another, you can alias the former with the latter using:

environment.aliasing(\.main, to: \.mainQueue)

Both properties will then return the same dependency value.
Aliasing can also be defined when using the @DerivedEnvironment property wrapper.

ComposableDependencies

The ComposableDependencies type, where you install your computed properties to access your dependencies, has been renamed Dependencies. An Xcode "fix-it" is provided.