vipwan / Biwen.AutoClassGen

Source Gen Roslyn
MIT License
15 stars 0 forks source link

Does it support inheritance? #6

Closed rofenix2 closed 9 months ago

rofenix2 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 VenueResourceand it has derived types like VenueImage, VenueSvgand VenueVideo. Then you would need to generate VenueResourceDto(abstract), VenueImageDto, VenueSvgDtoand 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 commented 9 months ago

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; }
    }