Table of Contents

Class ExportAttribute

Namespace
Arc4u.Dependency.Attribute
Assembly
Arc4u.Dependency.dll

Represents an attribute that indicates a type provides a specific export. This attribute can be used in combination with other attributes to define the export's lifetime:

If neither SharedAttribute nor ScopedAttribute is used, the export will have a transient lifetime.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class ExportAttribute : Attribute
Inheritance
ExportAttribute
Inherited Members

Examples

public interface IClock { DateTime UtcNow { get; } }

// Registered as a singleton for the contract IClock.
[Export(typeof(IClock)), Shared]
public class SystemClock : IClock
{
    public DateTime UtcNow => DateTime.UtcNow;
}

Constructors

ExportAttribute()

Initializes a new instance of the ExportAttribute class, exporting the type or member marked with this attribute under the default contract name.

public ExportAttribute()

ExportAttribute(string)

Initializes a new instance of the ExportAttribute class, exporting the type or member marked with this attribute under the specified contract name.

public ExportAttribute(string contractName)

Parameters

contractName string

A string containing the contract name to export the type or member marked with this attribute, under; or null or an empty string ("") to use the default contract name.

ExportAttribute(string?, Type?)

Initializes a new instance of the ExportAttribute class, exporting the type or member marked with this attribute under the specified contract name.

public ExportAttribute(string? contractName, Type? contractType)

Parameters

contractName string

A string containing the contract name to export the type or member marked with this attribute, under; or null or an empty string ("") to use the default contract name.

contractType Type

A Type of which to derive the contract name to export the type or member marked with this attribute, under; or null to use the default contract name.

ExportAttribute(Type)

Initializes a new instance of the ExportAttribute class, exporting the type or member marked with this attribute under a contract name derived from the specified type.

public ExportAttribute(Type contractType)

Parameters

contractType Type

A Type of which to derive the contract name to export the type or member marked with this attribute, under; or null to use the default contract name.

Properties

ContractName

Gets the contract name to export the type or member under.

public string? ContractName { get; }

Property Value

string

A string containing the contract name to export the type or member marked with this attribute, under. The default value is an empty string ("").

ContractType

Get the contract type that is exported by the member that this attribute is attached to.

public Type? ContractType { get; }

Property Value

Type

A Type of the export that is be provided. The default value is null which means that the type will be obtained by looking at the type on the member that this export is attached to.