We have a REST API that already uses "/ v1 /" in controller routes, and we plan to create a path "/ v2 /" and also use Web API 2. I managed to find a lot of information about version control of controllers (attribute routing, user converters, etc.), but one thing I could not find articles about is managing your Model objects (e.g., data transfer objects). How do people control versions of Model objects?
In our code base and problem area, the controllers are βsimpleβ (CRUD), and these are model objects that encode our domain expertise and on which our core business logic works. (I suspect this is true for many applications, so itβs strange that most web articles about Web API 2 and version control focus on controllers and fix problems with model objects as if they would take care.)
In an ideal world, I would like to be able to use the same classes for both versions of the API, as well as add property attributes to include or exclude objects such as "only version 1", "only version 2+", "" deprecated in version 2 "etc. I think I can implement this with a special serializer that looks for the attribute classes that I create, but I want to know if there is built-in support for this or open source libraries for it before I roll back .
Another possible approach would be to get the version 2 model classes from the version 1 model classes, but I could only add this method and not delete anything. I could get both version 1 and version 2 classes from the base class, but for any of these approaches based on inheritance, A) refactoring will be required, where the classes are plus B) the factory pattern so that the internals can create the correct type derivatives. I would like to avoid this, but I still prefer its code duplication.
I suppose another approach is that we can hide our real model objects and copy their values ββinto "mute" data transfer objects in the interface. This approach is simple and will have maximum flexibility, but also maximizes performance.
Is there an option that I missed? What approach do other people use?
c # visual-studio-2013
Dennis
source share