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.