I'm trying to figuring out versioning in .Net core Web Api 2.0 and I have some questions after seeing a lot of 'tutorials'.
For example I have a large api with a lot of controllers/models/etc.
1. What is the best way to create a new version?
- I have seen people just putting all controllers in a different folder
/controllers/v1/
/controllers/v2/
, etc and the models also in the/models/v1/
,models/v2
, etc. - I have seen putting all controller versions in the same file and use attributes to specify which controller belongs to which version. (To me this looks messy because you loose track of which have multiple version and which dont).
- I have seen people just copy pasting almost everything in new versioning folders:
/v1/controllers, /v1/models
,/v2/controllers, /v2/models
. Which in essence is just cloning the whole code base to a new folder. (I like this one because if an older version can be deleted, you can just delete the whole folder and you're done).
2. How do you handle the namespace changes?
So for example you have a folder with v1
and it it all controllers, models, etc. And then you want to copy everything to a v2
for a new version. All namespaces in all those files do still have the .v1
in it. How do you rename all of them to a new namespace?