I'm trying to write some business logic for my app. At the core of my app are EF generated entities from Database First model. I have separated generated classes (.tt file ) from .edmx part.
I want to find the best place where to put my business logic, but the problem is, that business logic requires some complicated dependencies, for example, needs logging, calls some WebService, or makes pure SQL calls to DB. Because of that, I can't just use new() inside functions and create hard dependencies, but I want to somehow abstract away from them, following DI principles.
public class Person
{
public Person(IDbCaller dbCaller, IWebServiceCaller webServiceCaller) { }
}
My first bet was to use partial classes, that extend EF classes.
But after reading some articles, I am now thinking that injecting dependencies into EF classes is not a good idea:
Why not use an IoC container to resolve dependencies for entities/business objects?
http://lostechies.com/jimmybogard/2010/04/14/injecting-services-into-entities/
So, where should I put this logic? I agree, that dependencies on EF entities are bad, but I cant really find solutions. Logic needs to be somewhere. I see a few options/questions:
1) Put business logic (that requires dependencies) inside Service layers. This could lead to Anemic Domain Model, but maybe Service layers are the right place for this kind of logic, that requires dependencies?
2) Create some king or Wrapper/Factory classes, that I need to call every time query returns entities, so I can wrap entity with business logic.
3) Put that logic inside some other classes, that take entity as a function parameter.
What are some good, common practices for this?