且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有必要为每个实体创建存储库和服务?

更新时间:2023-02-13 15:00:34

可能您需要12个存储库.但也许您不需要12项服务.服务可以处理对多个存储库的访问.这取决于您的逻辑以及每个实体的重要性".

Probably you'll need the 12 repositories. But maybe you won't need 12 services. A service could handle the access to several repositories. It depends on your logic and how "important" are every entity.

例如,如果您具有实体User和Address,则可以具有UserRepository和AddressRepository.但是只有UserService才能使用addAddress(User user,Address address)...

For example, if you had the entities User and Address you could have UserRepository and AddressRepository. But only UserService, with methods like addAddress(User user, Address address)...

总的来说,我建议您根据业务逻辑而不是一堆CRUD来组织服务

All in all, I'd recomend you to organize your services accordingly your business logic instead of a bunch of CRUDs