csharpfritz / InstantAPIs

A library that generates Minimal API endpoints for an Entity Framework context.
MIT License
448 stars 57 forks source link

IModel #55

Open ChessGeekBoy opened 2 years ago

ChessGeekBoy commented 2 years ago

It might be nice if the user was allowed to inherit their model from an IModel interface that looked something like this:

interface IModel
{
    int/Guid Id { get; set;}
}

This would allow the code not to have to use the Type.GetProperty() method and provide more IntelliSense.

ScottKane commented 2 years ago

As we're working with entities I would go with:

public interface IEntity { }

public interface IEntity<TId> : IEntity
{
    public TId Id { get; set; }
}

Also pretty sure you can derive your model from that interface and it should just work in it's current form.

ChessGeekBoy commented 2 years ago

Sure, that would be better.

csharpfritz commented 2 years ago

Thinking this through... if this interface was implemented by a class and a collection, how do you see this applying to the APIs?

This feels like it plays in the same space as the #4 Repository support.

Thoughts?

ScottKane commented 2 years ago

Yeah I would agree this kind of falls into repository pattern territory

ChessGeekBoy commented 2 years ago

Yeah, I think this is the same thing as Repository support. This (or repository support) would allow the client/user to get a compilation error if their Model does not contain an Id property rather than getting an exception thrown during Type.GetProperty().