SlowFox.Constructors 1.0.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package SlowFox.Constructors --version 1.0.1
NuGet\Install-Package SlowFox.Constructors -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="SlowFox.Constructors" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SlowFox.Constructors --version 1.0.1
#r "nuget: SlowFox.Constructors, 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.
// Install SlowFox.Constructors as a Cake Addin
#addin nuget:?package=SlowFox.Constructors&version=1.0.1

// Install SlowFox.Constructors as a Cake Tool
#tool nuget:?package=SlowFox.Constructors&version=1.0.1

Introduction

SlowFox is a suite of .NET source generators, aiming to reduce the amount of repetitive code you need to write and maintain.

Source generators incur no run-time cost (as no reflection is involved), because the code is created at build time. Plus, using a supported IDE (like Visual Studio 2019/2022), you can see what's being generated immediately when you save your source code.

There are currently 2 generators available via SlowFox:

  1. Constructors, (this package), for generating constructors and private variables
  2. UnitTestMocks, for generating mock objects in unit tests

SlowFox.Constructors

alternate text is missing from this package README image alternate text is missing from this package README image Build Status Release Date Licence

SloxFox.Constructors is a generator that allows you to define the injectable dependencies for any given class, and the private class members, constructor and constructor assignments are all automatically created for you.

How do I get it working?

First off, install the NuGet package into your project:

alternate text is missing from this package README image

Then, find a class where you want to have the dependencies injected, mark it as partial, and add the SlowFox.InjectDependencies attribute. Pass into this attribute the types you want to be injected:

namespace MySampleProject
{
    [SlowFox.InjectDependencies(typeof(IUserReader), typeof(IFileHandler))]
    public partial class MyNewClass
    {
    }
}

SlowFox will then generate everything needed for these dependencies, as another partial class:

namespace MySampleProject
{
    public partial class MyNewClass
    {
        private readonly IUserReader _userReader;
        private readonly IFileHandler _fileHandler;

        public MyNewClass(IUserReader userReader, IFileHandler fileHandler)
        {
            _userReader = userReader;
            _fileHandler = fileHandler;
        }
    }
}

You can reference these private members in your original class, and you can call this constructor during DI, or call it manually, or use it in unit tests - it's as if you've written it all yourself:

namespace MySampleProject
{
    [SlowFox.InjectDependencies(typeof(IUserReader), typeof(IFileHandler))]
    public partial class MyNewClass
    {
        public void SaveUserImage()
        {
            var image = _userReader.GetImage();
            _fileHandler.AddFile(image);
        }
    }
}

This generator is compatible with:

  • inheritance
  • abstract classes
  • generic types
  • nullable types
  • tuples

Configuration

Configuration is set in a .editorconfig file.

To configure the generated code to not use underscores for member names, set the skip_underscores value to true:

[*.cs]
slowfox_generation.constructors.skip_underscores = true

To include a null check (and a throw of ArgumentNullException if the constructor parameter is null), set include_nullcheck to true:

[*.cs]
slowfox_generation.constructors.include_nullcheck = true
There are no supported framework assets in this 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.1 48 5/3/2024
1.0.1-CI-20240502-154026 29 5/2/2024
1.0.0 291 4/19/2023
1.0.0-CI-20230419-075719 195 4/19/2023
0.3.1 173 4/18/2023
0.3.1-CI-20230418-125027 206 4/18/2023
0.3.1-CI-20230418-104341 183 4/18/2023
0.3.0 372 2/24/2023
0.3.0-CI-20230224-125642 208 2/24/2023
0.3.0-CI-20230224-123744 188 2/24/2023
0.2.0 441 5/23/2022
0.2.0-CI-20220523-151129 260 5/23/2022
0.1.2 407 3/14/2022
0.1.2-CI-20220428-101109 238 4/28/2022