Skip to content

Instantly share code, notes, and snippets.

@cbanner
Created December 29, 2018 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbanner/62de4c3b05f62cec91dff8f259acf0f9 to your computer and use it in GitHub Desktop.
Save cbanner/62de4c3b05f62cec91dff8f259acf0f9 to your computer and use it in GitHub Desktop.
Part 3: Pseudo code demonstrating the final phase of how to isolate logging components through decoration.
public interface IAuthenticationStep
{
bool IsAuthentic(HttpRequest request);
}
public class LoggingAuthenticationStep : IAuthenticationStep
{
private readonly ILogger logger;
private readonly IAuthenticationStep inner;
public LoggingAuthenticationStep(ILogger logger, IAuthenticationStep inner)
{
this.logger = logger;
this.inner = inner;
}
public bool IsAuthentic(HttpRequest request)
{
this.logger.Trace($"Beginning authentication step: {typeof(this.inner).FullName}");
var result = this.inner.IsAuthentic(request);
this.logger.Trace($"Step found request to be authentic: {result}");
return result;
}
}
public class SignatureAuthenticationProcedure : IAuthenticationProcedure
{
private readonly IEnumerable<IAuthenticationSteps> authenticationSteps;
public SignatureAuthenticationProcedure(IEnumerable<IAuthenticationStep> authenticationSteps)
{
this.authenticationSteps = authenticationSteps;
}
public AuthenticationResult Authenticate(HttpRequest request)
{
return this.authenticationSteps.All(step => step.IsAuthentic(request));
}
}
public class SignatureVerificationStep : IAuthenticationStep
{
public bool IsAuthentic(HttpRequest request)
{
// ...
}
}
public class TimestampAuthenticationStep : IAuthenticationStep
{
public bool IsAuthentic(HttpRequest request)
{
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment