Skip to content

Instantly share code, notes, and snippets.

@CoditCompany
Last active July 12, 2019 06:47
Show Gist options
  • Save CoditCompany/53abd555a53c39ec0bf025971dd31bdf to your computer and use it in GitHub Desktop.
Save CoditCompany/53abd555a53c39ec0bf025971dd31bdf to your computer and use it in GitHub Desktop.
// Specification before the actual check of the base-uri.
Spec<Uri> spec =
Spec.Of<Uri>()
.Add(uri => uri.Scheme == Uri.UriSchemeHttps, "should be 'https' scheme");
// Demonstration purposes, generic type could be anything.
IObservable<T> obs = null;
// Access controlled function with validation, revocation, limited amount of evaluations and time-based availability.
Access<Uri, Uri> access =
Access.OnlyUriFromBase(new Uri("https://localhost:9090/"))
.Satisfy(spec)
.Once()
.DuringHours(9, 17)
.RevokedWhen(obs);
// Somewhere else...
AccessResult<Uri> result = access.Eval(new Uri("http://localhost:9090/path"));
if (result.TryGetValue(out Uri output))
{
// use the now correct 'output'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment