DDDSampleApplicationContext.java 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package se.citerus.dddsample.config;
  2. import com.pathfinder.api.GraphTraversalService;
  3. import org.hibernate.SessionFactory;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.context.annotation.Bean;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.context.annotation.ImportResource;
  8. import org.springframework.transaction.PlatformTransactionManager;
  9. import se.citerus.dddsample.application.ApplicationEvents;
  10. import se.citerus.dddsample.application.BookingService;
  11. import se.citerus.dddsample.application.CargoInspectionService;
  12. import se.citerus.dddsample.application.HandlingEventService;
  13. import se.citerus.dddsample.application.impl.BookingServiceImpl;
  14. import se.citerus.dddsample.application.impl.CargoInspectionServiceImpl;
  15. import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
  16. import se.citerus.dddsample.application.util.SampleDataGenerator;
  17. import se.citerus.dddsample.domain.model.cargo.CargoRepository;
  18. import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
  19. import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
  20. import se.citerus.dddsample.domain.model.location.LocationRepository;
  21. import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
  22. import se.citerus.dddsample.domain.service.RoutingService;
  23. import se.citerus.dddsample.infrastructure.routing.ExternalRoutingService;
  24. @Configuration
  25. @ImportResource({
  26. "classpath:context-interfaces.xml",
  27. "classpath:context-infrastructure-messaging.xml",
  28. "classpath:context-infrastructure-persistence.xml"})
  29. public class DDDSampleApplicationContext {
  30. @Autowired
  31. CargoRepository cargoRepository;
  32. @Autowired
  33. LocationRepository locationRepository;
  34. @Autowired
  35. VoyageRepository voyageRepository;
  36. @Autowired
  37. GraphTraversalService graphTraversalService;
  38. @Autowired
  39. RoutingService routingService;
  40. @Autowired
  41. HandlingEventFactory handlingEventFactory;
  42. @Autowired
  43. HandlingEventRepository handlingEventRepository;
  44. @Autowired
  45. ApplicationEvents applicationEvents;
  46. @Autowired
  47. PlatformTransactionManager platformTransactionManager;
  48. @Autowired
  49. SessionFactory sessionFactory;
  50. @Bean
  51. public BookingService bookingService() {
  52. return new BookingServiceImpl(cargoRepository, locationRepository, routingService);
  53. }
  54. @Bean
  55. public CargoInspectionService cargoInspectionService() {
  56. return new CargoInspectionServiceImpl(applicationEvents, cargoRepository, handlingEventRepository);
  57. }
  58. @Bean
  59. public HandlingEventService handlingEventService() {
  60. return new HandlingEventServiceImpl(handlingEventRepository, applicationEvents, handlingEventFactory);
  61. }
  62. @Bean
  63. public HandlingEventFactory handlingEventFactory() {
  64. return new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
  65. }
  66. @Bean
  67. public RoutingService routingService() {
  68. ExternalRoutingService routingService = new ExternalRoutingService();
  69. routingService.setGraphTraversalService(graphTraversalService);
  70. routingService.setLocationRepository(locationRepository);
  71. routingService.setVoyageRepository(voyageRepository);
  72. return routingService;
  73. }
  74. @Bean
  75. public SampleDataGenerator sampleDataGenerator() {
  76. return new SampleDataGenerator(platformTransactionManager, sessionFactory, cargoRepository, voyageRepository, locationRepository, handlingEventRepository);
  77. }
  78. }