-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathManualExample.cs
More file actions
38 lines (31 loc) · 1.18 KB
/
ManualExample.cs
File metadata and controls
38 lines (31 loc) · 1.18 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
using SS.Core;
using SS.Core.ComponentInterfaces;
namespace Example.InterfaceExamples;
/// <summary>
/// This example shows a manually gotten Component Interface
/// that is used for the entire life of the module.
/// </summary>
public sealed class ManualExample : IModule
{
private ILogManager? _logManager;
bool IModule.Load(IComponentBroker broker)
{
// You can hold onto the reference,
// but you must release it at some point.
_logManager = broker.GetInterface<ILogManager>();
// Use it, only if it was available.
// Keep in mind, GetInterface could have returned null.
// Therefore, checking for null with the ?. (null-conditional operator)
_logManager?.LogM(LogLevel.Info, nameof(ManualExample), "Subspace Server .NET is awesome!");
return true;
}
bool IModule.Unload(IComponentBroker broker)
{
// Manually gotten Component Interfaces must be manually released.
// This is necessary!
// If we had forgotten to do it, the LogManager module would not Unload.
if (_logManager is not null)
broker.ReleaseInterface(ref _logManager);
return true;
}
}