mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-22 08:29:18 +01:00
cleanup
This commit is contained in:
parent
db3e9a4171
commit
a725bbf8e0
4 changed files with 14 additions and 23 deletions
|
|
@ -145,7 +145,7 @@ internal class ServiceContainer : IServiceProvider, IServiceType
|
||||||
/// <param name="publicScopes">Scoped objects to be injected.</param>
|
/// <param name="publicScopes">Scoped objects to be injected.</param>
|
||||||
/// <param name="scope">The scope to be used to create scoped services.</param>
|
/// <param name="scope">The scope to be used to create scoped services.</param>
|
||||||
/// <returns>A <see cref="ValueTask"/> representing the operation.</returns>
|
/// <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 scopeImpl = scope as ServiceScopeImpl;
|
||||||
var objectType = instance.GetType();
|
var objectType = instance.GetType();
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ internal interface IServiceScope : IDisposable
|
||||||
/// but not directly to created objects.
|
/// but not directly to created objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="scopes">The scopes to add.</param>
|
/// <param name="scopes">The scopes to add.</param>
|
||||||
public void RegisterPrivateScopes(params object[] scopes);
|
void RegisterPrivateScopes(params object[] scopes);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create an object.
|
/// Create an object.
|
||||||
|
|
@ -25,7 +25,7 @@ internal interface IServiceScope : IDisposable
|
||||||
/// <param name="objectType">The type of object to create.</param>
|
/// <param name="objectType">The type of object to create.</param>
|
||||||
/// <param name="scopedObjects">Scoped objects to be included in the constructor.</param>
|
/// <param name="scopedObjects">Scoped objects to be included in the constructor.</param>
|
||||||
/// <returns>The created object.</returns>
|
/// <returns>The created object.</returns>
|
||||||
public Task<object> CreateAsync(Type objectType, params object[] scopedObjects);
|
Task<object> CreateAsync(Type objectType, params object[] scopedObjects);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Inject <see cref="PluginInterfaceAttribute" /> interfaces into public or static properties on the provided object.
|
/// 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="instance">The object instance.</param>
|
||||||
/// <param name="scopedObjects">Scoped objects to be injected.</param>
|
/// <param name="scopedObjects">Scoped objects to be injected.</param>
|
||||||
/// <returns>A <see cref="ValueTask"/> representing the status of the operation.</returns>
|
/// <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>
|
/// <summary>
|
||||||
|
|
@ -47,29 +47,20 @@ internal class ServiceScopeImpl : IServiceScope
|
||||||
private readonly List<object> privateScopedObjects = [];
|
private readonly List<object> privateScopedObjects = [];
|
||||||
private readonly ConcurrentDictionary<Type, Task<object>> scopeCreatedObjects = new();
|
private readonly ConcurrentDictionary<Type, Task<object>> scopeCreatedObjects = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>Initializes a new instance of the <see cref="ServiceScopeImpl" /> class.</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>
|
/// <param name="container">The container this scope will use to create services.</param>
|
||||||
public ServiceScopeImpl(ServiceContainer container)
|
public ServiceScopeImpl(ServiceContainer container) => this.container = container;
|
||||||
{
|
|
||||||
this.container = container;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void RegisterPrivateScopes(params object[] scopes)
|
public void RegisterPrivateScopes(params object[] scopes) =>
|
||||||
{
|
|
||||||
this.privateScopedObjects.AddRange(scopes);
|
this.privateScopedObjects.AddRange(scopes);
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<object> CreateAsync(Type objectType, params object[] scopedObjects)
|
public Task<object> CreateAsync(Type objectType, params object[] scopedObjects) =>
|
||||||
{
|
this.container.CreateAsync(objectType, scopedObjects, this);
|
||||||
return this.container.CreateAsync(objectType, scopedObjects, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ValueTask InjectPropertiesAsync(object instance, params object[] scopedObjects) =>
|
public Task InjectPropertiesAsync(object instance, params object[] scopedObjects) =>
|
||||||
this.container.InjectProperties(instance, scopedObjects, this);
|
this.container.InjectProperties(instance, scopedObjects, this);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -487,7 +487,7 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool Inject(object instance, params object[] scopedObjects)
|
public bool Inject(object instance, params object[] scopedObjects)
|
||||||
{
|
{
|
||||||
var t = this.InjectAsync(instance, scopedObjects).AsTask();
|
var t = this.InjectAsync(instance, scopedObjects);
|
||||||
t.Wait();
|
t.Wait();
|
||||||
|
|
||||||
if (t.Exception is { } e)
|
if (t.Exception is { } e)
|
||||||
|
|
@ -504,7 +504,7 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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));
|
this.plugin.ServiceScope!.InjectPropertiesAsync(instance, this.GetPublicIocScopes(scopedObjects));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,7 @@ public interface IDalamudPluginInterface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="instance">The instance to inject services into.</param>
|
/// <param name="instance">The instance to inject services into.</param>
|
||||||
/// <param name="scopedObjects">Objects to inject additionally.</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);
|
bool Inject(object instance, params object[] scopedObjects);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -330,5 +330,5 @@ public interface IDalamudPluginInterface
|
||||||
/// <param name="instance">The instance to inject services into.</param>
|
/// <param name="instance">The instance to inject services into.</param>
|
||||||
/// <param name="scopedObjects">Objects to inject additionally.</param>
|
/// <param name="scopedObjects">Objects to inject additionally.</param>
|
||||||
/// <returns>A <see cref="ValueTask"/> representing the status of the operation.</returns>
|
/// <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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue