Skip to content

Support custom feature context #52

Description

@sagikazarmark

Is your feature request related to a problem? Please describe.
The context is great for primitive types, but not that great for complex types:

myService := ctx.Get("myservice").(*MyService)
myOtherService := ctx.Get("myotherservice").(*MyOtherService)

Describe the solution you'd like
It would be nice if the step function could accept an arbitrary contex and "unmarshal" the internal context on it. For example, by having to implement an Unmarshal function on the struct:

type MyFeatureContext struct {
    MyService Service
}

func (c *MyFeatureContext) UnmarshalContext(ctx context.Context) {
   c.MyService = ctx.Get("myservice").(*Service)
}

Although this is not so much different from getting the values directly from the context, it keeps the step functions relatively clean.

Describe alternatives you've considered

As a practice, the following could work, minimizing the work on both ends:

myContext := ctx.Get("mycontext").(*MyContext)

myContext.MyService.Do()

This could even go to the documentation if it sounds an acceptable practice (not sure yet to be honest).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions