Autofac.Extras.AttributeMetadata 7.0.0

Prefix Reserved
dotnet add package Autofac.Extras.AttributeMetadata --version 7.0.0
                    
NuGet\Install-Package Autofac.Extras.AttributeMetadata -Version 7.0.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="Autofac.Extras.AttributeMetadata" Version="7.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Autofac.Extras.AttributeMetadata" Version="7.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Autofac.Extras.AttributeMetadata" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Autofac.Extras.AttributeMetadata --version 7.0.0
                    
#r "nuget: Autofac.Extras.AttributeMetadata, 7.0.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.
#:package Autofac.Extras.AttributeMetadata@7.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Autofac.Extras.AttributeMetadata&version=7.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Autofac.Extras.AttributeMetadata&version=7.0.0
                    
Install as a Cake Tool

Autofac.Extras.AttributeMetadata

Attribute metadata support for Autofac IoC

Build status codecov NuGet

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

Quick Start

First, create a metadata attribute - any System.Attribute that has MEF's [MetadataAttribute] applied. Every publicly readable property becomes one metadata name/value pair, so the attribute below provides Age metadata:

[MetadataAttribute]
public class AgeMetadataAttribute : Attribute
{
  public int Age { get; private set; }

  public AgeMetadataAttribute(int age)
  {
    Age = age;
  }
}

Apply it to the component implementation rather than to the service interface:

public interface IArtwork
{
  void Display();
}

[AgeMetadata(100)]
public class CenturyArtwork : IArtwork
{
  public void Display() { ... }
}

Then register the AttributedMetadataModule so the container reads those attributes, and consume the metadata as you would any other:

var builder = new ContainerBuilder();
builder.RegisterModule<AttributedMetadataModule>();
builder.RegisterType<CenturyArtwork>().As<IArtwork>();
var container = builder.Build();

var artwork = container.Resolve<IEnumerable<Meta<IArtwork>>>()
                       .First(a => a.Metadata["Age"].Equals(100));
artwork.Value.Display();

You can read more details in the documentation.

Get Help

Need help with Autofac? We have a documentation site as well as API documentation. We're ready to answer your questions on Stack Overflow or check out the discussion forum.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Autofac.Extras.AttributeMetadata:

Package Downloads
Cogito.MassTransit.Autofac

Alternative Autofac integration for MassTransit.

Jabberwocky.Glass.Autofac.Mvc

Jabberwocky Glass and Autofac with MVC

Jabberwocky.Glass.Autofac.WebApi

Jabberwocky Glass and Autofac with WebApi

Idevs.Net.CoreLib.Autofac

Optional Autofac integration for Idevs.Net.CoreLib.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Autofac.Extras.AttributeMetadata:

Repository Stars
autofac/Examples
Example projects that consume and demonstrate Autofac IoC functionality and integration
daxnet/we-text
WeText is a sample application that demonstrates the implementation of DDD/CQRS and microservice architectural patterns in C#.
Version Downloads Last Updated
7.0.0 89 8/14/2026
6.0.0 717,303 10/6/2020
5.0.0 263,814 1/31/2020
4.1.0 147,194 9/10/2019
4.0.2 18,596 8/26/2019
4.0.1 427,062 1/18/2017
4.0.0 293,863 9/11/2015