如果我有立面,我如何构建我的项目?
控制器会调用外观来调用另一个包和自包中的类吗?
像:
feature/
├── order/
│ ├── OrderController <== here calls Facade
│ ├── OrderService
└── facade/
│ ├── CheckoutFacade <== here calls orderService(go to facade and back to self package) and personService
└── person/
└── PersonService
我应该单独创建一个功能的控制器包吗?
答案 0 :(得分:1)
您可以将包组织为:[现在我认为这是完全错误的]
[编辑]以下内容有点误导
orderfeature/
├── OrderController <== here calls Facade public
└── service/
├── CheckoutFacade <== here calls orderService(go to facade and back to self package) and personService - public for test purpouse
├── OrderService (might be package scope)
└── PersonService (might be package scope)
[编辑]这个是可以接受的!
orderfeature/
├── OrderController <== here calls Facade public
├── CheckoutFacade <== here calls orderService(go to facade and back to self package) and personService - (might be package scope)
├── OrderService (might be package scope)
└── PersonService (might be package scope)
有经验也在我的项目中得出了一些结论我有这种结构
我现在这样做的方式是:
orderfeature/
└── api/
├── OrderController <== PACKAGE SCOPE [autowiring CheckoutFacade and so on.., and there is no need to make it public]
└── exceptions/
├── ExampleException <== PUBLIC SCOPE
└── dto/
├── ExampleDTO <== PUBLIC SCOPE [to communicate with facade]
├── CheckoutFacade <== PUBLIC SCOPE
├── OrderService <== PACKAGE SCOPE [service is hidden]
├── PersonService <== PACKAGE SCOPE [service is hidden]
├── ExampleRepository <== PUBLIC SCOPE [repository interface is public]
├── ExampleRepositoryInMemory <== PACKAGE SCOPE [repository interface
└── FeatureConfiguration <== PACKAGE SCOPE [ex spring bean config]
我真的很开心