I used Dagger to inject dependencies on a Java Lambda:
我使用Dagger在Java Lambda上注入依赖项:
public class LambdaEntryPointHandler implements RequestHandler<SQSEvent, SQSBatchResponse> {
private final Handler handler;
public LambdaEntryPointHandler() {
ServiceComponent component = DaggerServiceComponent.create();
handler = component.getRequestHandler();
}
@Override
public SQSBatchResponse handleRequest(final SQSEvent sqsEvent, final Context context) {
return handler.handleRequest(sqsEvent, context);
}
}
I need to access the awsRequestId
of the context in a call far down the chain of calls, it's really tedious to pass the context object as a parameter to all the caller functions. I was wondering if using Dagger I could inject the context as a dependency to that class that uses it, instead of passing the parameter.
我需要在调用链下游的调用中访问上下文的awsRequestID,将上下文对象作为参数传递给所有调用者函数真的很繁琐。我想知道是否可以使用Dagger将上下文作为依赖项注入使用它的类,而不是传递参数。
I'm open to other suggestions, is there a global store available in this case? (Something like redux in react, to avoid passing props down the component tree)
我对其他建议持开放态度,这种情况下有没有全球商店?(类似Reaction中的redux,以避免在组件树中传递道具)
I saw this answer, but I don't use Spring.
我看到了这个答案,但我没有使用Spring。
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!