Flaeng.Productivity
0.3.0
See the version list below for details.
dotnet add package Flaeng.Productivity --version 0.3.0
NuGet\Install-Package Flaeng.Productivity -Version 0.3.0
<PackageReference Include="Flaeng.Productivity" Version="0.3.0" />
paket add Flaeng.Productivity --version 0.3.0
#r "nuget: Flaeng.Productivity, 0.3.0"
// Install Flaeng.Productivity as a Cake Addin #addin nuget:?package=Flaeng.Productivity&version=0.3.0 // Install Flaeng.Productivity as a Cake Tool #tool nuget:?package=Flaeng.Productivity&version=0.3.0
Flaeng.Productivity
What does it do?
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
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;
}
}
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.4.0)
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 | 245 | 8/5/2023 |
0.3.1 | 230 | 8/2/2023 |
0.3.0 | 178 | 7/30/2023 |
0.3.0-rc.3 | 92 | 7/30/2023 |
0.3.0-rc.2 | 77 | 7/14/2023 |
0.3.0-rc.1 | 95 | 7/14/2023 |
0.2.3 | 258 | 3/8/2023 |
0.2.2 | 275 | 3/5/2023 |
0.2.1 | 282 | 3/5/2023 |
0.2.0 | 279 | 3/4/2023 |
0.1.3 | 287 | 3/4/2023 |
0.1.2 | 261 | 3/4/2023 |
0.1.1 | 237 | 3/3/2023 |
0.1.0 | 238 | 3/2/2023 |