Binding child objects with default model binder issues

Showing 1-4 of 4 messages
Binding child objects with default model binder issues Richard Andrews 7/25/12 5:14 AM

We are having an issue with Nancy's default model binder. Given the below...

public class Foo
{
    public Foo()
    {
    }

    public string Name { get; set; }

    public Bar Bar { get; set; }
}

public class Bar
{
    public string Name { get; set; }
}

with elements like...

<input type="text" value="Name" />
<input type="text" value="Bar.Name" />

With the default model binder used like so..

var foo = this.Bind<Foo>();

This correctly binds Foo.Name but fails to bind Foo.Bar.Name

Is there a way to enable this kind of binding with the default binder or do we need to roll our own? If so are there any good examples?

Re: [nancy-dev] Binding child objects with default model binder issues João Bragança 7/25/12 11:05 AM
I ran into a similar issue. The default model binder assumes a 'flat'
class with public setters. You're gonna have to roll your own. That
being said it's pretty straightfoward
Re: [nancy-dev] Binding child objects with default model binder issues Andreas Håkansson 7/25/12 1:17 PM
Guys... if this is something that more and more people are bumping their heads against then perhaps we should update (pull request?) the default one to support child types?
Re: [nancy-dev] Binding child objects with default model binder issues Sunny 7/26/12 6:37 AM
Strictly speaking, there should be a DTO to represent the outside
communications - i.e. flat structure with all properties, which Nancy
supports. Then, if your internal object model is more complicated, use
Automapper or manual map.

It's always a bad idea to expose your internal domain structures to
the wide world.

Just 2c

Cheers,
Sunny
--
Svetoslav Milenov (Sunny)

Artificial Intelligence is no match for natural stupidity.