Code Monkey home page Code Monkey logo

sia-digital / pibox Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 3.0 649 KB

PiBox is a service hosting framework that allows .net devs to decorate their services with behaviours or functionality (think of plugins) while only using minimal configuration.

Home Page: https://sia-digital.gitbook.io/pibox/

License: MIT License

C# 99.68% Dockerfile 0.03% Shell 0.29%
dotnet dotnet-core framework lib library logging metrics performance pibox plugins

pibox's Introduction

PiBox

Framework MIT License Nuget Nuget

PiBox is a service hosting framework that allows .net devs to decorate their services with behaviours or functionality (think of plugins) while only using minimal configuration.

"PiBox" because we want to support unlimited plugins within the api out of the box!

Features

  • logs
  • metrics
  • traces
  • minimal api ready
  • auto discovered plugins
  • with performance in mind
  • less memory allocations
  • industry best practices applied security
  • standard dotnet core patterns & APIs
  • many plugins!

Prerequisites

Before you begin, ensure you have met the following requirements:

  • You have installed the latest version of .net8 sdk

Get started

To start using PiBox components/plugins, you have to:

  1. Install/add the PluginWebHost via nuget package PiBox.Hosting.WebHost
  2. Install/add the source generator plugin via nuget package PiBox.Hosting.Generator
  3. Rewrite the Entrypoint Program.cs to have following code:
using PiBox.Hosting.WebHost;
PluginWebHostBuilder.RunDefault(PiBox.Generated.PiBoxPluginTypes.All);
  1. Install/add your plugins via nuget packages prefixed with PiBox

Documentation

You can find a comprehensive documentation here

Or check the individual README files in each plugins directory

Building PiBox

To build PiBox, follow these steps:

dotnet build ./PiBox.sln

To format and style check the solution run:

dotnet format ./PiBox.sln

Testing PiBox

We are using these frameworks for unit testing

  • AutoBogus
  • Bogus
  • FluentAssertions
  • Microsoft.NET.Test.Sdk
  • NaughtyStrings.Bogus
  • NSubstitute
  • NUnit
  • RichardSzalay.MockHttp
  • WireMock.Net

To run unit tests for PiBox, follow these steps:

dotnet test ./PiBox.sln

Contributing to PiBox

To contribute to PiBox, follow these steps:

  1. Check the issues if your idea or problem already exists
  2. Open a new issue if necessary to explain your idea or problem with as much details as possible

To contribute code along your issue please follow the these steps: 2. Clone this repository. 3. Create a branch: git checkout -b <branch_name>. 4. Check our used tools and frameworks to ensure you are using the same tools which are already in place. 5. Check if your changes are in line with our style settings from .editorconfig and run dotnet format. 6. Make your changes and commit them: git commit -m '<commit_message>' 7. Push to the original branch: git push origin PiBox/<branch_name> 8. Create the pull request.

Development decisions

  • Follow the code style which is configured via .editorconfig

Disabled Compiler Errors

Code Reason Link
1701 Assembly Referencing 1701
1702 Assembly Referencing 1702
1591 Disable XML Comments 1591

pibox's People

Contributors

dependabot[bot] avatar fb-smit avatar lk-smit-ag avatar lukas-kd avatar redbit86k avatar sabrina-biersack-smit avatar siaaba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pibox's Issues

Enhance PluginWebHostBuilder for usage

Current behaviour
Currently you can only call "Build" on the PluginWebHostBuilder. So you cant configure or override something.

Feature request

  1. Make Services configurable through PluginWebHostBuilder
  2. Make configuration configurable through PluginWebHostBuilder
  3. Make logging configurable through PluginWebHostBuilder
  4. Add RunDefaultAsync for the PluginWebHostBuilder
  5. Create a TestHost for UnitTesting / IntegrationTesting

Add ability to validate ef core model with in sql server provider in tests

Use case:

  • DB-First
  • Model generated by dotnet ef cli tool with "scaffold"

To help with making sure the generated model is valid with the sql server provider there should be a method to help out with that.

Maybe we need a new project for sql server specific thing in testing or we would need to add the nuget package for the sql server to the general testing package (which i would not prefer).

Code could look something like this:

var builder = new DbContextOptionsBuilder<MyDbContext>();
builder.UseSqlServer("Server=.;Database=404;Connection Timeout=1;Command timeout=1");
using var ctx = new MyDbContext(builder.Options);
var action = () => ctx.AnyTable.FirstOrDefault();
action.Should().ThrowExactly<SqlException>().WithMessage(
    "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)");

This test or method would throw exceptions if the model has some issues with the sql server provider, so one can fix them right away.

  • Decide where to put this functionality for helping out with testing db models used in sql server
  • Implement and provide the functionality described

Add ability to ensure ef core context interface and implementation match

We should add a method in the testing project which enables to check if the interface is missing any public DbSet<> from the acutal context class.

Check could look something like this

var interfacesSets = typeof(IMyDBContext).GetProperties().Select(x => x.Name);
var implementationSets = typeof(MyDBContext)
    .GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public)
    .Select(x => x.Name);
string.Join(' ', implementationSets.Except(interfacesSets)).Should().BeEmpty();

The assert statement also has the benefit of showing the actual missing DbSet<> names, so one can add them easily

Configuration attribute does not automatically register nested classes

Consider the following case

[Configuration("persistence")]
public class PersistenceConfiguration
{
    public SqlServerConfiguration SqlServer { get; set; }
    public SmbConfiguration Smb { get; set; }
}

Current Behaviour
The webhost currently only auto registers the PeristenceConfiguration with the IoC Container bc it has the attribute, the nested config classes will not be registed automatically.

Expected Behaviour
Nested configuration classes are also automatically registered as singleton in the IoC Container.

Add ability to validate ef core model with in memory provider in tests

Use case:

  • DB-First
  • Model generated by dotnet ef cli tool with "scaffold"

To help with making sure the generated model is valid with at least the in-memory provider there should be a method to help out with that.

This does not ensure compatibility with the specific db provider used but as a general check it could be quite useful

Code could look something like this:

public class PersistenceTests
{
    private MyDbContext _myDbContext;

    [SetUp]
    public void SetUp()
    {
        var contextOptions = new DbContextOptionsBuilder<MyDbContext>()
            .UseInMemoryDatabase("test")
            .Options;

        _myDbContext = new MyDbContext(contextOptions);
    }

    [Test]
    public void ValidateEntityRelationships()
    {
        _myDbContext.GetContext().Should().NotBeNull().And.BeOfType<MyDbContext>();
        var entityTypes = _myDbContext.Model.GetEntityTypes();
        foreach (var entityType in entityTypes)
        {
            // We need the class reference to construct the method call
            var reference = typeof(PersistenceTests);

            // We need the name of generic method to call using the class reference
            var methodInfo = reference.GetMethod("AssertFirstOrDefaultIsNull",
                BindingFlags.Instance | BindingFlags.NonPublic);

            // This creates a callable MethodInfo with our generic type
            var miConstructed = methodInfo.MakeGenericMethod(entityType.ClrType);

            // This calls the method with the generic type using Invoke
            miConstructed.Invoke(this, null);
        }
        // stored procedures are not supported by the inMemoryDatabase and thus can't be verified here
    }

#pragma warning disable S1144
#pragma warning disable IDE0051
    /// <summary>
    /// This is called via reflection because of that we need to pragma warning disable the linter
    /// This method is needed since there is not _myDbContext.Set(Type type) method anymore in ef core
    /// </summary>
    /// <typeparam name="T"></typeparam>
    private void AssertFirstOrDefaultIsNull<T>() where T : class
    {
        _myDbContext.Set<T>().FirstOrDefault().Should().BeNull();
    }
#pragma warning restore S1144
#pragma warning restore IDE0051
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.