-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restructure @Dependency
property and use BFS for DependencyManager
#112
Conversation
@Dependency
@Dependency
property and use BFS for DependencyManager
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #112 +/- ##
==========================================
+ Coverage 88.03% 90.33% +2.30%
==========================================
Files 47 47
Lines 1470 1602 +132
==========================================
+ Hits 1294 1447 +153
+ Misses 176 155 -21
Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the great addition @Supereg!
I am wondering if we should keep a simple "worry-free" approach with DefaultInitializable
for now but am happy to mark this as deprecated if there is good reason we want to remove it on the long run.
Sources/Spezi/Dependencies/Property/DependencyCollectionBuilder.swift
Outdated
Show resolved
Hide resolved
Sources/Spezi/Dependencies/Property/DependencyPropertyWrapper.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Restructure
@Dependency
property and use BFS for DependencyManager♻️ Current situation & Problem
The
Module
and dependency system is very powerful and useful infrastructure of the Spezi framework ecosystem allowing it to be modularized. There was immense thought put into it to generalize the concept of dependency declaration between modules. With recent PRs it has become even more powerful support a lot of different use cases like dynamism (e.g., like modeling Bluetooth devices as modules).However, it some scenarios the
@Dependency
property lacks the expressiveness as required in certain use cases. For example, it is currently always required to either specify a default value (either manually or throughDefaultInitializable
) or declare it as an optional dependency. Simply, declaring a required dependency that is assumed to be present, cannot be modeled. For example, a module A, might configure a module B and C, where B has a required dependency to C (as it knows it is always configured by A and therefore can safely assume that C is present). This is currently not possible with either a) having to unwrap a optional dependency all the time or b) declaring a dependency with a default value which might be not always be possible if there are initializer arguments required.Secondly, you currently cannot have a guarantee that a given module instance you provide to the
@Dependency
property wrapper is actually loaded as it is always used as a default argument and a module declared on the outside takes precedence.The changes of this PR are listed in the next section.
⚙️ Release Notes
This PR introduces several changes to the dependency system.
@Depenency(Example.self) var example
_example = Dependency(load: myInstance)
or using any array based initializers.@Dependency var example: Example?
you have to specify `@Dependency(Example.self) var example: Example?.@Dependency var example: Example
(forDefaultInitializable
), you will specify@Dependency(Example.self) var example
for a required dependency. The default value will automatically be created.Old initializers are marked deprecated and shall be removed in the next major version release.
📚 Documentation
This PR updates documentation to refer to the most recent versions of the
@Dependency
property wrapper.✅ Testing
New unit tests were added to cover new cases. We added some verification that deprecated initializers still work as expected.
📝 Code of Conduct & Contributing Guidelines
By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines: