davezych / shience

A .NET port(ish) of Github's Scientist library. (https://github.com/github/scientist)
MIT License
9 stars 1 forks source link

Provide a fluent interface #8

Closed MovGP0 closed 8 years ago

MovGP0 commented 8 years ago

As a personal opinion, there should be a fluent interface like the StringBuilder and many modern libraries like Polly have.

Shience.SetPublisher(new FilePublisher(@"C:\file\path\to\results.txt"));

var userCanRead = Shience.New<bool>("widget-permissions")
    .Setup(() => ...)
    .Test(
        control: (() => return UserPermissions.CheckUser(currentUser); ), 
        candidate: (() => return User.Can(currentUser, Permission.Read); )
    )
    .WithComparer(new PermissionComparer())
    .When(() => if-condition)
    .WithContext(new { ... })
    .TestPercentage(0.3d)
    .PublishTo(result => ...)
    .Execute(); 

if(userCanRead)
{
    //do things!
}

The advantage of this is that it becomes way easier to extend and maintain the interface. Also, the code for setting up an Scientist (extensions) can be separated from the Scientist (state) into different classes.

The user profits because the order of the properties becomes less important and the improved Auto Complete experience.

davezych commented 8 years ago

I agree, and is something I had been considering more and more.

Up for grabs if you want it, otherwise I'll look into it soon.

davezych commented 8 years ago

I have some time today, I'll start this now...

MovGP0 commented 8 years ago

oh. obviously we both worked on the same item...

davezych commented 8 years ago

Implemented in #13. Closing.