A comprehensive ASP.NET Core 7 Web API project demonstrating enterprise-level development practices with authentication, validation, and modern architectural patterns.
- ASP.NET Core Web API 7.0 - Latest framework version
- Entity Framework Core - Database access with SQL Server
- ASP.NET Core Identity - User management and authentication
- JWT Bearer Authentication - Secure token-based authentication
- AutoMapper - Object-to-object mapping
- FluentValidation - Input validation with fluent syntax
- Swagger/OpenAPI - API documentation and testing interface
- Dependency Injection - Loosely coupled architecture
- Repository Pattern - Data access abstraction
- Service Layer - Business logic separation
EnterpriseWebAPI/
├── Controllers/ # API controllers
│ ├── AuthController.cs # Authentication endpoints
│ ├── ProductsController.cs # Product CRUD operations
│ └── WeatherForecastController.cs
├── Data/ # Database context and configurations
│ └── ApplicationDbContext.cs
├── DTOs/ # Data Transfer Objects
│ ├── ProductDtos.cs
│ └── UserDtos.cs
├── Models/ # Entity models
│ ├── Product.cs
│ └── User.cs
├── Services/ # Business logic services
│ ├── AuthService.cs
│ ├── IServices.cs
│ └── ProductService.cs
├── Validators/ # FluentValidation validators
│ ├── ProductValidators.cs
│ └── UserValidators.cs
├── Mapping/ # AutoMapper profiles
│ └── MappingProfile.cs
└── Program.cs # Application configuration
- .NET 7.0 SDK
- SQL Server (LocalDB for development)
- Visual Studio 2022 or VS Code
-
Clone the repository
git clone <repository-url> cd EnterpriseWebAPI
-
Restore packages
dotnet restore
-
Update database connection string
Edit
appsettings.jsonandappsettings.Development.jsonto configure your database connection. -
Run the application
dotnet run
-
Access Swagger UI
Navigate to
https://localhost:5001orhttp://localhost:5000to access the Swagger documentation.
POST /api/auth/register- Register a new userPOST /api/auth/login- Login with email/passwordGET /api/auth/me- Get current user information
GET /api/products- Get all productsGET /api/products/{id}- Get product by IDPOST /api/products- Create new product (requires authentication)PUT /api/products/{id}- Update product (requires authentication)DELETE /api/products/{id}- Delete product (requires authentication)GET /api/products/category/{category}- Get products by categoryGET /api/products/search?searchTerm={term}- Search products
The API uses JWT (JSON Web Tokens) for authentication. To access protected endpoints:
- Register a new user or login with existing credentials
- Include the JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>
{
"JwtSettings": {
"SecretKey": "YourSuperSecretKeyThatIsAtLeast32CharactersLong12345",
"Issuer": "EnterpriseWebAPI",
"Audience": "EnterpriseWebAPIUsers",
"ExpirationInHours": 24
}
}{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=EnterpriseWebAPI;Trusted_Connection=true;MultipleActiveResultSets=true"
}
}dotnet run --environment Developmentdotnet run --environment Production# Build the image
docker build -t enterprise-web-api .
# Run the container
docker run -p 8080:80 enterprise-web-api- Run the application
- Navigate to the Swagger UI (root URL)
- Use the "Authorize" button to input your JWT token
- Test the endpoints directly from the interface
Example registration request:
curl -X POST https://localhost:5001/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"password": "Password123",
"confirmPassword": "Password123"
}'- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.EntityFrameworkCore.Tools
- Microsoft.EntityFrameworkCore.Design
- Microsoft.AspNetCore.Identity.EntityFrameworkCore
- Microsoft.AspNetCore.Authentication.JwtBearer
- AutoMapper
- AutoMapper.Extensions.Microsoft.DependencyInjection
- FluentValidation
- FluentValidation.AspNetCore
- Swashbuckle.AspNetCore
- Clean Architecture - Separation of concerns with layers
- SOLID Principles - Dependency inversion, single responsibility
- Async/Await - Non-blocking operations
- Input Validation - FluentValidation for robust validation
- Error Handling - Consistent error responses
- Security - JWT authentication, password hashing
- Documentation - Swagger/OpenAPI integration
- Logging - Built-in .NET logging
- Configuration - Environment-specific settings
# Add migration
dotnet ef migrations add InitialCreate
# Update database
dotnet ef database update
# Build project
dotnet build
# Run tests
dotnet test
# Publish for deployment
dotnet publish -c ReleaseFor production deployment, consider using environment variables:
ConnectionStrings__DefaultConnectionJwtSettings__SecretKeyJwtSettings__IssuerJwtSettings__Audience
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Contact the development team
- Check the API documentation in Swagger UI
Enterprise Web API - Built with ❤️ using ASP.NET Core