https://github.com/purejoymind/apisetupprojecttemplate
A .NET 8 Web Api project template with EF Core, Swagger, Api Versioning, NLog, and SignalR setup.
https://github.com/purejoymind/apisetupprojecttemplate
dotnet project-template template-project visual-studio webapi
Last synced: 4 months ago
JSON representation
A .NET 8 Web Api project template with EF Core, Swagger, Api Versioning, NLog, and SignalR setup.
- Host: GitHub
- URL: https://github.com/purejoymind/apisetupprojecttemplate
- Owner: PureJoyMind
- License: mit
- Created: 2024-02-28T19:14:15.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-03-01T12:01:34.000Z (about 1 year ago)
- Last Synced: 2024-11-12T09:17:33.875Z (6 months ago)
- Topics: dotnet, project-template, template-project, visual-studio, webapi
- Language: C#
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# .NET 8 Web Api Project Template
This is a web api project template which has EF Core, Swagger, Api Versioning, NLog, and signalR setup.## How to Use
***Note***: I have created and tested this template in `Visual Studio 2022 version 17.8`. It should work in version `>17.0`.* Download the Template: Visit the GitHub [Repository](https://github.com/PureJoyMind/ApiSetupProjectTemplate) of the template project.
* Get the Template File: Download the template file from the Release section of the repository.
* Copy the Template file to `C:\Users\{User}\Documents\Visual Studio 2022\Templates\ProjectTemplates`
* Create A new Project and select the template from the list of templates. If you don't see the template search for it.

### Creation
Choose this Template when creating a new project in visual studio. The nuget packages are updated as needed up to 3/1/2024.
I have upgraded the packages which had vulnerabilities.### Features
* ***Versioning***: The project contains a default Controller, which has two methods. One of them is commented out. Its purpose is to show how to use Api versioning.
* ***Logging***: I have used NLog as the projects default logger. You can see how to inject and use it in the project in the Default controller. There is a `nlog.config` file in the root of the project. Look at [NLog](https://github.com/nlog/nlog/wiki)'s official docs to see how you can twick its settings. I have setup three log levels(Info, Debug, Error) which are written in separate files outside of the project runtime folder in a folder called Logs.
* ***DbContext***: In order to use EF Core, you need to know what you are doing. in the `Program.cs` file you can see `builder.Services.AddDbContext` which adds the connection string. you can change this as you want. Or you can move the connection string to `appsettings.json`. You can then inject and use the DbContext whenever you want.
* ***SignalR***: Even though .NET 8 already has the SignalR packages by default, I have set the project in a way that you can immediately write signalR code upon project creation. In the `Program.cs` file you can see `app.MapHub("hub");` which means that the route to SignalR's websocket is `/hub`. The Hub that I have setup is Strong-Typed, which means that you can call client methods by simply calling the methods name (You have to declare clients methods in the Interface. See Strong-Typed Hubs in official [Docs](https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server#strongly-typed-hubs)).