|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.ObjectModel;
namespace System.Composition
{
/// <summary>
/// Applied to an import for ExportFactory{T}, this attribute marks the
/// boundary of a sharing scope. The ExportLifetimeContext{T} instances
/// returned from the factory will be boundaries for sharing of components that are bounded
/// by the listed boundary names.
/// </summary>
/// <example>
/// [Import, SharingBoundary("HttpRequest")]
/// public ExportFactory<HttpRequestHandler> HandlerFactory { get; set; }
/// </example>
/// <seealso cref="SharedAttribute" />
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
[MetadataAttribute]
[CLSCompliant(false)]
public sealed class SharingBoundaryAttribute : Attribute
{
private readonly string[] _sharingBoundaryNames;
/// <summary>
/// Construct a <see cref="SharingBoundaryAttribute"/> for the specified boundary names.
/// </summary>
/// <param name="sharingBoundaryNames">Boundaries implemented by the created ExportLifetimeContext{T}s.</param>
public SharingBoundaryAttribute(params string[] sharingBoundaryNames)
{
_sharingBoundaryNames = sharingBoundaryNames ?? throw new ArgumentNullException(nameof(sharingBoundaryNames));
}
/// <summary>
/// Boundaries implemented by the created ExportLifetimeContext{T}s.
/// </summary>
public ReadOnlyCollection<string> SharingBoundaryNames => Array.AsReadOnly(_sharingBoundaryNames);
}
}
|