Let's clarify few things before starting, if you could observe now a days, all typical modern application handle request either from mobile device or web browser (all the platforms like Windows, Mac, Linux). and from the desktop platform. See the drawing below:
Application Architecture:
Therefore, the request are coming from different devices, which we call (cross platform) but we can make the endpoint universal. There are different technology out there. You could consider Asp.net Web API
Now come to your point.
"How do I ensure the models are shared so I don't have redundant code to duplicate?"
There are couple of way to restrict code redundancy. You can consider SOLID principle. Within the SOLID you could specifically implement Single Responsibility means a class should only have one responsibility additionally you could implement Inheritance of OOP so that you can reuse of the base code in your derive class when your project/application would continuously extended.
There are bundle of example you could found online for above terms.
So what I am trying to explain is make your backend application universal so that it can handle all the request no matter where they are coming from. So that it would be easier for you to handle code reusability and eventually it would restrict the redundancy as well.
Now Consider Your Domain Model:
Into your ApplicationDbContext you can now define all of your domain model like you can think of your business model as the domain model for example: RegularVisitors, Merchants and admins and internal team as Users domain model, You can design your ApplicationDbContext as below:
public class ApplicationDbContext: DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<Merchants> Merchants{ get; set; }
public DbSet<RegularVisitors> RegularVisitors{ get; set; }
public DbSet<User> User { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Merchants>().ToTable("Merchants");
modelBuilder.Entity<RegularVisitors>().ToTable("RegularVisitors");
modelBuilder.Entity<User>().ToTable("User");
}
}
This is how you could move forward considering your requirement. For details implementation you could consider this thread to implement your requirement accordingly
Hope above steps and implementations guided you accordingly.
发布评论
评论(1)
应用程序架构:
因此,请求来自不同的设备,我们称之为(跨平台)但我们可以使端点通用。那里有不同的技术。您可以考虑
Asp.net Web API
“如何确保模型共享,这样我就没有多余的代码可以重复?”
您可以在网上找到有关上述术语的大量示例。
现在考虑您的域模型:
希望上述步骤和实施能够
Application Architecture:
Therefore, the request are coming from different devices, which we call (cross platform) but we can make the endpoint universal. There are different technology out there. You could consider
Asp.net Web API
"How do I ensure the models are shared so I don't have redundant code to duplicate?"
There are bundle of example you could found online for above terms.
Now Consider Your Domain Model:
Hope above steps and implementations guided you accordingly.