Flaeng.Productivity 0.3.2

dotnet add package Flaeng.Productivity --version 0.3.2
NuGet\Install-Package Flaeng.Productivity -Version 0.3.2
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="Flaeng.Productivity" Version="0.3.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Flaeng.Productivity --version 0.3.2
#r "nuget: Flaeng.Productivity, 0.3.2"
#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 Flaeng.Productivity as a Cake Addin
#addin nuget:?package=Flaeng.Productivity&version=0.3.2

// Install Flaeng.Productivity as a Cake Tool
#tool nuget:?package=Flaeng.Productivity&version=0.3.2

Flaeng.Productivity

CodeFactor Maintainability

Nuget Nuget

Mission / What does it do

Flaeng.Productivity aims to improve productivity and developer experience by generating code, that would often be boilerplate, using C# source generators

How does it that?

GenerateInterfaceAttribute generates a interface with all the public properties, fields and methods in your class so you don't have to keep it up-to-date but only need to change your test code.

InjectAttribute generates a constructor for the declaring class with parameters for every property or field with the InjectAttribute in the order they are defined in the class.

MakeFluentAttribute - Makes methods for each property or field marked with the attribute (or all properties and fields if marked on the class) so that you can chain the method-calls like a fluent API

RegisterServiceAttribute - Makes an RegisterServices-extensions-method on the IServiceCollection-interface so that you don't have to remmeber to add your services to you dependency injection container

Examples

More examples in the docs

GenerateInterface Example 1: Input

using System;

namespace Flaeng.Productivity.Sample.Providers;

[Flaeng.GenerateInterface]
public partial class SummaryProvider
{
    public string[] GetSummaries()
    {
        return new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };
    }
}

GenerateInterface Example 1: Output

// <auto-generated/>

using System;

#nullable enable

namespace Flaeng.Productivity.Sample.Providers
{
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Flaeng.Productivity", "0.2.3.0")]
    public interface ISummaryProvider
    {
        string[] GetSummaries();
    }
    public partial class SummaryProvider : ISummaryProvider
    {
    }
}

GenerateInterface and Inject Example 2: Input

using Flaeng.Productivity.Sample.Providers;

namespace Flaeng.Productivity.Sample.Services;

[Flaeng.GenerateInterface]
public partial class WeatherForecastService
{
    [Flaeng.Inject] protected readonly ISummaryProvider _summaryProvider;

    public IEnumerable<WeatherForecast> GetWeatherForecast()
    {
        var Summaries = _summaryProvider.GetSummaries();
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast
        {
            TemperatureC = Random.Shared.Next(-20, 55),
            Summary = Summaries[Random.Shared.Next(Summaries.Length)]
        })
        .ToArray();
    }
}

GenerateInterface and Inject Example 2: Output

// <auto-generated/>

using Flaeng.Productivity.DependencyInjection;
using Flaeng.Productivity.Sample.Providers;

#nullable enable

namespace Flaeng.Productivity.Sample.Services
{
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Flaeng.Productivity", "0.2.3.0")]
    public interface IWeatherForecastService
    {
        IEnumerable<WeatherForecast> GetWeatherForecast();
    }
    public partial class WeatherForecastService : IWeatherForecastService
    {
    }
}

// <auto-generated/>

using Flaeng.Productivity.DependencyInjection;
using Flaeng.Productivity.Sample.Providers;

#nullable enable

namespace Flaeng.Productivity.Sample.Services
{
    public partial class WeatherForecastService
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Flaeng.Productivity", "0.2.3.0")]
        public WeatherForecastService(
            ISummaryProvider _summaryProvider
            )
        {
            this._summaryProvider = _summaryProvider;
        }
    }
}

MakeFluent Example 1: Input

[Flaeng.MakeFluent]
public class Blah 
{ 
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age;
}

MakeFluent Example 1: Output

public static partial class BlahExtensions
{
    public static Blah FirstName(
        this Blah _this,
        global::System.String FirstName
    )
    {
        _this.FirstName = FirstName;
        return _this;
    }
    public static Blah LastName(
        this Blah _this,
        global::System.String LastName
    )
    {
        _this.LastName = LastName;
        return _this;
    }
    public static Blah Age(
        this Blah _this,
        global::System.Int32 Age
    )
    {
        _this.Age = Age;
        return _this;
    }
}

RegisterService Example 1: Input

namespace TestNamespace
{
    public interface IMyServiceInterface { }
    [Flaeng.RegisterService]
    public class MyService : IMyServiceInterface { }

    public interface IMyTransientServiceInterface { }
    [Flaeng.RegisterService(ServiceType = Flaeng.ServiceType.Transient)]
    public class MyTransientService : IMyTransientServiceInterface { }

    public interface IMyScopedServiceInterface { }
    [Flaeng.RegisterService(ServiceType = Flaeng.ServiceType.Scoped)]
    public class MyScopedService : IMyScopedServiceInterface { }

    public interface IMySingletonServiceInterface { }
    [Flaeng.RegisterService(ServiceType = Flaeng.ServiceType.Singleton)]
    public class MySingletonService : IMySingletonServiceInterface { }
}

RegisterService Example 1: Output

using Microsoft.Extensions.DependencyInjection;

public static partial class StartupExtensions
{
    public static global::Microsoft.Extensions.DependencyInjection.IServiceCollection RegisterServices(
        this global::Microsoft.Extensions.DependencyInjection.IServiceCollection services
    )
    {
        services.AddScoped<global::TestNamespace.IMyServiceInterface, global::TestNamespace.MyService>();
        services.AddTransient<global::TestNamespace.IMyTransientServiceInterface, global::TestNamespace.MyTransientService>();
        services.AddScoped<global::TestNamespace.IMyScopedServiceInterface, global::TestNamespace.MyScopedService>();
        services.AddSingleton<global::TestNamespace.IMySingletonServiceInterface, global::TestNamespace.MySingletonService>();
        return services;
    }
}

More examples in the docs

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
0.3.2 211 8/5/2023
0.3.1 206 8/2/2023
0.3.0 160 7/30/2023
0.3.0-rc.3 72 7/30/2023
0.3.0-rc.2 57 7/14/2023
0.3.0-rc.1 72 7/14/2023
0.2.3 231 3/8/2023
0.2.2 248 3/5/2023
0.2.1 260 3/5/2023
0.2.0 258 3/4/2023
0.1.3 264 3/4/2023
0.1.2 234 3/4/2023
0.1.1 216 3/3/2023
0.1.0 217 3/2/2023