Ive been struggling with this for like some time. If you do an architecture like this..
Project.Domain
- Entities
- Repositories interfaces Project.Persistence.EF
- Repositories
- ContextProvider
- etc..
Project.Persistence.SQL
???
Project.Tasks
...
Project.Presentation
...
With an IoC you can almost change any components for others components.. The important interface here which is related to the question is IRepository (Generic) located at the domain. That only the definition, not the implementation.
The main problem i was looking at is How i can switch EF for SQL in almost no time ?
If you look at the repository interface.. it is intended to work with a context obviously.
public interface IRepository<T> where T : class
{
void Add(T entity);
void Delete(T entity);
T GetById(long Id);
}
How i can then make this repository to work also with an SQL implementation so i can use a IoC to choose betwen EF and SQL ?
Sure i could make IRepositorySQL and IRepositoryEF but then i wouldnt be able to use an IoC for this... and im stuck again.
Any ideas or suggestion or way to do things ?
Thanks.