Last post Mar 03, 2021 05:32 AM by GeorgeClass
Mar 02, 2021 09:19 PM|GeorgeClass|LINK
I'm a rookie at Net Core using Razor pages and I have doubts about how to use the MVVM model but witout using the EntityFrameWork (which I consider it useful just on basic things)
So I'm doing this, please let me know if I'm wrong on best practices:
Model - It's a pure class file with only properties inside the Models directory
View - HTML and C# code behind
So far, so good, but where should I put the database and logical layers? (like LoadClients using LoadDatatable)
I created a directory "Classes" and there I have Clients.cs and
am I doing something wrong with this?
Maybe functions in Clients.cs should be inside the Model...
Thanks in advance.
Mar 02, 2021 09:59 PM|bruce (sqlwork.com)|LINK
I'd put them in a separate project(s). The razor project should just have the UI code and only the UI code.
there should be a database layer project and a business (logic) layer project. The UI project should only reference the business layer, and its classes should be injected.
the database layer should implement interfaces used by the logic layer. then you can mock, and write unit tests for the business layer.
note: EF just implements a DB repository. You are free to build your own, as I use database first, I seldom use EF.
Mar 02, 2021 10:54 PM|DA924|LINK
You only have a part of it MVVM which is SoD.
Understanding Basics of UI Design Pattern MVC, MVP and MVVM - CodeProject
Then there is a bigger design pattern the MVVM can be implemented in that is using SoC
Separation of concerns - Wikipedia
You might want to look into Layered style.
Chapter 3: Architectural Patterns and Styles | Microsoft Docs
You can look into writing clean code.
ASP.NET - Writing Clean Code in ASP.NET Core with Dependency Injection | Microsoft Docs
Architectural principles | Microsoft Docs
New is Glue | Blog (ardalis.com)
I like to use the DAO pattern in the DAL
Data Access Object (DAO) design pattern in Java - Tutorial Example (javarevisited.blogspot.com)
And about using EF on basic things don't kid yourself now. :)
I have used EF DB first behind an ASP.NET WCF Web service that was doing CRUD operations for an over 80 objects Model with the DAO pattern in the DAL. EF is far more or any ORM like nHibernare are way far more that a basic usage.
Mar 03, 2021 05:31 AM|GeorgeClass|LINK
Thanks Bruce, this helped me a lot.
Mar 03, 2021 05:32 AM|GeorgeClass|LINK
Thanks for the references DA, they will light my path.