我在asp .Net Core中构建Web Api有三个这样的接口:
public interface IBook
{
string Title { get; set; }
string Author { get; set; }
long Id { get; set; }
}
public interface IBookReq
{
string Title { get; set; }
string Author { get; set; }
}
public interface IBookRes
{
string Title { get; set; }
long Id { get; set; }
}
我想要做的是将Book实现为:
public class Book : IBook, IBookReq, IBookRes
{
//Not Implemented
}
因此,我可以在WebApi项目的不同部分中对Book实例进行不同的表示,我不确定如何将Book转换为特定的界面。
您可能希望将BookViewModel或DTO用作有线格式。如您所知,通过API公开您的域/数据模型并不是一个好主意。正如评论所建议的那样,您可以使用像Automapper这样的工具,以便在有线格式类和数据/域类之间轻松实现。