-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleAttributes.cs
More file actions
168 lines (148 loc) · 4.83 KB
/
ModuleAttributes.cs
File metadata and controls
168 lines (148 loc) · 4.83 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using Microsoft.Extensions.DependencyInjection;
namespace Modulight.Modules
{
/// <summary>
/// Specifies the manifest for the module.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class ModuleAttribute : Attribute
{
/// <summary>
/// Set module manifest.
/// </summary>
public ModuleAttribute() : this(null) { }
/// <summary>
/// Set module manifest.
/// </summary>
public ModuleAttribute(string? name = null)
{
Name = name;
}
/// <summary>
/// Name
/// </summary>
public string? Name { get; }
/// <summary>
/// Display name
/// </summary>
public string? DisplayName { get; init; }
/// <summary>
/// Description
/// </summary>
public string? Description { get; init; }
/// <summary>
/// Version
/// </summary>
public string? Version { get; init; }
/// <summary>
/// Author
/// </summary>
public string? Author { get; init; }
/// <summary>
/// Project URL
/// </summary>
public string? Url { get; init; }
}
/// <summary>
/// Specifies the service for the module.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class ModuleServiceAttribute : Attribute
{
/// <summary>
/// Specifies the service for the module.
/// </summary>
/// <param name="implementationType">The implementation type.</param>
public ModuleServiceAttribute(Type implementationType)
{
ImplementationType = implementationType;
}
/// <summary>
/// The service type. Null to use the implement type.
/// </summary>
public Type? ServiceType { get; init; }
/// <summary>
/// The implementation type.
/// </summary>
public Type ImplementationType { get; }
/// <summary>
/// Service lifetime (default as <see cref="ServiceLifetime.Scoped"/>).
/// </summary>
public ServiceLifetime Lifetime { get; init; } = ServiceLifetime.Scoped;
/// <summary>
/// Behavior when the service been added.
/// </summary>
public ServiceRegisterBehavior RegisterBehavior { get; init; } = ServiceRegisterBehavior.Normal;
}
/// <summary>
/// Behavior when the service been added.
/// </summary>
public enum ServiceRegisterBehavior
{
/// <summary>
/// Normal (Use Add).
/// </summary>
Normal,
/// <summary>
/// The service is optional (Use TryAdd).
/// </summary>
Optional,
}
/// <summary>
/// Specifies the option for the module.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class ModuleOptionAttribute : Attribute
{
/// <summary>
/// Specifies the option for the module.
/// </summary>
/// <param name="optionType">Type for the option.</param>
public ModuleOptionAttribute(Type optionType)
{
OptionType = optionType;
}
/// <summary>
/// Type for the option.
/// </summary>
public Type OptionType { get; }
}
/// <summary>
/// Specifies the startup for the module.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class ModuleStartupAttribute : Attribute
{
/// <summary>
/// Specifies the startup for the module.
/// </summary>
/// <param name="startupType">The startup type. It must implement <see cref="IModuleStartup"/>.</param>
public ModuleStartupAttribute(Type startupType)
{
StartupType = startupType;
}
/// <summary>
/// The startup type. It must implement <see cref="IModuleStartup"/>.
/// </summary>
public Type StartupType { get; }
}
/// <summary>
/// Specifies the dependency for the module.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class ModuleDependencyAttribute : Attribute
{
/// <summary>
/// Specifies the dependency for the module.
/// </summary>
/// <param name="moduleType">The dependency module type. It must implement <see cref="IModule"/>.</param>
public ModuleDependencyAttribute(Type moduleType)
{
ModuleType = moduleType;
}
/// <summary>
/// The dependency module type. It must implement <see cref="IModule"/>.
/// </summary>
public Type ModuleType { get; }
}
}