Closed Supereg closed 11 months ago
Merging #72 (03e84f3) into main (162c932) will decrease coverage by
0.61%
. The diff coverage is92.24%
.
@PSchmiedmayer I addresses all the feedback. Wanted to re-request your review just to make sure 🚀
Thank you! I will have some time in the late afternoon to re-review the PR. If it is fine with you I can fix smaller issues that I might find myself and then merge the PR after that? Maybe I don't even have some feedback and could also directly merge it 👍
Component communication
:recycle: Current situation & Problem
Currently, there is no easy way for a
Component
to access features or information provided by anotherComponent
.I illustrate the usefulness using a real-world example we are currently facing with
SpeziAccount
. AAccountConfiguration
is used by the user to configure theSpeziAccount
subsystem which in turn does everything necessary to set up the requestAccountServices
to be accessible by the App's views. While one may just provide off-the-shelveAccountServices
using the initializer of the configuration object, there might be instances where an third-partyAccountService
is controlled and configured by aComponent
. In such cases it should be possible for the user to place theComponent
in theConfiguration
closure as usual with theAccountConfiguration
queryingAccountService
instances from all configuredComponents
.:bulb: Proposed solution
In this PR we introduce the
@Provide
and@Collect
property wrappers that can be used to pass around information or functionality betweenComponents
. The@Provide
property wrapper is used to supply a singleValue
(orValue?
if it e.g. only supplies it conditionally) or multiple values ([Value]
) to be collected by otherComponents
. AnotherComponent
can then use@Collect
with a type of[Value]
to collect all the provided items.Here is a short code example:
While the example shows the usage of a reference type, this feature can also easily be used with value types (though then, no modifications post the collection phase are possible).
:gear: Release Notes
@Provide
and@Collect
property wrappers for easy to use inter-Component
communicationSharedRepository
pattern to easily implement typed collections.:heavy_plus_sign: Additional Information
Shared Repository Pattern
This PR additionally introduces the concept of the
SharedRepository
software pattern based on Buschmann et al. (Pattern-Oriented Software Architecture: A Pattern Language for Distributed Computing). We provide a variety of different types ofKnowledgeSource
s which are stored inSharedRepository
implementations. Each shared repository defines aSharedRepositoryAnchor
it expects from an implementingKnowledgeSource
.This instantiation of the shared repository pattern replaces the previous
TypedCollection
implementation. Further, it will be of equal use forSpeziAccount
(storing arbitrary account details). The current draft PR introduces a similar concept. This PR helps to generalize this software pattern and increase code reuse across the framework ecosystem.Alternative Considered
As with the previous
TypeCollection
implementation, aSharedRepository
allows for acollect(allOf:)
query which is, e.g., internally used to query allComponents
that conform toLifecycleHandler
. Instead of the proposed system, we could have created a property wrapper that just collects all components that conform to a given protocol. I decided against this approach considering the following points:@Dependency
system (or we would need to consider '@Collect` declarations in the execution order).Component
by default allowing for arbitrary information (value types, reference types, information, functionality).Related PRs
Testing
Test cases were adapted but still need to be extended for newly added code.
Reviewer Nudging
There are two separate parts to the PR:
SharedRepository
data structureCollect
andProvide
property wrappers. You may look at the tests to easily glance what their use case is.Code of Conduct & Contributing Guidelines
By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines: