This is a complete architecture to support enterprise application. Following things are implemented in this architecture.
- NLog
- Store Procedure
- Linq Query
- JWT
- SignalR
- Swagger
- Generic Repository
- Generic Store Procedure Call
- Unit of work
- Login: This method returns a JWT token. Role authentication can also be done just need to change
[Authorize] to [Authorize(Role="RoleId Entered in JWT")] in controller.
- DecodeToken: This method decode token, use to identity user and it provide security to application.Eample: Roleid is encoded in tokens so if hacker changes the token he/she will be unauthorized.
If user need his family member name so he is only sending a GET request and token.We will decode token at run time and use his Roldid(Encoded in JWT token) to idetitfy user
-
DataFromLinqQuery: Returns data using linq query and entity Framework.
-
DataFromSP: Returns data using Store Procedure and Enitity Framework.
- Add Controller
- Add Service and Interface in Services project.
Don't forget to register service in servicemodule.cs
Example: services.AddTransient<ITestService, TestService>();
-
Add Unit of work into service file using dependency injection. ` private readonly IUnitOfWork _unitOfWork; private readonly AppSettings _appSettings;
public TestService(IUnitOfWork unitOfWork, IOptions<AppSettings> appSettings) { _unitOfWork = unitOfWork; _appSettings = appSettings.Value; }`
-
User unit of work to use Linq or Store Procedure.
public TestTable DbLinq() { var userRepository = _unitOfWork.GetRepository<TestTable>(); int a = 2; var user = userRepository.GetAll().Where(c => c.ID == a).SingleOrDefault(); if (user == null) return null; return user; }
public TestTable SpQuery() { var id = new SqlParameter("@UserId", SqlDbType.Int) { Value = 2 }; return _unitOfWork.SpRepository<TestTable>("testSP @UserId", id).SingleOrDefault(); }
- Make Models in TwinCityCoders.Models project and add dbset in DatabaseContext.cs file.
public DbSet<TestTable> TestTables { get; set; }
Thats it !!