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

Does it support inheritance? #6

Closed
rofenix2 opened this issue Jan 19, 2024 · 3 comments
Closed

Does it support inheritance? #6

rofenix2 opened this issue Jan 19, 2024 · 3 comments

Comments

@rofenix2
Copy link

rofenix2 commented Jan 19, 2024

Is it compatible with entity inheritance and DDD best practices? for example my entity has a IReadOnlyCollection<RelatedEntity> and RelatedEntity its a abstract class which is implemented by MyClassA, MyClassB and MyClassC. Will the library make the following DTOs?:

RelatedEntityDto (abstract), MyClassADto, MyClassBDto and MyClassCDto?.

Thanks.

@vipwan
Copy link
Owner

vipwan commented Jan 20, 2024

Just provide a simple DTO generation, here are the use cases #4 ,
if you have more specific needs, you can post your sample code, if time permits, I can do my best to implement

@rofenix2
Copy link
Author

rofenix2 commented Jan 20, 2024

Some simple example for collections in DDD style:

public class Venue
{
    private readonly EntityCollection<VenueImage> _images;

    public Id BusinessId { get; }
    public VenueName Name { get; private set; }
    public Address Address { get; private set; }

    public IReadOnlyCollection<VenueImage> Images { get => _images.AsReadOnly(); }
}

public class VenueImage
{
    public Id VenueId { get; }
    public ImageUrl Url { get; }
    public PositiveNonZeroInt OrderId { get; private set; }
}

It should generate a VenueDto with a List<VenueImageDto> Images { get; } = [] and VenueImageDto its just generated as the library already does.

Also the scenario gets a little more tricky when the image the collection is of an abstract class, for example VenueResource and it has derived types like VenueImage, VenueSvg and VenueVideo. Then you would need to generate VenueResourceDto (abstract), VenueImageDto, VenueSvgDto and VenueVideoDto.

Mind this scenarios are common when working with DDD and CQRS, you want those models to their DTO version in order to use them in command requests for their command handler for example creating a new Venue would require a VenueDto as a the command request.

@vipwan
Copy link
Owner

vipwan commented Jan 22, 2024

Sorry, I don't have any plans to automatically generate DTO internal classes in DTOs, can only implement the requirements with the following code :

    [AutoDto<VenueImage>]
    public partial class VenueImageDto
    {
    }

    [AutoDto<Venue>(nameof(Venue.Images))]
    public partial class VenueDto
    {
        public IList<VenueImageDto>? Images { get; set; }
    }

@vipwan vipwan closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants