mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-31 21:03:43 +01:00
Add IDalamudPluginInterface.InjectAsync
This commit is contained in:
parent
4b98f4e60a
commit
db3e9a4171
4 changed files with 92 additions and 97 deletions
|
|
@ -468,7 +468,14 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa
|
|||
t.Wait();
|
||||
|
||||
if (t.Exception is { } e)
|
||||
Log.Error(e, "{who}: Failed to initialize {what}", this.plugin.Name, typeof(T).FullName ?? typeof(T).Name);
|
||||
{
|
||||
Log.Error(
|
||||
e,
|
||||
"{who}: Exception during {where}: {what}",
|
||||
this.plugin.Name,
|
||||
nameof(this.Create),
|
||||
typeof(T).FullName ?? typeof(T).Name);
|
||||
}
|
||||
|
||||
return t.IsCompletedSuccessfully ? t.Result : null;
|
||||
}
|
||||
|
|
@ -477,19 +484,29 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa
|
|||
public async Task<T> CreateAsync<T>(params object[] scopedObjects) where T : class =>
|
||||
(T)await this.plugin.ServiceScope!.CreateAsync(typeof(T), this.GetPublicIocScopes(scopedObjects));
|
||||
|
||||
/// <summary>
|
||||
/// Inject services into properties on the provided object instance.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to inject services into.</param>
|
||||
/// <param name="scopedObjects">Objects to inject additionally.</param>
|
||||
/// <returns>Whether or not the injection succeeded.</returns>
|
||||
/// <inheritdoc/>
|
||||
public bool Inject(object instance, params object[] scopedObjects)
|
||||
{
|
||||
return this.plugin.ServiceScope!.InjectPropertiesAsync(
|
||||
instance,
|
||||
this.GetPublicIocScopes(scopedObjects)).GetAwaiter().GetResult();
|
||||
var t = this.InjectAsync(instance, scopedObjects).AsTask();
|
||||
t.Wait();
|
||||
|
||||
if (t.Exception is { } e)
|
||||
{
|
||||
Log.Error(
|
||||
e,
|
||||
"{who}: Exception during {where}: {what}",
|
||||
this.plugin.Name,
|
||||
nameof(this.Inject),
|
||||
instance.GetType().FullName ?? instance.GetType().Name);
|
||||
}
|
||||
|
||||
return t.IsCompletedSuccessfully;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ValueTask InjectAsync(object instance, params object[] scopedObjects) =>
|
||||
this.plugin.ServiceScope!.InjectPropertiesAsync(instance, this.GetPublicIocScopes(scopedObjects));
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>Unregister the plugin and dispose all references.</summary>
|
||||
|
|
|
|||
|
|
@ -323,4 +323,12 @@ public interface IDalamudPluginInterface
|
|||
/// <param name="scopedObjects">Objects to inject additionally.</param>
|
||||
/// <returns>Whether or not the injection succeeded.</returns>
|
||||
bool Inject(object instance, params object[] scopedObjects);
|
||||
|
||||
/// <summary>
|
||||
/// Inject services into properties on the provided object instance.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to inject services into.</param>
|
||||
/// <param name="scopedObjects">Objects to inject additionally.</param>
|
||||
/// <returns>A <see cref="ValueTask"/> representing the status of the operation.</returns>
|
||||
ValueTask InjectAsync(object instance, params object[] scopedObjects);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue