Question

I came up with a separation of concerns problem while trying to solve repository and unit of work pattern with Entity Framework Model First. In my solution I have 4 projects: Data, Domain, Repository, Console. In my data layer, I have EF, edmx file. In domain layer, I have my objects, in repository layer, i have repo interface and UOW class. In console layer, i try to write names on screen. But in order to write names on screen, I have to add EF dll to Console Project and write database connection string to app.config. But this is wrong I guess for separation of concerns. Console project should not know about EF, it should only communicate with Repo layer to use Unit of Work(UOW) class.

Here is my structure:

enter image description here

Two projects use EF dll which is

enter image description here

My simple Console app references(this is how I want it to be, only use repo layer and domian layer)

enter image description here

My console code is :

enter image description here

Here the console code doesn't work unless I add EF to project and connection string to the project. What am I doing wrong? Any suggestion would help, I look into some github projects and could not find a simple solution which doesn't have connection string in app.config or web.config

Was it helpful?

Solution

The connection string dependency is not something i see as violating the separation of concerns. The start projects Knows the environment. BUT:

if you want to avoid having connection strings you can create contexts passing in connection Info

public class MyContext : DbContext
public MyContext(DbConnection dbConnection, bool contextOwnsConnection)
        : base(dbConnection, contextOwnsConnection) 

I also have EF as a package referenced so it can be loaded.

 <package id="EntityFramework" version="6.0.1" targetFramework="net45" />

But I just checked with Resharper. It can be safe deleted. So i dont have code references to EF. Just an environmental load/package reference.

Not breaking the code separation Domain driven development paradigm in my view

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top