-
Notifications
You must be signed in to change notification settings - Fork 0
Home
_viwe edited this page Apr 23, 2023
·
4 revisions
Welcome to the Distro wiki!
dotnet add package gitViwe.Shared --version 1.4.4
Defines the schema for the custom ProblemDetails class
interface IDefaultProblemDetailsSome custom exceptions
class ForbiddenException { }
class NotFoundException { }
class UnauthorizedException { }
class ServiceUnavailableException { }
class ValidationException { }Some helper classes
static class Conversion {
static string ByteArrayToString(byte[] value);
static byte[] StringToByteArray(string hex);
static string RandomString(int length);
static DateTime UnixTimeStampToDateTime(long unixTimeStamp);
static long DateTimeToUnixTimeStamp(DateTime dateTime);
static byte[] ParseBase64WithoutPadding(string payload);
}
static class Formatter {
static string FormatSize(long bytes)
}
static class Generator {
static string RandomString(CharacterCombination combination, int length)
}A unified return type for the API endpoint.
Response {
static Response Fail(string message);
static Response Fail(string message, int statusCode);
static Response Success(string message);
static Response Success(string message, int statusCode);
}
Response<TData> {
static Response<TData> Fail(string message);
static Response<TData> Fail(string message, int statusCode);
static Response<TData> Success(string message, TData data);
static Response<TData> Success(string message, int statusCode, TData data);
}
PaginatedResponse<TData> {
static PaginatedResponse<TData> Success(IEnumerable<TData> data, int count, int page, int pageSize);
static PaginatedResponse<TData> Success(IEnumerable<TData> dataToPaginate, int page, int pageSize);
}dotnet add package gitViwe.Shared.Cache --version 1.4.4
builder.Services.AddGitViweRedisCache(builder.Configuration)"ConnectionStrings": {
"Redis": "localhost:6379"
},
"RedisDistributedCacheOption": {
"InstanceName": "redis_demo",
"AbsoluteExpirationInMinutes": 5,
"SlidingExpirationInMinutes": 2
}builder.Services.AddGitViweRedisCache(options =>
{
options.Configuration = "localhost:6379";
options.InstanceName= "redis_demo";
options.AbsoluteExpirationInMinutes = 5;
options.SlidingExpirationInMinutes = 2;
});
public IActionResult Result([FromServices] IRedisDistributedCache redis, [FromBody] UrlShortenRequest request)
{
await redis.SetAsync(key: "mykey", value: request.Uri, absoluteExpirationRelativeToNow: TimeSpan.FromMinutes(request.MinutesUntilExpiry));
string value = await redis.GetAsync(key: "mykey") ?? string.Empty;
return value;
}dotnet add package gitViwe.Shared.ProblemDetail --version 1.4.4
var extensionValue = new
{
Balance = 30.0m,
Accounts = { "/account/12345", "/account/67890" }
};
var problem = ProblemDetailFactory.CreateProblemDetails(
context: HttpContext,
statusCode: StatusCodes.Status412PreconditionFailed,
extensions: new Dictionary<string, object?>()
{
{ "outOfCredit", extensionValue }
},
detail: "Your current balance is 30, but that costs 50.");