title: WCF ServiceAuthorizationManager dependency injection
body: <p>I made a small class that inherits ServiceAuthorizationManager in order to implement basic HTTP authentication in WCF REST api. It works, but at the same time it violates SOLID principles. Is there a way to inject dependencies to this class through a constructor? The DI container of my choice is Autofac.</p>
  
  <p>Full code:</p>
  
  <pre><code>public class RestAuthorizationManager : ServiceAuthorizationManager
  {
      private readonly string _correctUserName;
      private readonly string _correctPasswordHash;
  
      public RestAuthorizationManager()
      {
          _correctUserName = ConfigurationManager.AppSettings["User"];
          _correctPasswordHash = ConfigurationManager.AppSettings["PasswordHash"];
      }
  
      protected override bool CheckAccessCore(OperationContext operationContext)
      {
          if (WebOperationContext.Current != null)
          {
              var authHeader = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];
              if (!string.IsNullOrEmpty(authHeader))
              {
                  var svcCredentials = Encoding.ASCII.GetString(Convert.FromBase64String(authHeader.Substring(6))).Split(':');
                  var user = new { Name = svcCredentials[0], Password = svcCredentials[1] };
  
                  if (user.Name == _correctUserName &amp;&amp; GetHash(user.Password) == _correctPasswordHash)
                  {
                      return true;
                  }
                  return false;
              }
          }
          if (WebOperationContext.Current != null)
          {
              WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authenticate: Basic realm=\"Enter your password\"");
              WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Unauthorized;
              return false;
          }
          throw new WebFaultException(HttpStatusCode.Unauthorized);
      }
  
      private static string GetHash(string stringToHash)
      {
          byte[] passwordBytes = Encoding.ASCII.GetBytes(stringToHash);
          using (var sha1 = new SHA1Managed())
          {
              var hash = sha1.ComputeHash(passwordBytes);
              return Convert.ToBase64String(hash);
          }
      }
  }
  </code></pre>