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);
|
_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 />
|
/// <inheritdoc />
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -130,6 +130,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the feature this info is associated with
|
/// Gets the feature this info is associated with
|
||||||
|
/// <para>Note: <see langword="null" /> if the associated <see cref="Plugin" /> is disabled</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PluginFeature? Instance
|
public PluginFeature? Instance
|
||||||
{
|
{
|
||||||
@ -137,12 +138,6 @@ namespace Artemis.Core
|
|||||||
internal set => SetAndNotify(ref _instance, value);
|
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; }
|
internal PluginFeatureEntity Entity { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -150,5 +145,14 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
return Instance?.Id ?? "Uninitialized feature";
|
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