forked from PHOENIXCONTACT/MORYX-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResourceRegistrationAttribute.cs
46 lines (41 loc) · 1.53 KB
/
ResourceRegistrationAttribute.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
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
using System;
using System.Linq;
using Moryx.Container;
namespace Moryx.AbstractionLayer.Resources
{
/// <summary>
/// Simplified plugin registration attribute for resources
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class ResourceRegistrationAttribute : PluginAttribute
{
/// <summary>
/// ReadOnly Name of component.
/// For resources the name is the FullName of the type
/// </summary>
public new string Name => base.Name;
/// <summary>
/// Generic registration with lifecycle <see cref="LifeCycle.Transient"/>
/// </summary>
public ResourceRegistrationAttribute()
: base(LifeCycle.Transient, typeof(IResource))
{
}
/// <summary>
/// Constructor of custom type with lifecycle <see cref="LifeCycle.Singleton"/>
/// </summary>
public ResourceRegistrationAttribute(Type customRegistration)
: base(LifeCycle.Singleton, typeof(IResource), customRegistration)
{
}
/// <summary>
/// Constructor of custom type with lifecycle <see cref="LifeCycle.Singleton"/>
/// </summary>
public ResourceRegistrationAttribute(Type customRegistration, params Type[] customRegistrations)
: base(LifeCycle.Singleton, customRegistrations.Union(new[] { typeof(IResource), customRegistration }).ToArray())
{
}
}
}