Live data from Hacker News

Show HN: Mapperly – A .NET source generator for object to object mappings

github.com

11–20 of 71 posts

Re: Show HN: Mapperly – A .NET source generator for object to object mappings

#11

Why not just have no mappings and reuse the same objects?

It can be useful to distinguish between domain objects and objects that you use at the edge of your service, like on the API. They might have different annotations or you might want to evolve them differently, e.g. your domain objects might change while you want to keep your API the same so as not to break your consumers. Things like that.

Re: Show HN: Mapperly – A .NET source generator for object to object mappings

#12
It is sad we still live in the enterprise world where having both "SomeClass" and "SomeClassEntity" isn't grounds for rejecting a PR that dares to do this.

Therefore, thank you for making this. Automapping is a sign of incorrect abstractions and unarguably bad solution architecture but since we are still forced to deal with such, doing so with speed and without reflection is always welcome.

Re: Show HN: Mapperly – A .NET source generator for object to object mappings

#13

Why not just have no mappings and reuse the same objects?

So you are happy with the same class that is used to represent the row in the database including potentially sensitive data also being used in responses to API calls?

Re: Show HN: Mapperly – A .NET source generator for object to object mappings

#15
I like how everyone here and the repo’s readme talks about performance as if the problem with Automapper was the fact that it was making your enterprise app that waits N seconds for a db query and relies on caching to be even remotely usable, slow.

The problem with automapper is that it throws the compiler out the window and invites all the bugs that would normally not be there.

Mapping code is still your code and should receive the same care as your fancy services.

I hate automapper, and I hate this too, just less because at least it has the potential to catch bugs at compile time… I think.

Some people really want to write libraries, I guess.

Re: Show HN: Mapperly – A .NET source generator for object to object mappings

#16

Why not just have no mappings and reuse the same objects?

So you are happy with the same class that is used to represent the row in the database including potentially sensitive data also being used in responses to API calls?

or better yet, directly in GUI layer :)

Re: Show HN: Mapperly – A .NET source generator for object to object mappings

#17
post #8

Something that should not be needed was just improved.

> was just improved That’s yet to be seen, otherwise I wholeheartedly agree with your statement :)

If a type can't be mapped this should now fail at compile time instead of at runtime - which is an improvement.

I can understand that this might be intrieging for newcomers. I've certainly learned the hard way that the only thing worse than manually writing mapping code is doing it automatically at runtime.

Re: Show HN: Mapperly – A .NET source generator for object to object mappings

#18

It is sad we still live in the enterprise world where having both "SomeClass" and "SomeClassEntity" isn't grounds for rejecting a PR that dares to do this. Therefore, thank you for making this. Automapping is a sign of incorrect abstractions and unarguably bad solution architecture but since we are still forced to deal with such, doing so with speed and without reflection is always welcome.

In many cases DbModel is not exactly the same as AppModel and ViewModel. In typed programming languages automappers are rather useful.

> without reflection

Source generators are not reflection.

Re: Show HN: Mapperly – A .NET source generator for object to object mappings

#19

I've never really understood the use case for these mapping generators. Every time I've seen them used (MapStruct in Java, AutoMapper in C#) the mapping configuration eventually ends up being so complex that just manually writing out the mapping would've been just as simple and arguably simpler to understand.

In webapps it's often very useful to accept a subset of a domain entity as an APIs request body, or to return it as a response body.

It's nice having separate classes to describe the request & response bodies because this lets you automatically generate OpenAPI descriptors which can then be used for client generation and so on.

When your domain objects are small it's easy to just manually copy the data between your domain entities and request & response objects. Once your objects grow it's convenient to just automate the mapping in a way that still gives you compile-time correctness checks.

Re: Show HN: Mapperly – A .NET source generator for object to object mappings

#20

It is sad we still live in the enterprise world where having both "SomeClass" and "SomeClassEntity" isn't grounds for rejecting a PR that dares to do this. Therefore, thank you for making this. Automapping is a sign of incorrect abstractions and unarguably bad solution architecture but since we are still forced to deal with such, doing so with speed and without reflection is always welcome.

I'm curious, why would this be bad? I've generally always seen it as best practice to create classes in your domain model and try to write your ideal code and then have separate classes/DTOs that are used for communicating outside your domain model such as reading/writing to a database using an ORM or responding from an API with your ideal model for the consumer (since more often than not consumers don't need or want all of the cruft inside the domain model and your DB will likely have stored the information in a different format in a large system). I always love thinking of ways to simplify architecture though and I absolutely hate having classes/records that looks so similar though so I'm intrigued about a simpler solution if there is one? Domain Driven Design practices really encourage a bloated/complex architecture so I try to avoid it if possible but more often than not business requirements end up becoming so complex that I immediately fall back to those abstractions when the logic starts to get complex.
Post reply on HN