hal icon indicating copy to clipboard operation
hal copied to clipboard

Ability to add multiples resources with fluent API

Open kevingeorget opened this issue 1 year ago • 0 comments

Hello @daxnet ! First of all, thank you for this library (:

From the IEmbeddedResourceBuilder, the fluent API seems to expose a Resource method that only accepts one ResourceBuilder as argument:

var resource = new ResourceBuilder()
            .WithState(new { count = 4 })
            .AddSelfLink()
            .WithLinkItem(
                $"{Configuration.AppBaseUrl()}/{Endpoints.MyRaceEvents}",
                "Race Events Registrations"
            )
            .AddEmbedded("raceEventRegistrations")
            .Resource(new ResourceBuilder().WithState(new {id = 1}))
            .Resource(new ResourceBuilder().WithState(new {id = 2}))
            .Resource(new ResourceBuilder().WithState(new {id = 3}))
            .Resource(new ResourceBuilder().WithState(new {id = 4}))
            .Build();

Let's say i have a collection of entities i want to embed to the Hal resource. I can't achieve an elegant way to simply add several resources to my embedded resource collection from a list.

I'd like to achieve something like this :

var resource = new ResourceBuilder()
            .WithState(new { count = registrations.Count })
            .AddSelfLink()
            .WithLinkItem(
                $"{Configuration.AppBaseUrl()}/{Endpoints.MyRaceEvents}",
                "Race Events Registrations"
            )
            .AddEmbedded("raceEventRegistrations")
            .Resources(
                registrations.Select(r => new ResourceBuilder().WithState(new { id = r.Id }))
            )
            .Build();

Did I miss something ?

Thank you in advance

kevingeorget avatar Nov 01 '24 07:11 kevingeorget