I have ASP.NET MVC application with the following controller and action:
public class AccountsController
{
public ActionResult Index()
{
var accounts = _accountsManager.GetAccounts();
return View(accounts);
}
}
and AccountsManager
class like this:
public class AccountsManager
{
private ILogger Logger ...
private ICache Cache ...
private IAccountsService Service ...
private IMapper ViewModelMapper ...
private const string CacheKey = "Accounts";
public AccountViewModel[] LoadAccounts()
{
try
{
if (Redis.TryGet(CacheKey, out var cached)) // Cache
return cached;
var accounts = Service.GetAccounts(); // Call service
var vms = ViewModelMapper.Map<AccountViewModel[]>(accounts); // Map result
Redis.Set(CacheKey, vms); // Update cache
return vms;
}
catch (Exception ex)
{
Logger.Error(ex); // Log exceptions
throw;
}
}
}
So, this AccountsManager
class removes code duplication and encapsulates the following logic:
- Communication with back-end
- Resolving dependencies
- Caching
- Logging
- Error handling
- ViewModel mapping
- Request retrying, service auth etc.
However, calling this classes XXXManager
makes me feel uncomfortable since this word Manager
is ambiguous.
How is this layer usually called?
Application Service Layer
in the past. I don't know how common that is, though. – MetaFight Nov 17 '17 at 10:34