mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Plugins - Add Get method to plugin to get service without a Ninject ref
This commit is contained in:
parent
3825c34be1
commit
1b6802bad7
@ -155,6 +155,19 @@ namespace Artemis.Core
|
||||
_profilers.Remove(profiler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an instance of the specified service using the plugins dependency injection container.
|
||||
/// <para>Note: To use parameters reference Ninject and use <see cref="Kernel" /> directly.</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The service to resolve.</typeparam>
|
||||
/// <returns>An instance of the service.</returns>
|
||||
public T Get<T>()
|
||||
{
|
||||
if (Kernel == null)
|
||||
throw new ArtemisPluginException("Cannot use Get<T> before the plugin finished loading");
|
||||
return Kernel.Get<T>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@ -50,7 +50,7 @@ namespace Artemis.Core
|
||||
else
|
||||
Icon = "Plugin";
|
||||
}
|
||||
|
||||
|
||||
internal PluginFeatureInfo(Plugin plugin, PluginFeatureAttribute? attribute, PluginFeature instance)
|
||||
{
|
||||
if (instance == null) throw new ArgumentNullException(nameof(instance));
|
||||
@ -124,12 +124,13 @@ namespace Artemis.Core
|
||||
public bool AlwaysEnabled { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the feature is enabled in persistent storage
|
||||
/// Gets a boolean indicating whether the feature is enabled in persistent storage
|
||||
/// </summary>
|
||||
public bool EnabledInStorage => Entity.IsEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the feature this info is associated with
|
||||
/// <para>Note: <see langword="null" /> if the associated <see cref="Plugin" /> is disabled</para>
|
||||
/// </summary>
|
||||
public PluginFeature? Instance
|
||||
{
|
||||
@ -137,12 +138,6 @@ namespace Artemis.Core
|
||||
internal set => SetAndNotify(ref _instance, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<PluginPrerequisite> Prerequisites { get; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ArePrerequisitesMet() => Prerequisites.All(p => p.IsMet());
|
||||
|
||||
internal PluginFeatureEntity Entity { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -150,5 +145,14 @@ namespace Artemis.Core
|
||||
{
|
||||
return Instance?.Id ?? "Uninitialized feature";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<PluginPrerequisite> Prerequisites { get; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ArePrerequisitesMet()
|
||||
{
|
||||
return Prerequisites.All(p => p.IsMet());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user