LabIOC 1.0.1

dotnet add package LabIOC --version 1.0.1
                    
NuGet\Install-Package LabIOC -Version 1.0.1
                    
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="LabIOC" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LabIOC" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="LabIOC" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LabIOC --version 1.0.1
                    
#r "nuget: LabIOC, 1.0.1"
                    
#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.
#:package LabIOC@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LabIOC&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=LabIOC&version=1.0.1
                    
Install as a Cake Tool

About

LabIOC is a C# inversion of control framework. This essentially means your classes are more loosely coupled to one another, making them much easier to test and maintain long-term.

Usage/Examples

Interface and implementation

public class Car : ICar
{
    private readonly IEngine _engine;
    private readonly ITurbo _turbo;

    public Car(IEngine engine, ITurbo turbo)
    {
        _engine = engine;
        _turbo = turbo;
    }

    public int CalculateHorsepower()
    {
        return (int) (_engine.EnginePower() * _turbo.TurboFactor());
    }

    public override string ToString()
    {
        return $"{CalculateHorsepower()}hp.";
    }
}

public interface ICar
{
    int CalculateHorsepower();
}


public class BasicEngine : IEngine
{
    public double EnginePower()
    {
        return 100;
    }
}

public class BigEngine : IEngine
{
    public double EnginePower()
    {
        return 200;
    }
}

public interface IEngine
{
    double EnginePower();
}


public class DefaultTurbo : ITurbo
{
    public double TurboFactor()
    {
        return 1;
    }
}

public class SuperTurbo : ITurbo
{
    public double TurboFactor()
    {
        return 1.25;
    }
}

public interface ITurbo
{
    double TurboFactor();
}

Creating a container via the factory and adding our classes and interfaces

var demoContainer = LabContainerFactory.Create()
                    .Register<IDemo, Demo>() // every object must implement an interface
                    .Build();

var baseCarContainer = LabContainerFactory.Create()
    .Register<ICar, Car>()
    .Register<IEngine, BasicEngine>()
    .Register<ITurbo, DefaultTurbo>()
    .Build();

Getting data from a class

var car = baseCarContainer.Get<ICar>();

Console.WriteLine(car); // "100hp"

Another Example

var fastCarContainer = LabContainerFactory.Create()
    .Register<ICar, Car>()
    .Register<IEngine, BigEngine>()
    .Register<ITurbo, SuperTurbo>()
    .Build();
    
var superCar = fastCarContainer.Get(ICar)();
Console.WriteLine(superCar); // "312hp"

License

MIT

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on LabIOC:

Package Downloads
Medi8r.LabIOCIntegration

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 449 11/28/2022
1.0.0 694 5/10/2022