Answer the question
In order to leave comments, you need to log in
How to pass context from one assembly to another?
Hello! Right now I'll try to formulate the question.
I want to make a library for working with EF so that other libraries (projects) can use it without depending on EF. I can't figure out how to pass all domain entities to the context of my EF library.
For example:
created a new solution in it created three libraries (layers)
Myproject.Domain,
Myproject.Domain.EF,
Myproject.UI.
In "Myproject.Domain.EF" where I need to work with EF, I do not connect EF, but I connect my library in which there is a dependency on EF.
But how do I pass all the entities of the new project to the context (DbContext) of my library for working with EF.
public class EFDbContext : DbContext
{
DbSet<User> Users; <--
DbSet<Role> Roles; <--
}
Answer the question
In order to leave comments, you need to log in
No way, you want to use EF classes without connecting EF, this will not work, C # is a strongly typed language and must always clearly understand what it works with. If you want to isolate, you will have to make an intermediate class that both the library and the application will know, in which there is no dependence on EF, that is, pass raw data through it. In any case, such an approach is a terrible crutch that completely erases all the advantages of EF for which it was created. No crutches needed, just connect the dependencies to the application.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question