As an expansion from my previous question about using separate projects for seperate layers – Good practice on Visual Studio Solutions
I now wish to know if I am putting the right functionality in the correct layers.
Background
I'm building a WPF application from scratch, that contains business logic and business objects. The database itself sits on another server on the web with access to it, restricted to web API calls using OAuth authentication.
I think the following content should be in these layers. The idea being, you go from layer 1 to layer 4, you are only depending on the layers below you. To prevent circular dependencies.
1. Presentation
WPF View (what the user will see)
WPF ViewModel (how the program responds to user interaction)
No WPF Model, as it will just be the business object
2. Application/Services
Repository (class used by ViewModel to load/save business objects)
Utility classes to assist in saving objects, by selecting the correct API calls.
3. Business layer
Business objects/Entities/DTO (whichever name is preferred)
Factories (Used by the repositories in the creation of business objects)
Other misc business class (i.e. storage of currently logged in user)
4. Infrastructure/Data Access
OAuth client (makes authenticated calls against the web server, used by repository classes)
Best Answer
The four layers you mentioned match the names of the layering I've used when I recently architected two our our company solutions. I also strongly agree to @Konamiman reply, Data Access and Infrastructure shall be two separate layer. In our solutions Infrastucture is a cross-cutting layer which can be referenced by projects in any layer. In the infrastructure layer we keep the logging functionality, security and validation code.
I would also consider adding a layer below the Data Access Layer called Entities. Put all your business object there, add Interfaces of of the entities in the Data Access Layer and reference the Data Access Layer with the Entities project.
I'm used to using non-strict referencing as you described, an upper layer can reference any of the lower layers. In a strict referencing an upper layer should only reference the the closest lower layer.