SkywardApps / popcorn

Popcorn is a .Net Middleware for your RESTful API that allows your consumers to request exactly as much or as little as they need, with no effort from you.
https://skywardapps.github.io/popcorn/
MIT License
59 stars 19 forks source link

We need an attribute that designates that one type can map from another #33

Closed undiwahn closed 6 years ago

undiwahn commented 6 years ago

We get a lot of mapping boilerplate lines when using simple maps that don't require much customization.

eg

config.Map<Car,CarProjection>();
config.Map<Employee,EmployeeProjection>();
...

Ideally, we want an attribute that you can apply that designates something as the target of a mapping. So for example:

[ExpandFrom(typeof(Car), "[My,Default,Includes]"]
class CarProjections {
...
}

This means that we need a new method on PopcornConfiguration called something like 'ScanAssemblyForMapping' that will look for all class types within an assembly that have the [ExpandFrom] attribute applied, and automatically register them.

alexbarbato commented 6 years ago

Did we want to be able to declare a set of Default includes with the ExpandFrom attribute? Does seem like this could create conflicts with the default include attribute.

undiwahn commented 6 years ago

I think the idea was that it would replace the manual Map<> call entirely. Since you can optionally provide an include list to the Map<> call, you should be able to optionally provide an include list to the attribute.

On Oct 29, 2017 6:56 PM, "alexbarbato" notifications@github.com wrote:

Did we want to be able to declare a set of Default includes with the ExpandFrom attribute? Does seem like this could create conflicts with the default include attribute.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SkywardApps/popcorn/issues/33#issuecomment-340310064, or mute the thread https://github.com/notifications/unsubscribe-auth/AJNm3pIZeZKRsXFjyb-A0qEDJI7SrTrBks5sxQKigaJpZM4QIO_7 .

undiwahn commented 6 years ago

( and you are correct about the conflict; it's the same as between the Map<> call and the DefaultInclude attribute. So it should also throw an exception if you try to provide both )

On Oct 29, 2017 7:01 PM, "Nick Elliott" nelliott@skywardapps.com wrote:

I think the idea was that it would replace the manual Map<> call entirely. Since you can optionally provide an include list to the Map<> call, you should be able to optionally provide an include list to the attribute.

On Oct 29, 2017 6:56 PM, "alexbarbato" notifications@github.com wrote:

Did we want to be able to declare a set of Default includes with the ExpandFrom attribute? Does seem like this could create conflicts with the default include attribute.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SkywardApps/popcorn/issues/33#issuecomment-340310064, or mute the thread https://github.com/notifications/unsubscribe-auth/AJNm3pIZeZKRsXFjyb-A0qEDJI7SrTrBks5sxQKigaJpZM4QIO_7 .

undiwahn commented 6 years ago

Closed with PR #36