Java 匕首-注册没有@Inject的类,仪式最少

Java 匕首-注册没有@Inject的类,仪式最少,java,kotlin,dependency-injection,dagger-2,dagger,Java,Kotlin,Dependency Injection,Dagger 2,Dagger,假设我想用Dagger注册一个类,该类在构造函数上没有@Inject注释,并且在构造函数中也有依赖项 i、 e 有没有一种方法可以注册这个类而不必手动将依赖项连接到构造函数中 // This is how I currently do it. I must list all constructor dependencies // and then pass them through to the constructor by hand @Provides public MyClass getMy

假设我想用Dagger注册一个类,该类在构造函数上没有
@Inject
注释,并且在构造函数中也有依赖项

i、 e

有没有一种方法可以注册这个类而不必手动将依赖项连接到构造函数中

// This is how I currently do it. I must list all constructor dependencies
// and then pass them through to the constructor by hand
@Provides
public MyClass getMyClass(MyDependency depdencency) {
    return new MyClass(dependency);
}

// Something like this is how I'd like to do it
// In this case, the class is registered _as if_ it had the @Inject on the constructor
@ProvideEvenWithoutAnInject
public abstract MyClass getMyClass();

Dagger是否提供类似于
@provided的东西,即使没有上面显示的对象
注释?

如果无法在构造函数上放置
@Inject
注释,Dagger将无法为您创建对象。您需要将
@提供
注释的方法与模块一起使用,或将
@BindsInstance
与组件一起使用才能添加它。(或者,如果您需要更多额外的步骤,可以将其作为provision方法的组件依赖项)

在构造函数中使用
@Inject
是最简单的步骤。Dagger不知道调用可能很多的构造函数中的哪一个。
// This is how I currently do it. I must list all constructor dependencies
// and then pass them through to the constructor by hand
@Provides
public MyClass getMyClass(MyDependency depdencency) {
    return new MyClass(dependency);
}

// Something like this is how I'd like to do it
// In this case, the class is registered _as if_ it had the @Inject on the constructor
@ProvideEvenWithoutAnInject
public abstract MyClass getMyClass();