SlowFox.Constructors 0.3.1-CI-20230418-125027

Prefix Reserved
This is a prerelease version of SlowFox.Constructors.
There is a newer version of this package available.
See the version list below for details.
dotnet add package SlowFox.Constructors --version 0.3.1-CI-20230418-125027                
NuGet\Install-Package SlowFox.Constructors -Version 0.3.1-CI-20230418-125027                
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="0.3.1-CI-20230418-125027" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SlowFox.Constructors --version 0.3.1-CI-20230418-125027                
#r "nuget: SlowFox.Constructors, 0.3.1-CI-20230418-125027"                
#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=0.3.1-CI-20230418-125027&prerelease

// Install SlowFox.Constructors as a Cake Tool
#tool nuget:?package=SlowFox.Constructors&version=0.3.1-CI-20230418-125027&prerelease                

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 87 5/3/2024
1.0.1-CI-20240502-154026 50 5/2/2024
1.0.0 314 4/19/2023
1.0.0-CI-20230419-075719 224 4/19/2023
0.3.1 195 4/18/2023
0.3.1-CI-20230418-125027 240 4/18/2023
0.3.1-CI-20230418-104341 209 4/18/2023
0.3.0 441 2/24/2023
0.3.0-CI-20230224-125642 241 2/24/2023
0.3.0-CI-20230224-123744 216 2/24/2023
0.2.0 467 5/23/2022
0.2.0-CI-20220523-151129 290 5/23/2022
0.1.2 438 3/14/2022
0.1.2-CI-20220428-101109 275 4/28/2022