-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathInjectionExample.cs
More file actions
34 lines (28 loc) · 971 Bytes
/
InjectionExample.cs
File metadata and controls
34 lines (28 loc) · 971 Bytes
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
using SS.Core;
using SS.Core.ComponentInterfaces;
namespace Example.InterfaceExamples;
/// <summary>
/// An example on how to inject a component interface dependency into a constructor.
/// </summary>
public sealed class InjectionExample : IModule
{
private readonly ILogManager _logManager;
// Here we declare ILogManager as being a required dependency.
public InjectionExample(ILogManager logManager)
{
_logManager = logManager ?? throw new ArgumentNullException(nameof(logManager));
}
bool IModule.Load(IComponentBroker broker)
{
// Use it.
_logManager.LogM(LogLevel.Info, nameof(InjectionExample), "Subspace Server .NET is awesome!");
return true;
}
bool IModule.Unload(IComponentBroker broker)
{
// For the injected component interfaces,
// getting the interface is done for you, and
// releasing it is too. There's nothing to do.
return true;
}
}