TwT.Base
1.0.0
dotnet add package TwT.Base --version 1.0.0
NuGet\Install-Package TwT.Base -Version 1.0.0
<PackageReference Include="TwT.Base" Version="1.0.0" />
paket add TwT.Base --version 1.0.0
#r "nuget: TwT.Base, 1.0.0"
// Install TwT.Base as a Cake Addin
#addin nuget:?package=TwT.Base&version=1.0.0
// Install TwT.Base as a Cake Tool
#tool nuget:?package=TwT.Base&version=1.0.0
TwT.Base
Base package that will be used by all the other projects from me. This base package isn't intended to have all the possible usable code that there is. It just contains the most used logic or logic that I think should always used (E.G. interface for configurations).
🚀 About Me
I'm a full stack developer mainly working with Umbraco, however my passion will always be at the Back-End. I started as an Embedded Engineer and slowly rolled into C# which I am using now for over more then 8 years
License
This package is not made for anyone but myself. However feel free the use, clone and/or modify it MIT. Also requests for change or pull request are welcome. If you do make money of it, congratz on you!
If you mind a buying me a coffee that's ofcourse always appreciated!
Features
The following version are available
Version 1.0.0 (10-10-2023)
First release
- Configuration base and interface ITwTConfiguration
- TwTException
- IRestApi with Refit implementation
Roadmap
At the moment there are no concrete items for the roadmap. However at some point I'm sure that I will add logic.
Security
At least twice a year this package will be checked for secuirty issues. If a high security issues arises earlier, it will be patched directlly.
Installation
NUGET command here
npm install my-project
cd my-project
Usage/Examples
Below are some samples of code that do work with this package
Configuration
Every configuration file used should inherited from TwTConfigurationBase this helps with making sure that the interface ITwTConfiguration is always implemented in the same way.
public interface IExampleConfiguration : ITwTConfiguration
{
public bool Enabled { get; }
public string Host { get; }
public string Username { get; }
public string Password { get; }
}
internal class ExampleConfiguration : TwTConfigurationBase
{
public bool Enabled { get; set; }
public string Host { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public override IReadOnlyCollection<string> Validate()
{
var result = new List<string>();
if (Enabled)
{
if(string.IsNullOrWhiteSpace(Host))
result.Add(GenerateErrorMessageForEmptyString(nameof(Host)));
if (string.IsNullOrWhiteSpace(Username))
result.Add(GenerateErrorMessageForEmptyString(nameof(Username)));
if (string.IsNullOrWhiteSpace(Password))
result.Add(GenerateErrorMessageForEmptyString(nameof(Password)));
}
return result;
}
}
}
Exceptions
All the exceptions should inherited from TwTException so that it can be easly catched
try
{
//Logic
}
catch (TwTException twtException)
{
switch (twtException)
{
case RestApiException apiException:
System.Console.WriteLine($"API responded with an error. StatusCode from server: '{apiException.StatusCode}' || ReasonPhrase from server: '{apiException.ReasonPhrase}'");
break;
case ConfigurationValidationException exception:
System.Console.WriteLine($"Whoops the configuration was incorrect. It has {exception.ValidationErrorCount} validation errors");
break;
}
}
catch (Exception twTException)
{
System.Console.WriteLine($"UnExpected exception. Message: '{twTException.Message}'");
}
API
This package has a defualt wrapper for https://github.com/reactiveui/refit that can be used for setting up API clients
var config = new RestApiConfiguration()
{
UserAgent = "test",
BaseUrl = "https://google.nl",
Headers = null
};
System.Console.WriteLine($"Config has '{config.ValidationErrorCount}' errors");
try
{
var api = new RestAPi<IGoogleApi>(config, NullLogger<RestAPi<IGoogleApi>>.Instance, checker);
var foo = api.Endpoint.Test().Result;
}
catch (Exception e)
{
System.Console.WriteLine(e);
}
private static EndpointReachAbility checker(IGoogleApi api)
{
return EndpointReachAbility.IsUp;
}
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.Extensions.Logging.Abstractions (>= 7.0.1)
- Refit (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 137 | 10/10/2023 |
First release
- Configuration base and interface ITwTConfiguration
- TwTException
- IRestApi with Refit implementation