I'm trying to put it all together for an new architecture for existing application. Existing application has a lot of business logic, so I thought that Onion architecture (or something like that - layered, decoupled) could be the right solution - http://jeffreypalermo.com/blog/the-onion-architecture-part-1/
All examples that I have seen use Repo/UoW (on top or ORM) pattern in Infrastructure layer (or DAL, or whatever the layer that actually connects to database is called). But I'm not sure that in my case Repo/UoW (on top of EF) is necessary, because:
EF6 can be nicely Unit Tested without Repo pattern with implementing Bounded DbContexts like this - http://msdn.microsoft.com/en-us/library/dn314429.aspx
Most Generic Repo examples tend to use leaky abstractions, because they expose methods that accept LINQ queries (like Expression> query)
- Non-generic Repos tend to cause a lot of code
So here are a few questions:
1) Most examples use EF code first and POCO objects in Core layer, but I have to use database first and generate model. Can I use EF generated .edmx model in Core, or does this makes unnecessary coupling to data access? Is there a way to split EF generated classes (.cs files with Table fields) from EF generated data access code (context.tt files etc.)?
2) I'm planning to implement Service layer like this (with Bounded DbContext interfaces being passed as dependencies)
public class OrderService(IMyDbContext) { ... }
This means, that instead of Repository Interfaces, there will be DbContext wrapper interfaces with DbSets. Unit testing could be done with mock IMyDbContext and mock IDataSet. Doesn't this beat the whole concept of abstracting away the database? Seems to me that this is enough for unit testing, but is this ok from architectural standpoint? Am I missing some great feature that Repo/UoW (on top of EF) pattern provides here?
3) Seems that one alternative for Repositories (although, not very popular) are Query Objects: http://www.wekeroad.com/2014/03/04/repositories-and-unitofwork-are-not-a-good-idea/
http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/
But I haven't really found any examples with Onion + Query Objects. Could this be reasonable choice for Repository interface layer? Placing Query interfaces there instead, and Query Implementations in Interface (Data Access) layer? Should I place all data access logic inside QueryObjects? If I use DbContext.Where queries directly in Coltroller/Service layer, does this create unnecessary coupling between Data Access and Business Logic?