Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: hybrid binding not working for me without attributes #56

Open
feanz opened this issue Sep 9, 2021 · 1 comment
Open

Question: hybrid binding not working for me without attributes #56

feanz opened this issue Sep 9, 2021 · 1 comment

Comments

@feanz
Copy link

feanz commented Sep 9, 2021

Hi I may be using the package incorrectly but I am trying to create API endpoints with a single object and bind from the body and the route to my single object. Reading the documentation I assume for my situation if I installed the package and added it in Startup when configuring services my scenario would work out the box without any additional decoration. I have a endpoint like this

``

    [HttpPost("todolist/{listId}/todo")]
    public async Task<ActionResult> CreateTodo(CreateTodoItemCommand command)
    {
        //some code
    }

``

My command object looks like this

``

public class CreateTodoItemCommand : IRequest
{
public int ListId { get; set; }

    public string Title { get; set; } = string.Empty;
    
    public string Note { get; set; } = string.Empty;
}

``

Title and note are bound from the body of the request and I want ListId to be bound from the route. I had assumed as I had a single source for each property I would not need additional binding attributes on either the controller method or the contract. However this does not work and ListId is never bound. Title and Note are bound without issue. I have tried playing around with global fallback order but this does not seem to do anything. The only way I can get this to work is to add the HybridBindProperty with a source of route on the ListId property.

Ideally I dont want to add a reference to hybridbinding into my contract repository and did not think I would need to in this simple use case. The documents seem to suggest that if you have a single object on the controller method and that the standard order for binding is acceptable this should just work. Am I doing something wrong or is my scenario not supported. Any help is much appreciated. Regards

@billbogaiv
Copy link
Owner

billbogaiv commented Sep 15, 2021

May you post a sample project as a ZIP-file? I can't duplicate this particular problem... I'm using the sample project from this repo. and made some modifications based on your explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants