Is it possible to use new instance whenever we need to use liveValue? #266
Replies: 1 comment 1 reply
-
While the library shines in single entry point, it is for sure compatible with non-single entry point 😄 See this section of the documentation: https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/singleentrypointsystems#Non-single-entry-point-systems
In Swift struct MyDependency {
var create: () -> MyInstance
}
// Or using a protocol, if you prefer:
protocol MyDependency {
func create() -> MyInstance
}
Again, we should consider these statics as interfaces that live as long as your application lives. Because the space is static it should also be relatively small, so there shouldn't be any worry about memory here, just like you shouldn't worry about If you have lifecycle-based dependencies that are introduced by some kind of
See this part of the docs: https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/livepreviewtest#Separating-interface-and-implementation |
Beta Was this translation helpful? Give feedback.
-
Hi I'm currently trying to pick & choose what DI framework that suits me because I'm still using the factory method as my DI ( you guys must be familiar with this 🤣).
It's interesting that this library is looking to SwiftUI Environment, but since most of my codebase is still UIKit, so I'm looking to how I could use this on my project. And this library can produce error when we're not using
testValue
to inject the data so that's a big + for my needs.And here's where I'm coming from on my new project:
Finally here's my questions:
static let
instead oflazy var
for theliveValue
& the other value? Is there a way to make a new instance everytime I need the dependency?static let
, when I have a lot of dependencies, does it mean we keep all of that property in the memory until the app closed or the library have a way to clean it up from the memory when it's not needed?a way to make the instance
rather than keeping theinstance
.I'm sorry for my long chat 🙇
Very appreciated to have a discussion with you guys.
Beta Was this translation helpful? Give feedback.
All reactions