Different models in both BLL and DAL

855 Views Asked by At

So I'm trying to learn how to keep a good structure in a WPF application and having a hard time figure out the best way to work with BLL and DAL.

I already have a couple of models in my BLL, for example:

Customer, Account, etc

I'm also using MVVMLight toolkit to make things easier so almost all my models inherit from "ObservableObject".

Now I'm going to create the DAL and use Entity framework. As all my models use ObservableObject I feel I can't just move them to my DAL to create my tables (code first).

Would the best way here be to create almost identical objects in my DAL and map all the data to my old models in my BLL when I retrieve them? I know it's a bit of double the work and so but can't see how I can keep it more clean (other than stop inherit from ObservableObject)

1

There are 1 best solutions below

2
EngineerSpock On

Entities like Customer and Account have to belong to the Domain model. It's recommended to keep your Domain agnostic of all irrelevant dependencies such as MVVM-blablabla. I would consider firstly how to remove a dependency on the MVVMLightToolkit from your models. You always can rely on INotifyPropertyChanged, sometimes it's better to sacrifice a couple of syntactic pieces of sugare. If you can avoid duplication, you should avoid it.

In the end, questions you raise are very dependent on circumstances, There is no one perfect remedy.

Consider to learn the following materials:
domain-driven-design-fundamentals
Eric Evans book on DDD