Skip to content
This repository was archived by the owner on Jul 20, 2020. It is now read-only.
This repository was archived by the owner on Jul 20, 2020. It is now read-only.

Accessing Root object when creating links in embbedded items #12

@danice

Description

@danice

To define links in embbedded items frequently is neccessary to have access to parent node info.

For example if we have a "folder" resource with a "self" link [folder], usually each of its items will have a "self" link as [folder]/[item]. To generate each item "self" link it needs all info in its parent object.

What I propose is to use the same

.Links((model, context) =>

,but extending context to not only contain NancyContext, but to be "custom" a HalContext with

public class HalContext
{
    public NancyContext NancyContext { get; set; }
    public Object Root { get; set; }
}

To mantain compatibiltiy with existing code we could have something like

public HalTypeConfiguration<T> Links(Func<T, NancyContext, Link> linkGetter)
{
    Func<T, HalContext, Link> halLinkGetter = (t, context) => linkGetter(t,context.Nancy);
    AddLinkFn(halLinkGetter);
    return this;
}

What do you think?
...and of course, i'm not asking you to do this.. i could implement this (or the solution proposed) myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions