-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutomaticFeatureRegistrationAttribute.cs
61 lines (55 loc) · 2.82 KB
/
AutomaticFeatureRegistrationAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
namespace DataCore.Adapter {
/// <summary>
/// Adapters that are derived from <see cref="AdapterBase{TAdapterOptions}"/> can be annotated
/// with this attribute to control if adapter features implemented directly by the adapter are
/// automatically added to the adapter's <see cref="IAdapter.Features"/> collection by default.
/// </summary>
/// <remarks>
///
/// <para>
/// The default behaviour of <see cref="AdapterBase{TAdapterOptions}"/> is to automatically
/// register all adapter features that are implemented on the adapter class. This behaviour
/// is inherited by derived types unless the derived type is annotated with its own
/// <see cref="AutomaticFeatureRegistrationAttribute"/> annotation that changes the
/// inherited behaviour. For example, if adapter class <c>AdapterA</c> is derived from
/// <see cref="AdapterBase{TAdapterOptions}"/> and is annotated with an <see cref="AutomaticFeatureRegistrationAttribute"/>
/// that disables automatic feature registration, adapters derived from <c>AdapterA</c> will
/// also have automatic feature registration disabled by default.
/// </para>
///
/// <para>
/// If automatic feature registration is disabled, it is the responsibility of the adapter
/// to add appropriate features to its <see cref="IAdapter.Features"/> collection.
/// </para>
///
/// <para>
/// The <see cref="Diagnostics.IHealthCheck"/> feature provided by <see cref="AdapterBase{TAdapterOptions}"/>
/// will always be registered, regardless of whether or not automatic feature registration
/// is enabled.
/// </para>
///
/// </remarks>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class AutomaticFeatureRegistrationAttribute : Attribute {
/// <summary>
/// Specifies if automatic feature registration is enabled for the adapter.
/// </summary>
public bool IsEnabled { get; }
/// <summary>
/// Creates a new <see cref="AutomaticFeatureRegistrationAttribute"/> object.
/// </summary>
/// <param name="enabled">
/// <see langword="true"/> to enable automatic feature registration for the adapter, or
/// <see langword="false"/> if the adapter will manually register all features.
/// </param>
/// <remarks>
/// The <see cref="Diagnostics.IHealthCheck"/> feature provided by <see cref="AdapterBase{TAdapterOptions}"/>
/// will always be registered, regardless of whether or not automatic feature
/// registration is enabled.
/// </remarks>
public AutomaticFeatureRegistrationAttribute(bool enabled = true) {
IsEnabled = enabled;
}
}
}