Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Tavernari/DIContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tavernari committed Jan 16, 2024
2 parents 878e521 + b62996d commit 3834f85
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ on:

jobs:
test:
runs-on: macos-11
runs-on: macos-latest

steps:
- name: Install Swift
uses: slashmo/install-swift@v0.4.0
with:
version: "5.9"

- name: Get Sources
uses: actions/checkout@v2

Expand Down
17 changes: 12 additions & 5 deletions Sources/DIContainer/Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class Container: Injectable {

/// A dictionary holding the dependencies.
///
/// The dependencies are stored as key-value pairs where the key is any hashable object and the value is the dependency.
/// The dependencies are stored as key-value pairs where the key
/// is any hashable object and the value is the dependency.
public var dependencies: [AnyHashable: Any] = [:]

/// Creates a new instance of `Container`.
Expand All @@ -22,7 +23,9 @@ public class Container: Injectable {

/// A property wrapper for injecting dependencies.
///
/// This struct wraps a property and injects a dependency into it. If the dependency cannot be resolved and no default value is provided, it will crash the application.
/// This struct wraps a property and injects a dependency into it.
/// If the dependency cannot be resolved and no default value is provided,
/// it will crash the application.
@propertyWrapper public struct Injected<Value> {

/// Error types related to dependency injection.
Expand Down Expand Up @@ -51,7 +54,9 @@ public class Container: Injectable {

/// The resolved value of the dependency.
///
/// This property lazily resolves the dependency. If the dependency cannot be resolved, it will use the provided default value. If both fail, the application will crash.
/// This property lazily resolves the dependency.
/// If the dependency cannot be resolved, it will use the provided default value.
/// If both fail, the application will crash.
public lazy var wrappedValue: Value = {
if let value = try? container.resolve(identifier) {
return value
Expand All @@ -67,7 +72,8 @@ public class Container: Injectable {

/// A property wrapper for safely injecting dependencies.
///
/// This struct wraps a property and injects an optional dependency into it. If the dependency cannot be resolved, the property will be nil.
/// This struct wraps a property and injects an optional dependency into it.
/// If the dependency cannot be resolved, the property will be nil.
@propertyWrapper public struct InjectedSafe<Value> {

/// Returns the standard container used for resolving dependencies.
Expand All @@ -88,6 +94,7 @@ public class Container: Injectable {

/// The optionally resolved value of the dependency.
///
/// This property lazily tries to resolve the dependency. If the dependency cannot be resolved, the property will be nil.
/// This property lazily tries to resolve the dependency.
/// If the dependency cannot be resolved, the property will be nil.
public lazy var wrappedValue: Value? = try? container.resolve(identifier)
}
6 changes: 4 additions & 2 deletions Sources/DIContainer/DIContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public protocol Resolvable {
func resolve<Value>(_ identifier: InjectIdentifier<Value>) throws -> Value
}

/// An enumeration representing errors that can occur during the resolution of dependencies.
/// An enumeration representing errors
/// that can occur during the resolution of dependencies.
public enum ResolvableError: Error {

/// Indicates that a dependency could not be found.
Expand All @@ -22,7 +23,8 @@ public enum ResolvableError: Error {
case dependencyNotFound(Any.Type?, String?)
}

/// Extension to make `ResolvableError` conform to `LocalizedError`, providing a localized description of the error.
/// Extension to make `ResolvableError` conform
/// to `LocalizedError`, providing a localized description of the error.
extension ResolvableError: LocalizedError {

/// A localized description of the error.
Expand Down

0 comments on commit 3834f85

Please sign in to comment.