Can someone explain? I'm trying to convert my wpf app mvvm into different layers (reading ddd). I have some small confusions
but the following confuse me
with all the above i have make sample application trying to understand where each one goes.
STEPS I FOLLOW
IService
that implements and inherited from reposirotyMy Question on this is. Is It normal? shouldn't service be independent?
Should Service Layer used it's own models? and convert data repository models to service models? therefor wpf will not need reference to repository? ( but if so.. isn't duplicate work?)
It depends on which pattern you want implement: rich domain model or anemic.
Some refs:
In two words:
If you talks about services, it's not pure DDD, it's anemic.
Fowler told that anemic is an anti-pattern, but it's used a quite often. The main problem of rich domain model, that you need a lot of experience to realise right way to implement it.
I think in your case you can use entities as domain objects.
If you trying to implement domain model, it requires a organised structure of you solution.
Usually it contains next projects:
*.Domain
- for domain objects
*.Application
- for you business logic, if we talk about anemic model
*.Dto
or *.Contract
- for dto's or another objects that can be use at outer scope of your application (for services interactions, dto's, etc.)
*.Persistence
- for data layer
Dto(Contract)
is placed in another project in case reusing items implemented at them.
Where * is your project name.
Dto depends on your needs.
I recommend declare dto's for each purpose, but if you don't want, you still can return domain object (but some people can say, that it's bad practice).
As I told previously you can place dto's to *.Dto or *.Contract projects
Implement at your *.Application
Usually you prefer to declare Data Repository interfaces at *.Domain
or *.Application
and implementation at *.Persistence
. It allows you use interfaces and don't care about realisation.
Best practice it's when service depends just on your *.Domain
assembly.
You services should work with domain models, and return dto's when it needs. One of general ideas of ddd, that you have common model for all operations. So it's good if you can return your domain model from repository.