-
|
In DDD some advise to not provide any way of creating an object with an "invalid or unpredicted" state, that's why we do not expose any public parameterless constructor in our domain entities. public class TodoTask
{
public long Id { get; set; }
public required string Name { get; set; }
public string? Description { get; private set; }
private TodoTask() // private to not create an "invalid state" object
{
}
[SetsRequiredMembers]
public TodoTask(long id, string name, string description)
{
Id = id;
Name = name;
Description = description;
}and also, I have the following DTO public record TodoTaskDto
{
public required long Id { get; set; }
public required string Name { get; set; }
public string? Description { get; set; }
}And now I want to map from one to another, like this [Mapper]
public partial class TodoTaskMapper
{
public partial TodoTaskDto ToDto(TodoTask todoTask);
public partial TodoTask ToTodoTask(TodoTaskDto todoTaskDto); // <-- Error RMG013 TodoTask has no accessible constructor with mappable arguments
}How can I solve this? |
Beta Was this translation helpful? Give feedback.
Answered by
latonz
Jan 19, 2024
Replies: 1 comment
-
|
Currently, you can't. What you need is #997 to enable private constructor access from Mapperly. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Ewerton
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, you can't. What you need is #997 to enable private constructor access from Mapperly.