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

Add Automapper support #106

Open
glennblock opened this issue Nov 30, 2014 · 15 comments
Open

Add Automapper support #106

glennblock opened this issue Nov 30, 2014 · 15 comments

Comments

@glennblock
Copy link
Member

I've seen a bunch of feedback from folks (lie @AlexZeitler) feeling it is too painful to have to implement document readers and writers. So I am thinking to just add Automapper support in the box (though possible as an add-on for those that don't want it).

  1. By default it would have some simple out of the box mapping rules.
  2. For more advanced cases would be able to customize the Automapper mapping.

The goal would be to reuse the existing abstractions (reader/writer), but you would have a strongly typed MappedReadDocument<T> / MappedWriteDocument<T> or something.

Thoughts on if this is worthwhile / and if so what you'd like to see done? I am definitely NOT the AM expert :-)

@AlexZeitler
Copy link
Member

Good to see you're thinking about AM-Support. Would be good if you spin up an "internal" instance of the AM MappingEngine as otherwise mappings might conflict with definitions used by the Mapper static instance provided by AM by default.

@glennblock
Copy link
Member Author

@AlexZeitler thanks, well you had something to do with it :-) Do you think it makes sense? Would it satisfy your needs if for example you could register say a generic MappingReadDocument<>, MappingReadDocument<> for handling the default cases, and then register specific closed ones for cases where you need to control the configuration? Or would you prefer a diff approach?

@glennblock
Copy link
Member Author

Gotcha on the internal instance. Would it make sense to allow one to pass in their own instance?

@AlexZeitler
Copy link
Member

At the moment I don't see a real advantage of being able to pass in my own instance. Also you could use configuration.Initialize() (if not passing in a custom instance) which improves mapping perf if im not totally wrong.

WRT to MappingReadDocument<>: it would make sense.

On the other hand, as already explained, the key issue for the team (I've been working with as an external) with the Reader / Writer approach is the dependency on CJ inside the controllers.

Don't you see scenarios where it makes sense to provide an API serving e.g. CJ and HAL in parallel?
If not, why? If yes, how would you deal with that?

@glennblock
Copy link
Member Author

@AlexZeitler I do see that would be valuable. But document reader and writer are interfaces deliberately. There's no problem having a single class implement both interfaces / be an adapter. I am not a huge fan of the idea of one generic interface to rule them all as I believe it will end up as a leaky abstraction and media types vary greatly.

@AlexZeitler
Copy link
Member

What do you think of a base class that provides support for all H-Factors and a concrete impl. maps the factors to the concrete HM type?

I think it is difficult to provide the HM generation in a generic manner especially when it comes to linking that requires problem domain context (e.g. paging).

@glennblock
Copy link
Member Author

This is what The Hypermedia Project is attempting (in multiple languages).
Basically providing a way to express H-Factors and then have utilities to
then express those in whatever format you like. Having been doing similar
roads in the past, I am a skeptic. I think it is possible, but that it will
get very ugly.

On Sat Nov 29 2014 at 6:44:40 PM Alexander Zeitler [email protected]
wrote:

What do you think of a base class that provides support for all H-Factors
and a concrete impl. maps the factors to the concrete HM type?

I think it is difficult to provide the HM generation in a generic manner
especially when it comes to linking that requires problem domain context
(e.g. paging).


Reply to this email directly or view it on GitHub
#106 (comment)
.

@glennblock
Copy link
Member Author

@AlexZeitler I am part of The Hypermedia Project because this is something they are focusing on and though I am skeptical, I am willing to be proven wrong. If it turns out I am, I'll gladly be more willing to embrace :-)

@AlexZeitler
Copy link
Member

For Web API I've a rough idea how it could be solved using AM and a IoC-Container, but I dunno about Nancy.=

@glennblock
Copy link
Member Author

@AlexZeitler @jchannon has it working currently with my library for Nancy. He wrote Nancy.CollectionJson for this purpose.

@glennblock
Copy link
Member Author

@AlexZeitler you mean how you can solve having the one model to rule them all?

@AlexZeitler
Copy link
Member

yes.

@glennblock
Copy link
Member Author

@AlexZeitler well if you look at The Hypermedia Project they already have it. Just hasn't been ported to .NET yet.

@AlexZeitler
Copy link
Member

Is HyperMedia project != DotNetHyperMedia project? Do you have a link?

@glennblock
Copy link
Member Author

Not the same. The first has been around for 6 months. It started when a bunch of us were at Api Craft in Chicago. https://github.com/the-hypermedia-project/charter

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

No branches or pull requests

2 participants