I use this tutorial to create a Database model.
I decided to create another assembly for abstractions such as IRepository
, IFooService
by reading this quote of "Programming .NET Components" by Juwal Lowy:
Because interfaces can be implemented by multiple components, it's good practice to put them in a separate assembly from that of the implementing components.
My solution structure could look like this:
PersonsApp.Solution
--PersonsApp.WebUI
-- Controllers (PersonController)
--PersonApp.Common
--Core folder
-IGenericRepository.cs (Abstraction)
-IUnitOfWork.cs (Abstraction)
--Repositories folder
-IPersonRepository.cs (Abstraction)
--PersonApp.Persistence
--Infrastructure folder
-DbDactory.cs (Implementation)
-Disposable.cs (Implementation)
-IDbFactory.cs (Abstraction)
-RepositoryBase.cs (Abstraction)
--Models folder(Here we have DbContext, EF models (Implementation))
-Person.cs (Implementation)
-PersonContext.cs (Implementation)
--Repositories folder
-PersonRepository.cs (Implementation)
However, PersonApp.Persistence
project has a reference to PersonApp.Common
. But my project PersonApp.Common
also needs a reference to PersonApp.Persistence
because I would like to create a IPersonRepository.cs
in Person.Common
:
public interface IPersonRepository : IRepository<Person> {}
The following error is thrown, when I try to add a reference to PersonApp.Persistence
into PersonApp.Common
:
A reference to 'PersonApp.Persistence' could not be added. Adding this project as a reference would cause a circular dependency.
However, I really would like to have separate assembly for interfaces and another assembly for Entity Framework.
How can I move repository interface to another assembly?
In addition, I would like to be able in future to keep the database schema in sync with the EF Core model by preserving data.
I use DatabaseFirst. Thank in advance. Any help would be greatly appreciated!