Closed rofenix2 closed 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
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.
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; }
}
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.