-
Notifications
You must be signed in to change notification settings - Fork 120
[Enhancement] Synchronization means through attribute like [SyncedMapping] etc. #71
Comments
Hi There is a discussion about this topic #12
I see this feature has aroused a lot of interest, but I'm not sure if this is doable. In order to make any attempt to implement it, I need more specific requirements. Especially, what are the expectations towards the "custom adjustment". How should they be handled? For complete automated mappings I would be nice to use https://github.com/dotnet/roslyn/blob/master/docs/features/generators.md but they are still WIP |
Thanks for elaborating on this. Custom adjustments can be marked like explicit method extracts as I showed in the example and for omissions one could mark such with an attribute like: public class MyDto
{
[NoMap]
public int MyProp {get; set;}
} I know, a bit intrusive. When it comes to performance, we can start with sth as simple as resync button (keyboard shortcut) to resync them all. The source generators look promising, indeed. |
I prefer to keep all the mapping information closed to the context as possible. I mean, your proposal has a few flaws:
|
[assembly:MappingSync(typeof(...), typeof(...))] or any convention you want. I understand that syncing all up automatically may be problematic but at least some analyzer utility would be helpful to cover entities evolution over time. This could be especially valuable for having the compiler detect entity modifications by 3rd parties that are not reflected in the mapping code yet. For this, a set of reasonable markers would do. |
I will make an attempt to create such analyzer, but this is not gonna happen in this month (quite busy season) |
I know, I wish I could attend your WG.NET talk on Roslyn this month. If you need any help developing such analyzer, I offer my help (well, I'm in TOP 2 of this repo Contributors list 😄). |
I'm not going to implement a synchronization mechanism. If you need a mapping code that is continuously synchronized with models, please take a look at |
Right now we have perfect means to create mappings. I'd would be useful too to resync the changes as entities/DTOs evolve over time (cliche, I know).
What about marking types/methods with attributes from e.g. MappingGenerator.Annotations (a dedicated NuGet) [SyncedMapping] to indicate the engine to look for changes and update mappings on the fly? It'd be particularly useful in scenarios when some entity-DTO pairs appear in multiple mappings as aggregate children.
I expect that one'd want some exclusion rules then too, e.g. custom mapping method discovery for not to loose custom changes:
It can be developed incrementally: 1) diagnostics only (i.e warnings) 2) code fixes (auto-sync updates on the fly).
The text was updated successfully, but these errors were encountered: