Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NancyContextAccountAccessor : IAccountAccessor {
- static readonly ILog _log = LogProvider.For<NancyContextAccountAccessor>();
- readonly IAccountRepository _accountRepository;
- readonly NancyContext _nancyContext;
- public NancyContextAccountAccessor(IAccountRepository accountRepository, NancyContext nancyContext) {
- _accountRepository = accountRepository;
- _nancyContext = nancyContext;
- }
- public Account GetCurrentAccount() {
- var hostName = _nancyContext.Request.Url.HostName;
- _log.DebugFormat("Hostname resolved from nancy context `{hostName}`", hostName);
- var account = _accountRepository.GetFirst(x => x.Hostname.ToLower() == hostName);
- if (account == null) {
- _log.WarnFormat("Account was not found in the system for `{hostName}`", hostName);
- throw new UnknownAccountException(3, string.Format("Hostname: {0} has not been registered.", hostName));
- }
- return account;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement