I am working on an Asp.Net Core application where I have defined a service that is responsible for storing the request into a SQL database. My Request consists of three properties Id, RequestType, and a SpecificRequestDto. The RequestType is an enum that specifies whether is it a Flight booking request, hotel booking request, or a RailBooking request. For instance, the SpecificRequestDto can be a FlightBookingRequest, HotelBookingRequest, RailBookingRequest. My request class
public class Request
{
public int RequestId{ get; set; }
public RequestType RequestType{ get; set; }
public IRequestDto RequestDto{ get; set; }
}
public class FlightBookingRequestDto : IRequestDto
{
}
public class HotelBookingRequestDto : IRequestDto
{
}
public class RailBookingRequestDto: IRequestDto
{
}
My request JSON can either FlightBookingRequestDto, HotelBookingRequestDto, or RailBookingRequestDto in the RequestDto property. Now my application cannot determine the type of RequestDto as I am sending an interface type and hence cannot be de-serialized. I have made the RequestDto as string property and sending the FlightBookingRequestDto, HotelBookingRequestDto, or RailBookingRequestDto as Json string and de-serializing it in my application based on RequestType.
I would like to know whether is it the right approach or Asp.Net core has a better solution for it. I am currently using the AspNet Boilerplate template.