Skip to content

Commit

Permalink
Updated documentation for DynamicInjected
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlongco committed Oct 10, 2024
1 parent dbed962 commit f350e0d
Show file tree
Hide file tree
Showing 237 changed files with 263 additions and 240 deletions.
41 changes: 27 additions & 14 deletions Sources/Factory/Factory/Injections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ import SwiftUI
/// EnvironmentObject in SwiftUI.
/// ```swift
/// class MyViewModel {
/// @Injected(\.myService) var service
/// @Injected(\MyCustomContainer.myService) var service
/// @Injected(\.myService) var service1
/// @Injected(\MyCustomContainer.myService) var service2
/// }
/// ```
/// The provided keypath resolves to a Factory definition on the `shared` container required for each Container type.
/// The short version of the keyPath resolves to the default container, while the expanded version
/// allows you to point an instance on your own customer container type.
/// allows you to point an instance of your own custom container type.
///
/// > Note: The @Injected property wrapper will be resolved on **initialization**. In the above example
/// the referenced dependencies will be acquired when the parent class is created.
Expand Down Expand Up @@ -95,13 +95,13 @@ import SwiftUI
/// EnvironmentObject in SwiftUI.
/// ```swift
/// class MyViewModel {
/// @LazyInjected(\.myService) var service
/// @LazyInjected(\MyCustomContainer.myService) var service
/// @LazyInjected(\.myService) var service1
/// @LazyInjected(\MyCustomContainer.myService) var service2
/// }
/// ```
/// The provided keypath resolves to a Factory definition on the `shared` container required for each Container type.
/// The short version of the keyPath resolves to the default container, while the expanded version
/// allows you to point an instance on your own customer container type.
/// allows you to point an instance of your own custom container type.
///
/// > Note: Lazy injection is resolved the first time the dependency is referenced by the code, and **not** on initialization.
@propertyWrapper public struct LazyInjected<T> {
Expand Down Expand Up @@ -179,13 +179,13 @@ import SwiftUI
///
/// ```swift
/// class MyViewModel {
/// @LazyInjected(\.myService) var service
/// @LazyInjected(\MyCustomContainer.myService) var service
/// @LazyInjected(\.myService) var service1
/// @LazyInjected(\MyCustomContainer.myService) var service2
/// }
/// ```
/// The provided keypath resolves to a Factory definition on the `shared` container required for each Container type.
/// The short version of the keyPath resolves to the default container, while the expanded version
/// allows you to point an instance on your own customer container type.
/// allows you to point an instance of your own custom container type.
///
/// > Note: Lazy injection is resolved the first time the dependency is referenced by the code, **not** on initialization.
@propertyWrapper public struct WeakLazyInjected<T> {
Expand Down Expand Up @@ -259,16 +259,29 @@ import SwiftUI
/// EnvironmentObject in SwiftUI.
/// ```swift
/// class MyViewModel {
/// @DynamicInjected(\.myService) var service
/// @DynamicInjected(\MyCustomContainer.myService) var service
/// @DynamicInjected(\.myService) var service1
/// @DynamicInjected(\MyCustomContainer.myService) var service2
/// }
/// ```
/// The provided keypath resolves to a Factory definition on the `shared` container required for each Container type.
/// The short version of the keyPath resolves to the default container, while the expanded version
/// allows you to point an instance on your own customer container type.
/// allows you to point an instance of your own custom container type.
///
/// - Note: The @DynamicInjected property wrapper will be resolved on **access**. In the above example
/// the referenced dependencies will be acquired each time the property is accessed.
/// - Important: The @DynamicInjected property wrapper's Factory will be resolved on each and every **access**.
///
/// In the above example the referenced dependencies will be resolved and acquired each and every time one of the
/// properties are accessed.
///
/// If the dependency is stateless this shouldn't be an issue. If the dependency needs to maintain state, however,
/// then it probably needs to be cached using one of Factory's caching mechanisms.
///
/// ```swift
/// extension Container {
/// var myService: Factory<MyServiceType> {
/// self { MyService() }.cached
/// }
/// }
/// ```
@propertyWrapper public struct DynamicInjected<T> {

private let reference: BoxedFactoryReference
Expand Down
2 changes: 1 addition & 1 deletion docs/data/documentation/factory.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/data/documentation/factory/autoregistering.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"variants":[{"paths":["\/documentation\/factory\/autoregistering"],"traits":[{"interfaceLanguage":"swift"}]}],"schemaVersion":{"major":0,"minor":3,"patch":0},"topicSections":[{"identifiers":["doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()"],"title":"Instance Methods"}],"metadata":{"modules":[{"name":"Factory"}],"roleHeading":"Protocol","symbolKind":"protocol","role":"symbol","navigatorTitle":[{"kind":"identifier","text":"AutoRegistering"}],"externalID":"s:7Factory15AutoRegisteringP","fragments":[{"kind":"keyword","text":"protocol"},{"kind":"text","text":" "},{"kind":"identifier","text":"AutoRegistering"}],"title":"AutoRegistering"},"abstract":[{"text":"Adds an registration “hook” to a ","type":"text"},{"code":"Container","type":"codeVoice"},{"type":"text","text":"."}],"kind":"symbol","sections":[],"hierarchy":{"paths":[["doc:\/\/Factory\/documentation\/Factory"]]},"primaryContentSections":[{"kind":"declarations","declarations":[{"platforms":["macOS"],"tokens":[{"kind":"keyword","text":"protocol"},{"kind":"text","text":" "},{"text":"AutoRegistering","kind":"identifier"}],"languages":["swift"]}]},{"kind":"content","content":[{"text":"Overview","level":2,"type":"heading","anchor":"overview"},{"inlineContent":[{"text":"Add this protocol to a container to support first-time registration of needed dependencies prior to first resolution","type":"text"},{"type":"text","text":" "},{"type":"text","text":"of a dependency on that container."}],"type":"paragraph"},{"type":"codeListing","syntax":"swift","code":["extension Container: @retroactive AutoRegistering {"," func autoRegister() {"," someService.register {"," CrossModuleService()"," }"," }","}"]},{"inlineContent":[{"type":"text","text":"The "},{"code":"autoRegister","type":"codeVoice"},{"type":"text","text":" function is called on each instantiated container prior to"},{"text":" ","type":"text"},{"type":"text","text":"the first resolution of a Factory on that container."}],"type":"paragraph"},{"name":"Warning","content":[{"type":"paragraph","inlineContent":[{"text":"Calling ","type":"text"},{"code":"container.manager.reset(options: .all)","type":"codeVoice"},{"type":"text","text":" restores the container to it’s initial state"},{"type":"text","text":" "},{"type":"text","text":"and autoRegister will be called again if it exists."}]}],"style":"warning","type":"aside"},{"inlineContent":[{"type":"text","text":"The "},{"code":"@retroactive","type":"codeVoice"},{"type":"text","text":" attribute is needed as of Swift 6 to silence a conformance warning."}],"type":"paragraph"}]}],"identifier":{"url":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering","interfaceLanguage":"swift"},"references":{"doc://Factory/documentation/Factory":{"kind":"symbol","title":"Factory","identifier":"doc:\/\/Factory\/documentation\/Factory","url":"\/documentation\/factory","abstract":[{"type":"text","text":"A new approach to Container-Based Dependency Injection for Swift and SwiftUI."}],"role":"collection","type":"topic"},"doc://Factory/documentation/Factory/AutoRegistering/autoRegister()":{"fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"kind":"identifier","text":"autoRegister"},{"kind":"text","text":"()"}],"type":"topic","role":"symbol","title":"autoRegister()","required":true,"identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","abstract":[{"type":"text","text":"User provided function that supports first-time registration of needed dependencies prior to first resolution"},{"text":" ","type":"text"},{"type":"text","text":"of a dependency on that container."}],"url":"\/documentation\/factory\/autoregistering\/autoregister()","kind":"symbol"},"doc://Factory/documentation/Factory/AutoRegistering":{"fragments":[{"kind":"keyword","text":"protocol"},{"kind":"text","text":" "},{"text":"AutoRegistering","kind":"identifier"}],"type":"topic","role":"symbol","title":"AutoRegistering","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering","navigatorTitle":[{"text":"AutoRegistering","kind":"identifier"}],"abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"code":"Container","type":"codeVoice"},{"type":"text","text":"."}],"url":"\/documentation\/factory\/autoregistering","kind":"symbol"}}}
{"hierarchy":{"paths":[["doc:\/\/Factory\/documentation\/Factory"]]},"metadata":{"modules":[{"name":"Factory"}],"roleHeading":"Protocol","symbolKind":"protocol","title":"AutoRegistering","fragments":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"text":"AutoRegistering","kind":"identifier"}],"role":"symbol","externalID":"s:7Factory15AutoRegisteringP","navigatorTitle":[{"kind":"identifier","text":"AutoRegistering"}]},"sections":[],"schemaVersion":{"minor":3,"patch":0,"major":0},"kind":"symbol","primaryContentSections":[{"kind":"declarations","declarations":[{"languages":["swift"],"tokens":[{"text":"protocol","kind":"keyword"},{"kind":"text","text":" "},{"kind":"identifier","text":"AutoRegistering"}],"platforms":["macOS"]}]},{"kind":"content","content":[{"anchor":"overview","type":"heading","text":"Overview","level":2},{"inlineContent":[{"type":"text","text":"Add this protocol to a container to support first-time registration of needed dependencies prior to first resolution"},{"type":"text","text":" "},{"type":"text","text":"of a dependency on that container."}],"type":"paragraph"},{"code":["extension Container: @retroactive AutoRegistering {"," func autoRegister() {"," someService.register {"," CrossModuleService()"," }"," }","}"],"type":"codeListing","syntax":"swift"},{"inlineContent":[{"text":"The ","type":"text"},{"type":"codeVoice","code":"autoRegister"},{"type":"text","text":" function is called on each instantiated container prior to"},{"type":"text","text":" "},{"text":"the first resolution of a Factory on that container.","type":"text"}],"type":"paragraph"},{"name":"Warning","type":"aside","content":[{"inlineContent":[{"type":"text","text":"Calling "},{"type":"codeVoice","code":"container.manager.reset(options: .all)"},{"text":" restores the container to it’s initial state","type":"text"},{"type":"text","text":" "},{"type":"text","text":"and autoRegister will be called again if it exists."}],"type":"paragraph"}],"style":"warning"},{"inlineContent":[{"type":"text","text":"The "},{"type":"codeVoice","code":"@retroactive"},{"type":"text","text":" attribute is needed as of Swift 6 to silence a conformance warning."}],"type":"paragraph"}]}],"identifier":{"url":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering","interfaceLanguage":"swift"},"topicSections":[{"title":"Instance Methods","identifiers":["doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()"]}],"abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"type":"codeVoice","code":"Container"},{"text":".","type":"text"}],"variants":[{"paths":["\/documentation\/factory\/autoregistering"],"traits":[{"interfaceLanguage":"swift"}]}],"references":{"doc://Factory/documentation/Factory/AutoRegistering/autoRegister()":{"fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"text":"autoRegister","kind":"identifier"},{"text":"()","kind":"text"}],"kind":"symbol","required":true,"type":"topic","title":"autoRegister()","url":"\/documentation\/factory\/autoregistering\/autoregister()","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","role":"symbol","abstract":[{"type":"text","text":"User provided function that supports first-time registration of needed dependencies prior to first resolution"},{"type":"text","text":" "},{"type":"text","text":"of a dependency on that container."}]},"doc://Factory/documentation/Factory/AutoRegistering":{"fragments":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"text":"AutoRegistering","kind":"identifier"}],"kind":"symbol","type":"topic","title":"AutoRegistering","url":"\/documentation\/factory\/autoregistering","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering","role":"symbol","navigatorTitle":[{"text":"AutoRegistering","kind":"identifier"}],"abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"type":"codeVoice","code":"Container"},{"type":"text","text":"."}]},"doc://Factory/documentation/Factory":{"abstract":[{"text":"A new approach to Container-Based Dependency Injection for Swift and SwiftUI.","type":"text"}],"role":"collection","identifier":"doc:\/\/Factory\/documentation\/Factory","title":"Factory","url":"\/documentation\/factory","type":"topic","kind":"symbol"}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"kind":"symbol","variants":[{"traits":[{"interfaceLanguage":"swift"}],"paths":["\/documentation\/factory\/autoregistering\/autoregister()"]}],"schemaVersion":{"major":0,"minor":3,"patch":0},"hierarchy":{"paths":[["doc:\/\/Factory\/documentation\/Factory","doc:\/\/Factory\/documentation\/Factory\/AutoRegistering"]]},"abstract":[{"type":"text","text":"User provided function that supports first-time registration of needed dependencies prior to first resolution"},{"type":"text","text":" "},{"type":"text","text":"of a dependency on that container."}],"identifier":{"url":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","interfaceLanguage":"swift"},"primaryContentSections":[{"kind":"declarations","declarations":[{"platforms":["macOS"],"languages":["swift"],"tokens":[{"text":"func","kind":"keyword"},{"kind":"text","text":" "},{"kind":"identifier","text":"autoRegister"},{"text":"()","kind":"text"}]}]}],"sections":[],"metadata":{"modules":[{"name":"Factory"}],"title":"autoRegister()","role":"symbol","roleHeading":"Instance Method","externalID":"s:7Factory15AutoRegisteringP12autoRegisteryyF","symbolKind":"method","fragments":[{"kind":"keyword","text":"func"},{"text":" ","kind":"text"},{"kind":"identifier","text":"autoRegister"},{"text":"()","kind":"text"}],"required":true},"references":{"doc://Factory/documentation/Factory/AutoRegistering":{"fragments":[{"kind":"keyword","text":"protocol"},{"kind":"text","text":" "},{"text":"AutoRegistering","kind":"identifier"}],"type":"topic","role":"symbol","title":"AutoRegistering","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering","navigatorTitle":[{"text":"AutoRegistering","kind":"identifier"}],"abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"code":"Container","type":"codeVoice"},{"type":"text","text":"."}],"url":"\/documentation\/factory\/autoregistering","kind":"symbol"},"doc://Factory/documentation/Factory/AutoRegistering/autoRegister()":{"fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"kind":"identifier","text":"autoRegister"},{"kind":"text","text":"()"}],"type":"topic","role":"symbol","title":"autoRegister()","required":true,"identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","abstract":[{"type":"text","text":"User provided function that supports first-time registration of needed dependencies prior to first resolution"},{"text":" ","type":"text"},{"type":"text","text":"of a dependency on that container."}],"url":"\/documentation\/factory\/autoregistering\/autoregister()","kind":"symbol"},"doc://Factory/documentation/Factory":{"kind":"symbol","title":"Factory","identifier":"doc:\/\/Factory\/documentation\/Factory","url":"\/documentation\/factory","abstract":[{"type":"text","text":"A new approach to Container-Based Dependency Injection for Swift and SwiftUI."}],"role":"collection","type":"topic"}}}
{"identifier":{"interfaceLanguage":"swift","url":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()"},"primaryContentSections":[{"declarations":[{"platforms":["macOS"],"tokens":[{"kind":"keyword","text":"func"},{"text":" ","kind":"text"},{"kind":"identifier","text":"autoRegister"},{"text":"()","kind":"text"}],"languages":["swift"]}],"kind":"declarations"}],"abstract":[{"type":"text","text":"User provided function that supports first-time registration of needed dependencies prior to first resolution"},{"type":"text","text":" "},{"text":"of a dependency on that container.","type":"text"}],"kind":"symbol","schemaVersion":{"patch":0,"major":0,"minor":3},"hierarchy":{"paths":[["doc:\/\/Factory\/documentation\/Factory","doc:\/\/Factory\/documentation\/Factory\/AutoRegistering"]]},"metadata":{"fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"kind":"identifier","text":"autoRegister"},{"text":"()","kind":"text"}],"required":true,"externalID":"s:7Factory15AutoRegisteringP12autoRegisteryyF","roleHeading":"Instance Method","title":"autoRegister()","symbolKind":"method","role":"symbol","modules":[{"name":"Factory"}]},"variants":[{"paths":["\/documentation\/factory\/autoregistering\/autoregister()"],"traits":[{"interfaceLanguage":"swift"}]}],"sections":[],"references":{"doc://Factory/documentation/Factory/AutoRegistering/autoRegister()":{"fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"text":"autoRegister","kind":"identifier"},{"text":"()","kind":"text"}],"kind":"symbol","required":true,"type":"topic","title":"autoRegister()","url":"\/documentation\/factory\/autoregistering\/autoregister()","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","role":"symbol","abstract":[{"type":"text","text":"User provided function that supports first-time registration of needed dependencies prior to first resolution"},{"type":"text","text":" "},{"type":"text","text":"of a dependency on that container."}]},"doc://Factory/documentation/Factory/AutoRegistering":{"fragments":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"text":"AutoRegistering","kind":"identifier"}],"kind":"symbol","type":"topic","title":"AutoRegistering","url":"\/documentation\/factory\/autoregistering","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering","role":"symbol","navigatorTitle":[{"text":"AutoRegistering","kind":"identifier"}],"abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"type":"codeVoice","code":"Container"},{"type":"text","text":"."}]},"doc://Factory/documentation/Factory":{"abstract":[{"text":"A new approach to Container-Based Dependency Injection for Swift and SwiftUI.","type":"text"}],"role":"collection","identifier":"doc:\/\/Factory\/documentation\/Factory","title":"Factory","url":"\/documentation\/factory","type":"topic","kind":"symbol"}}}
Loading

0 comments on commit f350e0d

Please sign in to comment.