TwT.Base 1.0.0

dotnet add package TwT.Base --version 1.0.0
NuGet\Install-Package TwT.Base -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TwT.Base" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TwT.Base --version 1.0.0
#r "nuget: TwT.Base, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

Build & Publish NuGet to GitHub Registry

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! "Buy Me A Coffee"

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 133 10/10/2023

First release

- Configuration base and interface ITwTConfiguration
- TwTException
- IRestApi with Refit implementation