I have a classlibrary which contains all the Database Manipulation Logic. The other Project in my ProjectSolution is my WPF Core app. I have created my Student Model there. In my Mainwindow.xaml.cs i instantiate my DataAccess Class. Here i have the dependency to my class library which contains this Data Access Class. Now i want insert some Dummy Data into my Database. (I use Dapper Micro ORM) Instead of hardcoding the sqlStatement, or using a stored procedure, my idea was to run through a List of Students and insert them into my Table. But for this i would need the Dependency to the Student in my Data Access Classlibrary. And there is the Problem. i want my Data Access decoupled from my Wpf Core app. Anyone a Idea? Btw im new to programming.
2 Answers
It's common to have a Core
project with entities and business logic.
Your WPF project (i.e. presentation layer), and all other projects including DAL would reference this Core App.
--------
| Core | <- DAL
-------- <- WPF App
A more traditional thing to do is something like:
DAL <- Core (Business Logic) <- App
Microsoft maintains a few sample projects with real-world examples that you can refer to. Here's a UWP example that takes the traditional route: https://github.com/microsoft/InventorySample
In that example as of 47d779a
, the Inventory.Data
project is your DAL, and the Inventory.ViewModels
is the "Core" project.

- 12,411
- 7
- 56
- 71
You should look up unit of work pattern, Repository pattern. Then you might want to look up SOLID -> 5 principles in one.
Combine all principles and patterns, should give something extremely solid.
If you are looking for something a little more concrete:
public interface ICreateStudent
void CreateStudent(IStudent student){
...create DAL-student from interface, store created obj.
}
//Generate this a partial class for implementing the IStudent interface, if your code is being
//autogenerated by dapper.
public partial class WPFStudent : IStudent
{
}
Then you only need to reference the interface and not the object itself. Also, maybe look up the term "Composition root".

- 1,413
- 11
- 23