Spring and the anemic domain model

前端 未结 4 700
后悔当初
后悔当初 2020-12-04 09:05

So, I\'ve noticed that I definitely have a tendency to pattern my Spring/Hibernate stack objects like this:

  • Foo controller makes a call to \"FooService\"
4条回答
  •  我在风中等你
    2020-12-04 09:34

    You can get Spring to inject your services into your Hibernate instantiated instances, using AOP. You can also get Hibernate to do the same, using Interceptors.

    See http://www.jblewitt.com/blog/?p=129

    Regarding "It's annoying to get a Foo to do several somethings transactionally", I would expect your service implementations would know/care about the transactions, and if you're now using the service interfaces within your domain model, that should now be not quite so annoying.

    I suspect that deciding when a domain model should be saved is dependent upon what it is and what you're doing with it.

    FWIW I have a tendency to produce just the same sort of anemic structures, but I'm getting there, now I know it's possible to do it a more sensible way.

提交回复
热议问题