This project demonstrates how to use Azure Cosmos DB in a .NET 8 Web API using Entity Framework Core.
The project is structured into several classes:
Game
: This is the model class that represents a game.GameContext
: This is the DbContext class that represents the session with the database. It allows querying and saving instances of theGame
class.IGamesRepo
: This is the interface that defines the contract for the repository.GamesRepository
: This is the class that implements theIGamesRepo
interface.Program
: This is the main entry point for the application.
To run this project, you need to have .NET 8 and Azure Cosmos DB.
- Clone this repository.
- Open the project in your favorite editor (e.g., Visual Studio, Visual Studio Code).
- Update the
CosmosDB:URL
andCosmosDB:AccessKey
in theappsettings.json
file with your Azure Cosmos DB settings. - Run the project.
The API exposes several endpoints that correspond to CRUD operations:
POST /api/games
: Create a new game.{ "GameId": "1", "Name": "Call of Duty: Warzone", "Description": "Call of Duty: Warzone was a free-to-play battle royale video game developed by Raven Software and Infinity Ward and published by Activision", "Type": "Shooter" }
GET /api/games/{id}
: Get a game by ID.GET /api/games
: Get all games.DELETE /api/games/{id}
: Delete a game by ID.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
MIT