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 static ILogger Logger ... private static ICache Cache ... private static IAccountsService Service ... private static IMapper ViewModelMapper ... private const string CacheKey = "Accounts"; public static AccountViewModel[] LoadAccounts() { try { if (Redis.TryGet(CacheKey, out var cached)) return cached; var accounts = Service.GetAccounts(); var vms = ViewModelMapper.Map<AccountViewModel[]>(accounts); Redis.Set(CacheKey, vms); return vms; } catch (Exception ex) { Logger.Error(ex); 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 ambigious.
How is this layer usually called?