Simple .Net Core Web API With JWT Auth

Mert Çalışkanyürek
2 min readMar 28, 2021

Hi, In this article I will share my .Net Core API project. I have been working on .Net core and JWT authentication for my personal use. I developed a simple Web API with JWT authentication that uses Repository and Unit Of Work pattern. I decided to share it open source for your personal use. You can develop your project based on it.

In this project, I use Repository and Unit Of Work patterns. For now, it includes just one entity: User entity, which allows CRUD operations and authentication. To create a new Entity follow these steps:

1-> Create a Model and properties in ./Domain/Entity/Model

2-> Generate a repository that uses the model in ./Domain/Repositories. You might extend GenericRepository or create your own. If you want the create your own you must define Interface for DI.

3-> Generate a service that uses this Repository in ./Domain/Services. You might extend GenericService or create your own. Again if you want the create your own you must define Interface for DI.

4-> Generate a controller that uses this Service in ./Controllers. You might create a Mapping class in ./Mapping extends Profile for mapping in Controller. You might also create a Resource class for using Controller methods in ./Mapping

Do not forget to add your Service to ConfigureServices method in Startup.cs. for DI.

services.AddScoped<IGenericService<YourEntity>, EntityService>();

or with your own Service Interface

services.AddScoped<IEntityService, EntityService>();

Hopefully it benefits your business. If you want me to elaborate further, contact me.

--

--