Generic Web Api controller to support any model

后端 未结 7 792
南旧
南旧 2020-11-30 09:43

Is it possible to have a generic web api that will support any model in your project?

class BaseApiController :ApiController
{
    private IReposito         


        
7条回答
  •  温柔的废话
    2020-11-30 10:35

    I did this for a small project to get something up and running to demo to a client. Once I got into specifics of business rules, validation and other considerations, I ended up having to override the CRUD methods from my base class so it didn't pan out as a long term implementation.

    I ran into problems with the routing, because not everything used an ID of the same type (I was working with an existing system). Some tables had int primary keys, some had strings and others had guids.

    I ended up having problems with that as well. In the end, while it seemed slick when I first did it, actually using it in a real world implementation proved to be a different matter and didn't put me any farther ahead at all.

提交回复
热议问题