Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Jul 24, 2024
1 parent db3e9a4 commit a725bbf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Dalamud/IoC/Internal/ServiceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ await Task.WhenAll(
/// <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();
Expand Down
27 changes: 9 additions & 18 deletions Dalamud/IoC/Internal/ServiceScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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.
/// </summary>
/// <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.
Expand All @@ -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>
Expand All @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions Dalamud/Plugin/DalamudPluginInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public async Task<T> CreateAsync<T>(params object[] scopedObjects) where T : cla
/// <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)
Expand All @@ -504,7 +504,7 @@ public bool Inject(object instance, params object[] scopedObjects)
}

/// <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
Expand Down
4 changes: 2 additions & 2 deletions Dalamud/Plugin/IDalamudPluginInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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);
}

0 comments on commit a725bbf

Please sign in to comment.