flamingo.me/flamingo-commerce/v3@v3.11.0/order/module.go (about) 1 package order 2 3 import ( 4 "flamingo.me/dingo" 5 "flamingo.me/flamingo-commerce/v3/order/domain" 6 "flamingo.me/flamingo-commerce/v3/order/infrastructure/fake" 7 "flamingo.me/flamingo-commerce/v3/order/interfaces/controller" 8 "flamingo.me/flamingo/v3/framework/web" 9 ) 10 11 type ( 12 // Module definition of the order module 13 Module struct { 14 useFakeAdapter bool 15 } 16 ) 17 18 const ( 19 // LogKey defines the module log category key 20 LogKey = "order" 21 ) 22 23 // Inject dependencies 24 func (m *Module) Inject( 25 config *struct { 26 UseFakeAdapter bool `inject:"config:commerce.order.useFakeAdapter,optional"` 27 }, 28 ) { 29 if config != nil { 30 m.useFakeAdapter = config.UseFakeAdapter 31 } 32 } 33 34 // Configure DI 35 func (m *Module) Configure(injector *dingo.Injector) { 36 37 if m.useFakeAdapter { 38 injector.Bind((*domain.CustomerIdentityOrderService)(nil)).To(fake.CustomerOrders{}) 39 } 40 41 injector.Bind((*domain.OrderDecoratorInterface)(nil)).To(domain.OrderDecorator{}) 42 web.BindRoutes(injector, new(routes)) 43 } 44 45 type routes struct { 46 controller *controller.DataControllerCustomerOrders 47 } 48 49 func (r *routes) Inject(controller *controller.DataControllerCustomerOrders) { 50 r.controller = controller 51 } 52 53 func (r *routes) Routes(registry *web.RouterRegistry) { 54 registry.HandleData("customerorders", r.controller.Data) 55 } 56 57 // FlamingoLegacyConfigAlias maps legacy config entries to new ones 58 func (m *Module) FlamingoLegacyConfigAlias() map[string]string { 59 return map[string]string{ 60 "order.useFakeAdapters": "commerce.order.useFakeAdapter", 61 } 62 }