-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow external ownership for Modules (#106)
# Allow external ownership for Modules ## ♻️ Current situation & Problem When loading modules dynamically using `loadModule(_:)`, Spezi always takes ownership of the Module. Spezi keeps a strong reference until `unloadModule(_:)` is called. This isn't strictly necessary (with some conditions applying). In some cases it is helpful for framework engineers to not pass ownership to Spezi. Namely, one can make use of being notified when objects are de-initialized (e.g., a framework creating a Module and passing ownership to the framework user and relying on the deinit to be notified when the user deallocated the object). This PR introduces the concept of `ModuleOwnership` that can be passed to the updated `loadModule(_:ownership:)` method. `external` ownership is available to framework developers via the `APISupport` SPI. When specifying `external` ownership does not keep any strong references to the loaded Module. This required making some changes how resources are automatically cleared (e.g., `@Dependency`, `@Provide`, `@Modifier` or `@Model` modifiers automatically clean up their resources once their are deallocated). Some features like `EnvironmentAccessible` are not available when using `external` ownership as they would inherently imply strong ownership. Other modules that depend on such modules either maintain a weak reference if they declare it as an optional dependency (in this case the dependency is automatically removed once the Module de-initializes) or a strong reference if declared as a required dependency. In such a case, ownership is shared with that module for the lifetime of the module that declares a required dependency to an externally managed module. ## ⚙️ Release Notes * Add support for dynamically loading Modules with external ownership. ## 📚 Documentation Documentation was updated for changed interfaces. ## ✅ Testing Additional unit testing was added to verify functionality of dynamically loaded modules with external ownership. ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
Showing
38 changed files
with
675 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.