Dependency Injection in Custom Plugin

Hi,

I was looking for samples and documentation of using dependency injection in a custom plugin. All the related links in the similar topics don’t point to anything conclusive.

I am familiar with dagger2 and am fine with injecting when the plugins apply method is called but I am worried that the graph won’t be around for tasks at execution time.

I was thinking along the lines of

override fun apply(target: Project) {
        DaggerComponent.builder().build().inject(this)
}

Will the object graph stay in memory or will each task need to do the same for dependencies?

@TaskAction
fun execute() {
    DaggerComponent.builder().build().inject(this)
}

Any documentation would be appreciated.

Thanks!