Created
March 17, 2019 06:58
-
-
Save dealproc/3ad96e34f94549e7d94530c932c4175c to your computer and use it in GitHub Desktop.
Multi-Tenant Solutions - NancyContextAccountAccessor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment