fix: wrong parameters for IoC

This commit is contained in:
goat 2021-08-24 01:49:26 +02:00
parent 6fb19c1c81
commit 5f19abd979
No known key found for this signature in database
GPG key ID: F18F057873895461
3 changed files with 7 additions and 14 deletions

View file

@ -1,6 +1,7 @@
using System; using System;
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.Logging; using Dalamud.Logging;
@ -25,7 +26,7 @@ namespace Dalamud.CorePlugin
/// Initializes a new instance of the <see cref="PluginImpl"/> class. /// Initializes a new instance of the <see cref="PluginImpl"/> class.
/// </summary> /// </summary>
/// <param name="pluginInterface">Dalamud plugin interface.</param> /// <param name="pluginInterface">Dalamud plugin interface.</param>
public PluginImpl(DalamudPluginInterface pluginInterface) public PluginImpl(DalamudPluginInterface pluginInterface, ChatGui chatGui)
{ {
try try
{ {

View file

@ -86,13 +86,13 @@ namespace Dalamud.IoC.Internal
var instance = FormatterServices.GetUninitializedObject(objectType); var instance = FormatterServices.GetUninitializedObject(objectType);
if (!this.InjectProperties(instance, scopedObjects)) if (!this.InjectProperties(instance, resolvedParams))
{ {
Log.Error("Failed to create {TypeName}, a requested property service type could not be satisfied", objectType.FullName); Log.Error("Failed to create {TypeName}, a requested property service type could not be satisfied", objectType.FullName);
return null; return null;
} }
ctor.Invoke(instance, scopedObjects); ctor.Invoke(instance, resolvedParams);
return instance; return instance;
} }
@ -109,8 +109,6 @@ namespace Dalamud.IoC.Internal
{ {
var objectType = instance.GetType(); var objectType = instance.GetType();
Log.Information($"Injecting props into {objectType.FullName}");
var props = objectType.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | var props = objectType.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic).Where(x => x.GetCustomAttributes(typeof(PluginServiceAttribute)).Any()).Select( BindingFlags.NonPublic).Where(x => x.GetCustomAttributes(typeof(PluginServiceAttribute)).Any()).Select(
propertyInfo => propertyInfo =>
@ -129,8 +127,6 @@ namespace Dalamud.IoC.Internal
foreach (var prop in props) foreach (var prop in props)
{ {
Log.Information($"Injecting {prop.propertyInfo.Name} for type {prop.propertyInfo.PropertyType.GetType().FullName}");
var service = this.GetService(prop.propertyInfo.PropertyType, scopedObjects); var service = this.GetService(prop.propertyInfo.PropertyType, scopedObjects);
if (service == null) if (service == null)
@ -142,8 +138,6 @@ namespace Dalamud.IoC.Internal
prop.propertyInfo.SetValue(instance, service); prop.propertyInfo.SetValue(instance, service);
} }
Log.Information("Injected");
return true; return true;
} }

View file

@ -15,9 +15,7 @@ using Dalamud.Game.Text.Sanitizer;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Internal;
using Dalamud.Plugin.Internal; using Dalamud.Plugin.Internal;
using ServiceContainer = Dalamud.IoC.Internal.ServiceContainer;
namespace Dalamud.Plugin namespace Dalamud.Plugin
{ {
@ -319,7 +317,7 @@ namespace Dalamud.Plugin
/// <returns>The created and initialized type.</returns> /// <returns>The created and initialized type.</returns>
public T? Create<T>(params object[] scopedObjects) where T : class public T? Create<T>(params object[] scopedObjects) where T : class
{ {
var svcContainer = Service<ServiceContainer>.Get(); var svcContainer = Service<IoC.Internal.ServiceContainer>.Get();
var realScopedObjects = new object[scopedObjects.Length + 1]; var realScopedObjects = new object[scopedObjects.Length + 1];
realScopedObjects[0] = this; realScopedObjects[0] = this;
@ -336,7 +334,7 @@ namespace Dalamud.Plugin
/// <returns>Whether or not the injection succeeded.</returns> /// <returns>Whether or not the injection succeeded.</returns>
public bool Inject(object instance, params object[] scopedObjects) public bool Inject(object instance, params object[] scopedObjects)
{ {
var svcContainer = Service<ServiceContainer>.Get(); var svcContainer = Service<IoC.Internal.ServiceContainer>.Get();
var realScopedObjects = new object[scopedObjects.Length + 1]; var realScopedObjects = new object[scopedObjects.Length + 1];
realScopedObjects[0] = this; realScopedObjects[0] = this;