mardi 24 mars 2015

Dependency Injection with EF - is mapping required?


I'm implementing the Repository pattern with using DI and EF6.


I created the database (that inherits from DbContext) object with the Visual Studio wizard ADO.NET Entity Data Model


I have a generic IRepository<T> in my domain assembly, and its implementation in different assemblies based on the data source.


The problems come with the mapping objects from the EF to the domain objects: almost all of my code is writing things like



private Sql.Database.Cat Map(Domain.Data.Cat cat)
{
return new Sql.Database.Cat
{
Species = cat.Species,
Legs = cat.Legs,
...
}
}


and the opposite of course. The mapping creates a big amount of problems, eg updating, but it is necessary in order not to add the Sql.Database dll as a dependency in the UI assembly.


Is there a way not to have to map objects and not having the EF assembly as a dependency as well?





Aucun commentaire:

Enregistrer un commentaire