【发布时间】:2021-07-11 07:48:39
【问题描述】:
我正在用 java 编写一个 azure 函数。为了使用良好的模块化模式,我创建了一个具有抽象接口类的服务层和一个实现服务层的实现层。
但是,我没有使用Spring-framework,所以我不能使用@Autowired 在运行器文件中创建服务层的单例实例。如何在我的 runner 类(或我项目中的其他地方)中使用我的服务层函数?
服务层
public interface TimeTriggeredService {
String getLogs(String token, String url,final ExecutionContext context);
}
实现层
public class TimeTriggeredServiceImpl implements TimeTriggeredService {
public String getLogs(String token, String url,final ExecutionContext context) {
// Some logic
}
}
跑步者类
public class TimeTriggeredFunction {
@FunctionName("TimeTriggeredFunction")
public void run(@TimerTrigger(name = "timerInfo", schedule = "0 */1 * * * *") String timerInfo,
final ExecutionContext context) {
String timeAuditLogs = TimeTriggeredService.getLogs(token, URL ,context); // unsure what should replace this line or what should be done before this.
}
}
注意:这不是春季项目。
【问题讨论】:
-
@Inject 会为你做 DI。
-
下面的答案有帮助吗?
标签: java azure-functions singleton service-layer