I'm using an ORM which doesn't allow me to inject dependencies in the constructor. Let's say I'm using DDD for the business logic, and the MVC pattern for the UI.
Now one of my domain objects needs to access an external service. I'm very opposed to the service locator anti-pattern (wouldn't touch it with a ten foot pole), but as I see it, that leaves me with the following:
class Controller
{
private readonly IExternalService _externalService;
public Controller(IExternalService externalService)
{
_externalService = externalService;
}
public ViewResult Action(Guid Id)
{
// Omitted repository access for brevity.
domainObject.DoSomethingWichNeedsAnExternalService(_externalService);
}
}
Somehow I get the feeling this isn't very clean, what if the "domainObject" is buried deep into the model/graph, should the "_externalService" be passed all the way down?
Are there any best-practice alternatives?