NotIlya.Extensions
3.1.0
⚠️ Deprecated. I decided to separate extensions to dedicated nuget packages.
dotnet add package NotIlya.Extensions --version 3.1.0
NuGet\Install-Package NotIlya.Extensions -Version 3.1.0
<PackageReference Include="NotIlya.Extensions" Version="3.1.0" />
paket add NotIlya.Extensions --version 3.1.0
#r "nuget: NotIlya.Extensions, 3.1.0"
// Install NotIlya.Extensions as a Cake Addin #addin nuget:?package=NotIlya.Extensions&version=3.1.0 // Install NotIlya.Extensions as a Cake Tool #tool nuget:?package=NotIlya.Extensions&version=3.1.0
NotIlya.Extensions
This is a pack of my extensions that I grew tired of copying from one project to another. Its not tied to any specific topic there are extensions for different cases. Currently readme isn't ready I will add description to each extension method later.
Instalation
ExceptionCatcherMiddleware is available on NuGet and can be installed via the below commands:
$ Install-Package NotIlya.Extensions
or via the .NET Core CLI:
$ dotnet add package NotIlya.Extensions
Docs
Serilog Extensions
There is one extension method for IServiceCollection
:
void AddSerilog(this IServiceCollection services, AddSerilogOptions options,
Action<IServiceProvider, LoggerConfiguration>? configureSerilog = null)
It has AddSerilogOptions
class, you can create instance yourself or by using IConfiguration
extension:
AddSerilogOptions GetAddSerilogOptions(this IConfiguration config, string key)
Assume we are going to do:
configuration.GetAddSerilogOptions("SerilogOptions");
Then IConfiguration
must has following structure:
{
"SerilogOptions": {
"ServiceName": "Gateway",
"SeqUrl": "http://localhost:5341",
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
... and other serilog options
}
}
You can add configured serilog with some predefined enrichers, sinks and other staff. Currently there are:
x-request-id Enricher
It searches for x-request-id header in request and use it while logging.ServiceName Enricher
You can provide service name to `` in options and it will be added in log properties.Seq Logging
You can specify seq url and it will log to seq.
Redis Extension
There is one IServiceCollection
extension that you can use to add Redis clients to your app:
IServiceCollection AddRedis(this IServiceCollection services, string connectionString)
It adds clients from StackExchange.Redis
, StackExchange.Redis.Extensions.Core
and StackExchange.Redis.Extensions.Newtonsoft
.
And now in services you can use IDatabase
and IRedisDatabase
.
You can provide connection string either yourself or by using IConfiguration
extension:
string GetRedisConnectionString(this IConfiguration config, string? key = null)
This is a dumb implementation of that extension since it doesn't validates any inputs, it just reads all your properties and concats then with comma. For example if call it like this:
configuration.GetRedisConnectionString("Redis");
You will need to has config like this:
{
"Redis": {
"Server": "localhost:6380,redis1:6380",
"allowAdmin": true,
"user": "admin",
"password": "asdasdasd"
}
}
It will be serialized to this: localhost:6380,redis1:6380,allowAdmin=true,user=admin,password=asdasdasd
. As you can see Server property omits its name but its the only exception.
Entity Framework Sql Server Extensions
You can add entity framework with sql server using:
IServiceCollection AddEfSqlServer<TDbContext>(this IServiceCollection services,
AddEfSqlServerOptions options) where TDbContext : DbContext
You can either create options instance yourself or using IConfiguration
extension:
AddEfSqlServerOptions GetAddEfSqlServerOptions(this IConfiguration config, string? key = null)
If you run:
configuration.GetAddEfSqlServerOptions("SqlServer");
You will need to have config like this:
{
"SqlServer": {
"MigrationsAssembly": "Infrastructure",
"QueryTrackingBehavior": "TrackAll",
"Server": "localhost:1433",
"Database": "Test",
"User Id": "user",
"Password": "asdasdasd",
... and other sql server connection string properties
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.Data.SqlClient (>= 5.1.1)
- Microsoft.EntityFrameworkCore (>= 7.0.5)
- Microsoft.EntityFrameworkCore.SqlServer (>= 7.0.5)
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
- Serilog.AspNetCore (>= 7.0.0)
- Serilog.Sinks.Seq (>= 5.2.2)
- StackExchange.Redis (>= 2.6.116)
- StackExchange.Redis.Extensions.Core (>= 9.1.0)
- StackExchange.Redis.Extensions.Newtonsoft (>= 9.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.