Use Typed Context for all Tasks
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.
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 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?
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
Yes, the ability to pass multiple typed contexts into a task.
Ooo, interesting...
That could be exactly what I am looking for!
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.