This commit is contained in:
Soreepeong 2024-07-24 19:20:39 +09:00
parent db3e9a4171
commit a725bbf8e0
4 changed files with 14 additions and 23 deletions

View file

@ -145,7 +145,7 @@ internal class ServiceContainer : IServiceProvider, IServiceType
/// <param name="publicScopes">Scoped objects to be injected.</param>
/// <param name="scope">The scope to be used to create scoped services.</param>
/// <returns>A <see cref="ValueTask"/> representing the operation.</returns>
public async ValueTask InjectProperties(object instance, object[] publicScopes, IServiceScope? scope = null)
public async Task InjectProperties(object instance, object[] publicScopes, IServiceScope? scope = null)
{
var scopeImpl = scope as ServiceScopeImpl;
var objectType = instance.GetType();

View file

@ -17,7 +17,7 @@ internal interface IServiceScope : IDisposable
/// but not directly to created objects.
/// </summary>
/// <param name="scopes">The scopes to add.</param>
public void RegisterPrivateScopes(params object[] scopes);
void RegisterPrivateScopes(params object[] scopes);
/// <summary>
/// Create an object.
@ -25,7 +25,7 @@ internal interface IServiceScope : IDisposable
/// <param name="objectType">The type of object to create.</param>
/// <param name="scopedObjects">Scoped objects to be included in the constructor.</param>
/// <returns>The created object.</returns>
public Task<object> CreateAsync(Type objectType, params object[] scopedObjects);
Task<object> CreateAsync(Type objectType, params object[] scopedObjects);
/// <summary>
/// Inject <see cref="PluginInterfaceAttribute" /> interfaces into public or static properties on the provided object.
@ -34,7 +34,7 @@ internal interface IServiceScope : IDisposable
/// <param name="instance">The object instance.</param>
/// <param name="scopedObjects">Scoped objects to be injected.</param>
/// <returns>A <see cref="ValueTask"/> representing the status of the operation.</returns>
public ValueTask InjectPropertiesAsync(object instance, params object[] scopedObjects);
Task InjectPropertiesAsync(object instance, params object[] scopedObjects);
}
/// <summary>
@ -47,29 +47,20 @@ internal class ServiceScopeImpl : IServiceScope
private readonly List<object> privateScopedObjects = [];
private readonly ConcurrentDictionary<Type, Task<object>> scopeCreatedObjects = new();
/// <summary>
/// Initializes a new instance of the <see cref="ServiceScopeImpl" /> class.
/// </summary>
/// <summary>Initializes a new instance of the <see cref="ServiceScopeImpl" /> class.</summary>
/// <param name="container">The container this scope will use to create services.</param>
public ServiceScopeImpl(ServiceContainer container)
{
this.container = container;
}
public ServiceScopeImpl(ServiceContainer container) => this.container = container;
/// <inheritdoc/>
public void RegisterPrivateScopes(params object[] scopes)
{
public void RegisterPrivateScopes(params object[] scopes) =>
this.privateScopedObjects.AddRange(scopes);
}
/// <inheritdoc />
public Task<object> CreateAsync(Type objectType, params object[] scopedObjects)
{
return this.container.CreateAsync(objectType, scopedObjects, this);
}
public Task<object> CreateAsync(Type objectType, params object[] scopedObjects) =>
this.container.CreateAsync(objectType, scopedObjects, this);
/// <inheritdoc />
public ValueTask InjectPropertiesAsync(object instance, params object[] scopedObjects) =>
public Task InjectPropertiesAsync(object instance, params object[] scopedObjects) =>
this.container.InjectProperties(instance, scopedObjects, this);
/// <summary>

View file

@ -487,7 +487,7 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa
/// <inheritdoc/>
public bool Inject(object instance, params object[] scopedObjects)
{
var t = this.InjectAsync(instance, scopedObjects).AsTask();
var t = this.InjectAsync(instance, scopedObjects);
t.Wait();
if (t.Exception is { } e)
@ -504,7 +504,7 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa
}
/// <inheritdoc/>
public ValueTask InjectAsync(object instance, params object[] scopedObjects) =>
public Task InjectAsync(object instance, params object[] scopedObjects) =>
this.plugin.ServiceScope!.InjectPropertiesAsync(instance, this.GetPublicIocScopes(scopedObjects));
#endregion

View file

@ -321,7 +321,7 @@ public interface IDalamudPluginInterface
/// </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>
/// <returns>Whether the injection succeeded.</returns>
bool Inject(object instance, params object[] scopedObjects);
/// <summary>
@ -330,5 +330,5 @@ public interface IDalamudPluginInterface
/// <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);
Task InjectAsync(object instance, params object[] scopedObjects);
}