scientistproject / Scientist.net

A .NET library for carefully refactoring critical paths. It's a port of GitHub's Ruby Scientist library
MIT License
1.46k stars 95 forks source link

Return results from experiment #124

Closed paulbreen closed 1 year ago

paulbreen commented 5 years ago

Scientist is designed to always return results from the control, however during development I have found it helpful to return the result from the candidate rather than the control, i.e. during design and debugging an issue etc.

The following PR exposes a delegate that will can effectively ignore the control and return the result from the first candidate. It has similar affects to turning off Scientist i.e. no comparison reports are generated, no over head etc

using GitHub;

...

public void ScientistSetup(){
   Scientist.EnabledControl(() => !HostingEnvironment.IsDevelopmentEnvironment);
}

public bool UseExperimentResult(IUser user)
{
    return Scientist.Science<bool>("widget-permissions", experiment =>
    {
        experiment.Use(() => IsCollaborator(user)); // control
        experiment.Try(() => HasAccess(user)); // candidate
    }); // returns the candidate value
}