vendredi 11 décembre 2015

Dependency Injection, Factory or neither

I have a web application with Web, Business Logic and Data Access layers (all separate projects).

MyProject.Web
    /Controllers
    /Views
    ...
MyProject.BusinessLogic
    /Contracts
    /Services <-- implementations
    ...
MyProject.DataAccess
    /Contracts
    /Repositories
    ...

In the service layer, for example, I have interfaces for services as well as concrete implementations. In the Web project I inject services defined in BusinessLogic layer.

Now, I have a caching service (both contract & implementation) in the BusinessLogic that is going to be used only in that project. Should I dependency-inject the caching service even though the composition root is in the Web project? (Or should I just use a Factory pattern instead?) Right now in the BusinessLogic project I have

private readonly ICacheService _cacheService = new CacheService();

but this feels wrong to me. Any suggestions?

Aucun commentaire:

Enregistrer un commentaire