KnitNeedle is a dependency injection visualisation framework built directly on top of Knit, utilising interactive graphs to map out dependency relationships, flag out errors, all from the comfort of your own IDE. KnitNeedle is lightning fast, informative, and packed with optimisations to keep things moving.
KnitNeedle improves upon Knit's internal logging system -- Knit does not produce a JSON dump if compilation was unsuccessful, meaning that such errors are not very visible to the user. To solve this issue, KnitNeedle employs optimistic logging -- meaning that even if dependency injection errors occur, the exact classes that led to the flagged issue(s) appear in the JSON dump and visualised.
This provides KnitNeedle with the unique ability to include errored classes in its dependency visualisation, and therefore also show affected upstream classes. This is reflected in the visualised dependency graph, which provides programmers a clear view of what classes are affected, and how to quickly resolve such issues.
KnitNeedle quickly updates dependency graphs in response to code changes -- by taking advantage of Kotlin's incremental compilation capabilities, KnitNeedle builds upon Knit's logging system to only capture logs for parts of the codebase that have to be recompiled. This offers a significant speed increase, as KnitNeedle no longer has to traverse the whole codebase just to update a small set of nodes -- a big plus for large codebases.
@Provides
class User(val name: String) // Producer
class UserService(
@Provides val name: String // Producer which can provide `String`
) {
val user: User by di // Consumer which need a `User`
}
fun main() {
val userService = UserService("foo")
val user = userService.user // User("foo")
}There are 2 basic concepts in Knit:
@Provides, producers should be marked with@Provides, it means this member can be used to provide something.by di, consumers should be marked withby di, marked properties should be injected by dependency injection.
In the previous case:
Userhas been marked with@Provides, it meansUserprovides its constructor as a dependency provider, and this provider needs aStringprovided to construct aUser.UserServicehas a constructor which needs aStringand it also provides this type insideUserService.UserService.usercan be injected through providedUserconstructor and provided parametername.- For
UserServicecall-site, the only thing needs to do is construct it like a normal constructor call, and access its member directly.
KnitNeedle is a fork of the original Knit repository.