Created
December 29, 2018 17:58
-
-
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.
This file contains 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 interface IAuthenticationStep | |
{ | |
bool IsAuthentic(HttpRequest request); | |
} |
This file contains 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 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; | |
} | |
} |
This file contains 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 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)); | |
} | |
} |
This file contains 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 SignatureVerificationStep : IAuthenticationStep | |
{ | |
public bool IsAuthentic(HttpRequest request) | |
{ | |
// ... | |
} | |
} |
This file contains 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 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