Implementing CleanArchitecture authentication and authorization in Web Api by using Identity and JWT and RedisDistributedCaching in in Web Api and Logging with elasticsearch in Web Api and ReportBusinessObjectStimulSoft in Web and HangFire in Web Mvc
1.authentication and authorization in Web Api by using Identity and JWT
2.RedisDistributedCaching in Web Api
3.Logging with Serilog and elasticsearch in Web Api
4.ReportBusinessObjectStimulSoft in Web Mvc
5.Read And Write Config in Web Mvc
6.TDD(XUnit) include 1.UnitTest 2.IntegrationTests
7.BDD (SpecFlow)
8.EFCore7
9.Net7
10.Swagger UI
is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents
is a diagnostic logging library for .NET applications. It is easy to set up, has a clean API, and runs on all recent .NET platforms. While it's useful even in the simplest applications, Serilog's support for structured logging shines when instrumenting complex, distributed, and asynchronous
PackageName | Desc |
---|---|
Serilog.AspNetCore | Serilog support for ASP.NET Core logging |
Serilog.Enrichers.Environment | Enrich Serilog log events with properties from System.Environment. |
Serilog.Exceptions | Serilog.Exceptions is an add-on to Serilog to log exception details and custom properties that are not output in Exception.ToString() |
Serilog.Sinks.Debug | A Serilog sink that writes log events to the debug output window |
Serilog.Sinks.Elasticsearch | Serilog sink for Elasticsearch |
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft":"Information",
"System": "Warning"
}
} },
"ElasticConfiguration": {
"Uri": "http://localhost:9200"
},
services.AddSerilog();
LoggerSerilogELK.ConfigureLogging(Configuration);
Controller
private readonly ILogger<CustomersController> _logger;
public CustomersController(ILogger<CustomersController> logger)
{
_logger = logger;
_DistributedCache = DistributedCache;
}
Action:
_logger.LogInformation("start_Customer");
Example appsetting-json
"AppSettings": {
"AppVersion": "1.2",
"AppId": 0,
"AppName": ""
},
Example of Settings
public class AppSettings
{
public string AppVersion { get; set; }
public string TypeLog { get; set; }
public string AppName { get; set; }
}
services.AddOptions();
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
private readonly AppSettings _settings;
public HomeController(
IOptionsSnapshot<AppSettings> settings = null)
{
if (settings != null) _settings = settings.Value;
}
public IActionResult Index()
{
var _resul = _settings;
return View();
}
public Startup( Microsoft.Extensions.Hosting.IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false,
reloadOnChange: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
//Configuration = configuration;
}
var settingsUpdater = new AppSettingsUpdater();
settingsUpdater.UpdateAppSetting(Key, value);
Example:
public IActionResult Index()
{
var settingsUpdater = new AppSettingsUpdater();
settingsUpdater.UpdateAppSetting("AppSettings:AppVersion", "1.7.5.2");
settingsUpdater.UpdateAppSetting("AppSettings:AppName", "Test");
settingsUpdater.UpdateAppSetting("AppSettings:AppId", 1014);
return View();
}
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object.
ASP.NET Core Identity is a membership system which allows you to add login functionality to your application.used to implement forms authentication
More details(About Implementing authentication and authorization in Web Api by using Identity and JWT)
https://github.com/abolfazlSadeqi/Net7JwtAuthentication/blob/master/README.md
A distributed cache is a cache shared by multiple app servers, typically maintained as an external service to the app servers that access it. A distributed cache can improve the performance and scalability of an ASP.NET Core app
More details(About Implementing Defined distributed cache in Web Api by using Redis)
https://github.com/abolfazlSadeqi/CurdRedisDistributedCaching/blob/main/README.md
Hangfire is an open-source framework that An easy way to perform background processing in .NET and .NET Core applications. No Windows Service or separate process required.
More details(About Implementing Hangfire in Web Mvc)
https://github.com/abolfazlSadeqi/HangFireNetCoreTutorial/blob/master/README.md
One of the methods of show reports without direct connection to the database is to use Business object
This is a very esay simple application ReportBusinessObject to and .Net7 and StimulSoft For Learn
A Business object is an object of the data class that can be used to represent data in various structures :tables, lists, arrays, etc.
More details(about implementation of Use BusinessObject in Stimulsoft in Web mvc)
https://github.com/abolfazlSadeqi/ReportBusinessObjectStimulSoft/blob/master/README.md
Install Clean.Architecture.Solution.Template on nuget
I used of this is template Clean Architecture(Clean.Architecture.Solution.Template ),customized based on my own code