Convert ints into Guids and vice versa, to avoid enumeration leaks in your application. Use Guids for your API endpoints and ints in your database and put Guint in between. Have your cake and eat it too!
$ dotnet add package GuintSure! int's make pretty primary keys! They're fast! Easy to share! Easy to communicate!
Change the primary key to Guid
Then, use Guint
Take your int and transform it to an Guid and the other way around. So have your int as a primary key in your database, but expose it as a Guid
In other words: Have your cake and eat it too!
public async Task<IHttpActionResult> Get(Guid id)
=> id
.ToInt()
.Match(
i => this.carService.Get(i),
notfound => NotFound());
}
Generate your personal secret. Go to https://dotnetfiddle.net/2x6cA6 or run var secret = Guint.GenerateSecret();
Initialize Guint at the start of your application with Guint.Use(secret)
To transform, use extension methods .ToGuid, .ToInt, .ToIntOrDefault or .ToGuidOrExplode
* For reasons!