Skip to content
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

Enhanced Dependency Injection Functionality and Documentation #6

Merged
merged 9 commits into from
Jan 16, 2024

Conversation

Tavernari
Copy link
Owner

This pull request introduces several significant improvements to the DIContainer module, focusing on enhancing its dependency injection functionality, refining code structure, and adding comprehensive documentation for better clarity and maintainability.

Changes

InjectIdentifier Refactoring and Documentation

File: InjectIdentifier.swift

  • Documentation: Added detailed comments explaining the purpose and usage of InjectIdentifier.
  • Hashable Conformance: Extended InjectIdentifier to conform to the Hashable protocol, ensuring unique identification of dependencies.
  • Public Extension: Provided a convenient public extension for creating InjectIdentifier instances.

DIContainer Enhancements and Documentation

File: DIContainer.swift

  • Resolvable Protocol: Documented the Resolvable protocol, clarifying its role in resolving dependencies.
  • ResolvableError Enumeration: Defined ResolvableError to encapsulate errors during dependency resolution, with comprehensive documentation.
  • Injectable Protocol: Extensively documented the Injectable protocol, detailing each function and its purpose in dependency management.

Container Class Refinements

File: Container.swift

  • Singleton Pattern: Emphasized the use of Container as a singleton for managing dependencies across the application.
  • Property Wrappers: Modified and documented Injected and InjectedSafe property wrappers for improved error handling and clearer dependency resolution logic.
  • Code Readability: Focused on enhancing code readability and maintainability, making it easier for future development and modifications.

Package.swift Swift Tools Version Update

File: Package.swift

  • Swift Tools Version: Updated the Swift tools version from 5.3 to 5.9, ensuring compatibility with the latest Swift features and optimizations.

Impact

These changes enhance the DIContainer's functionality, making it more robust and user-friendly. The added documentation significantly improves the understandability of the code, facilitating easier maintenance and future enhancements. The update in Swift tools version aligns the module with current Swift standards.

Testing

  • New Test Case: Added a test case testWrapperInjectWithDefaultValueByStructType to validate the new functionality of injecting default values.
  • Existing Tests: Ensured all existing tests pass with the new changes, maintaining the integrity and reliability of the module.

This PR aims to provide a more robust and well-documented DIContainer module, aligning with best practices and current Swift standards. The enhancements are expected to improve the efficiency and reliability of dependency injection in Swift projects.

- Added a private `default` property to the Container class.
- Modified the initializer of Container to accept a `default` value.
- Updated the `wrappedValue` property to return a default value if available, otherwise throwing a fatal error when resolution fails.
- Extended DIContainerTests with a new test case `testWrapperInjectWithDefaultValueByStructType` to validate the new functionality.
- Changed the swift-tools-version from 5.3 to 5.9 in Package.swift.
- Enhanced `InjectIdentifier.swift` with documentation comments, added `Hashable` conformance, and public extension for creating identifiers.
- Updated `DIContainer.swift` with detailed documentation for the `Resolvable` protocol, `ResolvableError` enum, and `Injectable` protocol.
- Added comprehensive documentation and refactored code in `Container.swift`, including changes to `Injected` and `InjectedSafe` property wrappers for clearer error handling and dependency resolution.
- Improved code readability and maintainability across all modified files.
@Tavernari Tavernari self-assigned this Jan 15, 2024
Sources/DIContainer/Container.swift Outdated Show resolved Hide resolved
Sources/DIContainer/Container.swift Outdated Show resolved Hide resolved
Sources/DIContainer/Container.swift Outdated Show resolved Hide resolved
Sources/DIContainer/Container.swift Outdated Show resolved Hide resolved
Sources/DIContainer/Container.swift Outdated Show resolved Hide resolved
Copy link

codeclimate bot commented Jan 16, 2024

Code Climate has analyzed commit aa641d5 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 93.9% (50% is the threshold).

This pull request will bring the total coverage in the repository to 92.1% (1.3% change).

View more on Code Climate.

@Tavernari Tavernari merged commit b62996d into main Jan 16, 2024
2 checks passed
@Tavernari Tavernari deleted the default-injectable-value branch January 16, 2024 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant