DiAttributes 1.1.0

.NET Standard 2.1
There is a newer version of this package available.
See the version list below for details.
Install-Package DiAttributes -Version 1.1.0
dotnet add package DiAttributes --version 1.1.0
<PackageReference Include="DiAttributes" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DiAttributes --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DiAttributes, 1.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install DiAttributes as a Cake Addin
#addin nuget:?package=DiAttributes&version=1.1.0

// Install DiAttributes as a Cake Tool
#tool nuget:?package=DiAttributes&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

DiAttributes

Super-small and super-simple library for registering classes with the ASP.NET Core IServiceCollection using attributes.

GitHub: https://github.com/tobysmith568/di-attributes NuGet: https://www.nuget.org/packages/DiAttributes/

Scoped, Transient, and Singleton

Classes can be registered as any of these three types of dependency via the respective attributes:

[Scoped]
public class MyService
{
  
}

This is the equivilent of having the following in your Startup.cs:

services.Scoped<MyService>();

You can also pass in a type as an argument to register the class against:

public interface IMyService
{
  
}

[Scoped(typeof(IMyService))]
public class MyService : IMyService
{
  
}

This is the equivilent of having the following in your Startup.cs:

services.Scoped<IMyService, MyService>();

The use of these attributes will require you to add the following line to your Startup.cs file:

services.RegisterDiAttributes();

Configuration

Classes can be automatically bound to sections of your app's configuration using the Configuration attribute.

If your appsettings.json looks like this:

{
  "Outer": {
    "Inner": {
      "MySetting": "My Value"
    }
  }
}

Then you can bind a class to the Inner object and register it with the IServiceCollection like this:

[Configuration("Outer:Inner")]
public class MyInnerOptions
{
  public string MySetting { get; set; }
}

To use this attribute you will require need to pass an ICollection to the RegisterDiAttributes call in your Startup.cs file:

services.RegisterDiAttributes(Configuration);
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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 81 1/26/2022
1.1.1 151 10/24/2021
1.1.0 132 10/24/2021
1.0.3 223 9/26/2021
1.0.2 216 9/26/2021
1.0.0 144 9/26/2021