- Introduction
- Setup
- Technologies
- Techniques
- Introduction
- Dynamic Filter and How to Create
- FluentValidation and Usage
- Aspects and Usages
- Nuget Packages and Their Versions
I have been developed this project to improve myself, learn design patterns and other technologies. If you need detailed information do not hesitate to contact me.
After downloading the files and opening the solution u need to do the required and optional configurations.
- Required
- Creating sql tables (You can get sql query from: .sql)
- Configure connection string from: DataAccess > Concrete > Ef > CarRentalContext.cs (default configuration for Mssql)
- Replace the server name with yours.
- Optional
- Authorization token configurations are held in WebApi > appsettings.json > TokenOptions.
- You can change token options as you wish.
- Start the project
- .NET
- ASP.NET for Restful api
- EntityFramework Core
- Autofac
- FluentValidation
- MsSql
- Angular for Frontend
I created a dynamic filter because of the need for creating queries for multiple filtering and controlling the filtered fields from one place. If you want to add a filter for your entity, you can follow the steps below.
- Create FilterDto, implement the interface of IFilterDto, and add properties that will be used for filtering the entity. (Example FilterDto)
- Create a method in the related DAL and implement the Filter structure. (Example usage of Filter Expression in the EfCarDal)
Filter Attributes Usage
- If you need to filter with the same property with multiple values, you should create the property as a List.
- To fetch the data that has the same value as the filter property you should place [EqualFilter("propertyName)"] attribute.
- To fetch the data that has bigger values than the filter property you should use [MinFilter("propertyName")] attribute.
- To fetch the data that has smaller values than the filter property you should use [MaxFilter("propertyName")] attribute.
You can create custom FilterDto's and filtering methods for other entities by following the same steps.
If you want to check content of entity when add, update etc. operations you can create validation for related entity.
Aspect for FluentValidation
You need to add [ValidationAspect(typeof(validationType))] on top of the related method.
If you want to add the returned data to the cache, you need to add [CacheAspect] on top of the related method, by default it adds the data to the cache for 60 minutes. If you want to change the duration you just modify it as [CacheAspect(20)]. It will cache the returned data for 20 minutes.
We need to clean cache when add, update, delete or any manipulative operations triggered because the data is changed. For that purpose, you can use the cache remove aspect by adding [CacheRemoveAspect("Servicename.Get")] on top of the related method. The name of the service, which is the interface of the related manager, must be given.
If the processing time of the method is longer than expected this aspect writes it to debug screen. I added this aspect to all methods. You can check it from: Core > Utilites > Interceptors > AspectInterceptorSelector.cs. By default, I gave 60 seconds for the performance control.
You can secure the usages of operations by adding [SecuredOperation("role1,role2")] on top of the related method.You should spare the roles just with a comma.
If an operation handles more than one transaction and other transactions need to withdrawal when one transaction failed, you can add [TransactionScopeAspect] on top of the related operation.
- Autofac - Version = v6.1.0
- Autofac.Extensions.DependencyInjection - Version = v7.1.0
- Autofac.Extras.DynamicProxy - Version = v6.0.0
- FluentValidation - Version = v9.5.1
- Microsoft.AspNetCore.Authentication.JwtBearer - Version = v3.1.12
- Microsoft.AspNetCore.Http - Version = v2.2.2
- Microsoft.AspNetCore.Http.Abstractions - Version = v2.2.0
- Microsoft.AspNetCore.Http.Features - Version = v5.0.3
- Microsoft.EntityFrameworkCore.SqlServer - Version = v3.1.12
- Microsoft.IdentityModel.Tokens - Version = v6.8.0
- Newtonsoft.Json - Version = v13.0.1
- System.IdentityModel.Tokens.Jwt - Version = v6.8.0