Specky6 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Specky6 --version 1.1.0
NuGet\Install-Package Specky6 -Version 1.1.0
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="Specky6" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Specky6 --version 1.1.0
#r "nuget: Specky6, 1.1.0"
#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 Specky6 as a Cake Addin
#addin nuget:?package=Specky6&version=1.1.0

// Install Specky6 as a Cake Tool
#tool nuget:?package=Specky6&version=1.1.0

Specky6

Lightweight wrapper to assist injection, using attributes, using the built in DI model integrated in .NET 6 and up.

Required at builder.Services to add Specks

builder.Services.AddSpecks();

Examples (If you're familiar with .NET's built in injection then the naming here should be straight forward.)

Transient

Transient will inject a new instance for every request.

[Transient]
public class MyClass { ... }

// Equivalent to builder.Services.AddTransient<MyClass>();

[TransientAs(typeof(IMyClass))]
public class MyClass : IMyClass { ... }

// Equivalent to builder.Services.AddTransient<IMyClass, MyClass>();

Scoped

Scoped will inject a new instance for every session, typically, in a web app for example, this is each time the Http connection is reset.

[Scoped]
public class MyClass { ... }

// Equivalent to builder.Services.AddScoped<MyClass>();

[ScopedAs(typeof(IMyClass))]
public class MyClass : IMyClass { ... }  

// Equivalent to builder.Services.AddScoped<IMyClass, MyClass>();

Singleton

Singleton will inject a the same instance for the lifetime of the application.

[Scoped]
public class MyClass { ... }    

// Equivalent to builder.Services.AddSingleton<MyClass>();

[ScopedAs(typeof(IMyClass))]
public class MyClass : IMyClass { ... }

// Equivalent to builder.Services.AddSingleton<IMyClass, MyClass>();

Using Speck attributes across multiple projects / assemblies

In order to scan for specks across multiple assemblies you need to pass those assemblies to the AddSpecks method. Note: Don't forget to include the assembly you are working in, assuming you will have Specks there also.

builder.Services.AddSpecks(new []
{
    typeof(Program).Assembly,
    typeof(MyProject2.SomeNamespace.SomeType).Assembly,
    typeof(MyProject3.AnotherNamespace.IInterfaceForSomething).Assembly
});
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in 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.2.0 870 5/12/2022
1.1.0 408 4/28/2022
1.0.1 413 2/4/2022
1.0.0 416 2/3/2022