Cake.Recipe icon indicating copy to clipboard operation
Cake.Recipe copied to clipboard

Use Typed Context for all Tasks

Open gep13 opened this issue 5 years ago • 5 comments

Currently, Cake.Recipe makes use of a static BuildParameters class to hold of the build time information.

Cake now has the concept of Typed Contexts, which makes it possible to create an instance of a class, which all tasks have access to, rather than having a static class instance.

Cake.Recipe should switch to using this where possible. It already has a partial implementation of this, but it would be good to completely remove the BuildParameters class.

gep13 avatar Jul 11 '20 16:07 gep13

IMHO BuildParameters currently contains two different things:

  • Input paramters
  • Build state

The second should go into a typed context. But for input a static BuildParameters class still can make sense. This would also lead to a clear separation between parameters and state.

pascalberger avatar Jul 11 '20 16:07 pascalberger

@pascalberger that is a fair point.

While you are here, I am assuming that it isn’t possible to do this:

Task(“Default”)
.Does<BuilldVersion, BuildData>((context, buildVersion, buildData) => {
});

Or is it?

gep13 avatar Jul 11 '20 17:07 gep13

Passing multiple typed context to a task?

I don't think there's an extension in Cake for this. But you can just use context.Data.Get() directly which the Does extension basically wraps: https://github.com/cake-build/cake/blob/7022572d5b151814172662d0500d6969041ca91e/src/Cake.Core/CakeTaskBuilder.Execution.cs#L168

pascalberger avatar Jul 11 '20 17:07 pascalberger

Yes, the ability to pass multiple typed contexts into a task.

Ooo, interesting...

That could be exactly what I am looking for!

gep13 avatar Jul 11 '20 17:07 gep13

We should also have documentation for advanced typed context scenarios on the website. I created https://github.com/cake-build/website/issues/934 for this.

pascalberger avatar Jul 11 '20 17:07 pascalberger