mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-18 05:47:43 +01:00
IoC: Allow private scoped objects to resolve singleton services
This commit is contained in:
parent
c82bb8191d
commit
69d8968dca
9 changed files with 134 additions and 78 deletions
|
|
@ -42,8 +42,13 @@ internal static class Service<T> where T : IServiceType
|
|||
else
|
||||
ServiceManager.Log.Debug("Service<{0}>: Static ctor called", type.Name);
|
||||
|
||||
if (exposeToPlugins)
|
||||
Service<ServiceContainer>.Get().RegisterSingleton(instanceTcs.Task);
|
||||
// We can't use the service container to register itself. It does so in its constructor.
|
||||
if (typeof(T) != typeof(ServiceContainer))
|
||||
{
|
||||
Service<ServiceContainer>.Get().RegisterSingleton(
|
||||
instanceTcs.Task,
|
||||
exposeToPlugins ? ObjectInstanceVisibility.ExposedToPlugins : ObjectInstanceVisibility.Internal);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -163,7 +168,7 @@ internal static class Service<T> where T : IServiceType
|
|||
return dependencyServices;
|
||||
|
||||
var res = new List<Type>();
|
||||
|
||||
|
||||
ServiceManager.Log.Verbose("Service<{0}>: Getting dependencies", typeof(T).Name);
|
||||
|
||||
var ctor = GetServiceConstructor();
|
||||
|
|
@ -174,12 +179,12 @@ internal static class Service<T> where T : IServiceType
|
|||
.Select(x => x.ParameterType)
|
||||
.Where(x => x.GetServiceKind() != ServiceManager.ServiceKind.None));
|
||||
}
|
||||
|
||||
|
||||
res.AddRange(typeof(T)
|
||||
.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
|
||||
.Where(x => x.GetCustomAttribute<ServiceManager.ServiceDependency>(true) != null)
|
||||
.Select(x => x.FieldType));
|
||||
|
||||
|
||||
res.AddRange(typeof(T)
|
||||
.GetCustomAttributes()
|
||||
.OfType<InherentDependencyAttribute>()
|
||||
|
|
@ -351,7 +356,7 @@ internal static class Service<T> where T : IServiceType
|
|||
var ctor = GetServiceConstructor();
|
||||
if (ctor == null)
|
||||
throw new Exception($"Service \"{typeof(T).FullName}\" had no applicable constructor");
|
||||
|
||||
|
||||
var args = await ResolveInjectedParameters(ctor.GetParameters(), additionalProvidedTypedObjects)
|
||||
.ConfigureAwait(false);
|
||||
using (Timings.Start($"{typeof(T).Name} Construct"))
|
||||
|
|
@ -387,7 +392,7 @@ internal static class Service<T> where T : IServiceType
|
|||
argTask = Task.FromResult(additionalProvidedTypedObjects.Single(x => x.GetType() == argType));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
argTask = (Task<object>)typeof(Service<>)
|
||||
.MakeGenericType(argType)
|
||||
.InvokeMember(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue