15
15
import life .qbic .projectmanagement .domain .service .BatchDomainService ;
16
16
import life .qbic .projectmanagement .domain .service .SampleDomainService ;
17
17
import org .springframework .beans .factory .annotation .Autowired ;
18
- import org .springframework .context .ApplicationContext ;
18
+ import org .springframework .context .annotation . Lazy ;
19
19
import org .springframework .stereotype .Service ;
20
20
import org .springframework .transaction .annotation .Transactional ;
21
21
29
29
@ Service
30
30
public class DeletionService {
31
31
32
- private ApplicationContext context ;
32
+ private DeletionService selfProxy ;
33
33
34
34
private final ProjectInformationService projectInformationService ;
35
35
private final ExperimentInformationService experimentInformationService ;
@@ -41,7 +41,8 @@ public class DeletionService {
41
41
public DeletionService (ProjectInformationService projectInformationService ,
42
42
ExperimentInformationService experimentInformationService ,
43
43
SampleInformationService sampleInformationService , BatchDomainService batchDomainService ,
44
- SampleDomainService sampleDomainService , ApplicationContext context ) {
44
+ SampleDomainService sampleDomainService ,
45
+ @ Lazy DeletionService selfProxy ) {
45
46
this .projectInformationService = requireNonNull (projectInformationService ,
46
47
"experimentInformationService must not be null" );
47
48
this .experimentInformationService = requireNonNull (experimentInformationService ,
@@ -52,6 +53,7 @@ public DeletionService(ProjectInformationService projectInformationService,
52
53
BatchDomainService .class .getSimpleName () + " must not be null" );
53
54
this .sampleDomainService = requireNonNull (sampleDomainService ,
54
55
SampleDomainService .class .getSimpleName () + " must not be null" );
56
+ this .selfProxy = selfProxy ;
55
57
}
56
58
57
59
/**
@@ -88,7 +90,7 @@ public BatchId deleteBatch(ProjectId projectId, BatchId batchId) {
88
90
});
89
91
// We need to get the proxy Spring has wrapped around the service, otherwise calling
90
92
// the @transaction annotated method has no effect
91
- context . getBean ( DeletionService . class ) .deleteSamples (projectId , batchId , samples );
93
+ selfProxy .deleteSamples (projectId , batchId , samples );
92
94
return deletedBatchId .getValue ();
93
95
}
94
96
0 commit comments