Fixed all tests
This commit is contained in:
Родитель
d48e431cb6
Коммит
e3a5c04fb5
|
@ -384,63 +384,6 @@ namespace Unity.Builder
|
|||
return Resolve(type, null, pipeline);
|
||||
}
|
||||
|
||||
public object? Resolve(Type type, IRegistration registration)
|
||||
{
|
||||
if (ReferenceEquals(Registration, registration)) throw new CircularDependencyException(type, registration.Name);
|
||||
|
||||
unsafe
|
||||
{
|
||||
var thisContext = this;
|
||||
var container = registration.LifetimeManager is ContainerControlledLifetimeManager containerControlled
|
||||
? (ContainerContext)containerControlled.Scope
|
||||
: ContainerContext;
|
||||
|
||||
var context = new BuilderContext
|
||||
{
|
||||
ContainerContext = container,
|
||||
Registration = registration,
|
||||
IsAsync = IsAsync,
|
||||
Type = type,
|
||||
List = List,
|
||||
Overrides = Overrides,
|
||||
DeclaringType = Type,
|
||||
#if !NET40
|
||||
Parent = new IntPtr(Unsafe.AsPointer(ref thisContext))
|
||||
#endif
|
||||
};
|
||||
|
||||
var manager = registration.LifetimeManager switch
|
||||
{
|
||||
null => TransientLifetimeManager.Instance,
|
||||
PerResolveLifetimeManager _ => (LifetimeManager?)context.Get(typeof(LifetimeManager)) ??
|
||||
TransientLifetimeManager.Instance,
|
||||
_ => registration.LifetimeManager
|
||||
};
|
||||
|
||||
// Check if already got value
|
||||
var value = manager.GetValue(ContainerContext.Lifetime);
|
||||
if (LifetimeManager.NoValue != value) return value;
|
||||
|
||||
if (registration.LifetimeManager is SynchronizedLifetimeManager synchronized)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = context.Pipeline(ref context);
|
||||
}
|
||||
catch
|
||||
{
|
||||
synchronized.Recover();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
else
|
||||
value = context.Pipeline(ref context);
|
||||
|
||||
manager.SetValue(value, ContainerContext.Lifetime);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public object? Resolve(Type type, string? name, ResolveDelegate<BuilderContext> pipeline)
|
||||
{
|
||||
var thisContext = this;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using Unity.Builder;
|
||||
using Unity.Lifetime;
|
||||
using Unity.Registration;
|
||||
using Unity.Resolution;
|
||||
using Unity.Storage;
|
||||
|
@ -170,5 +171,33 @@ namespace Unity
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Pipeline Creation
|
||||
|
||||
private ResolveDelegate<BuilderContext> DefaultBuildPipeline(LifetimeManager manager, Func<ResolveDelegate<BuilderContext>?> build)
|
||||
{
|
||||
ResolveDelegate<BuilderContext>? pipeline = null;
|
||||
|
||||
return (ref BuilderContext context) =>
|
||||
{
|
||||
if (null != pipeline) return pipeline(ref context);
|
||||
|
||||
lock (manager)
|
||||
{
|
||||
if (null == pipeline)
|
||||
{
|
||||
pipeline = build();
|
||||
manager.PipelineDelegate = pipeline;
|
||||
|
||||
Debug.Assert(null != pipeline);
|
||||
}
|
||||
}
|
||||
|
||||
return pipeline(ref context);
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,14 +113,7 @@ namespace Unity
|
|||
|
||||
return (ref BuilderContext context) =>
|
||||
{
|
||||
object value;
|
||||
|
||||
if (null != pipeline)
|
||||
{
|
||||
value = manager.Get(LifetimeContainer);
|
||||
if (LifetimeManager.NoValue != value) return value;
|
||||
return pipeline(ref context);
|
||||
}
|
||||
if (null != pipeline) return pipeline(ref context);
|
||||
|
||||
lock (manager)
|
||||
{
|
||||
|
@ -135,9 +128,6 @@ namespace Unity
|
|||
}
|
||||
}
|
||||
|
||||
value = manager.Get(LifetimeContainer);
|
||||
if (LifetimeManager.NoValue != value) return value;
|
||||
|
||||
try
|
||||
{
|
||||
// Build withing the scope
|
||||
|
@ -204,14 +194,7 @@ namespace Unity
|
|||
|
||||
return (ref BuilderContext context) =>
|
||||
{
|
||||
object value;
|
||||
|
||||
if (null != pipeline)
|
||||
{
|
||||
value = manager.Get(LifetimeContainer);
|
||||
if (LifetimeManager.NoValue != value) return value;
|
||||
return pipeline(ref context);
|
||||
}
|
||||
if (null != pipeline) return pipeline(ref context);
|
||||
|
||||
lock (manager)
|
||||
{
|
||||
|
@ -226,9 +209,6 @@ namespace Unity
|
|||
}
|
||||
}
|
||||
|
||||
value = manager.Get(LifetimeContainer);
|
||||
if (LifetimeManager.NoValue != value) return value;
|
||||
|
||||
return pipeline(ref context);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -64,14 +64,7 @@ namespace Unity
|
|||
|
||||
return (ref BuilderContext context) =>
|
||||
{
|
||||
object value;
|
||||
|
||||
if (null != pipeline)
|
||||
{
|
||||
value = manager.Get(LifetimeContainer);
|
||||
if (LifetimeManager.NoValue != value) return value;
|
||||
return pipeline(ref context);
|
||||
}
|
||||
if (null != pipeline) return pipeline(ref context);
|
||||
|
||||
lock (registration)
|
||||
{
|
||||
|
@ -86,9 +79,6 @@ namespace Unity
|
|||
}
|
||||
}
|
||||
|
||||
value = manager.Get(LifetimeContainer);
|
||||
if (LifetimeManager.NoValue != value) return value;
|
||||
|
||||
try
|
||||
{
|
||||
// Build withing the scope
|
||||
|
@ -153,14 +143,7 @@ namespace Unity
|
|||
|
||||
return (ref BuilderContext context) =>
|
||||
{
|
||||
object value;
|
||||
|
||||
if (null != pipeline)
|
||||
{
|
||||
value = registration.LifetimeManager.Get(LifetimeContainer);
|
||||
if (LifetimeManager.NoValue != value) return value;
|
||||
return pipeline(ref context);
|
||||
}
|
||||
if (null != pipeline) return pipeline(ref context);
|
||||
|
||||
lock (registration)
|
||||
{
|
||||
|
@ -175,9 +158,6 @@ namespace Unity
|
|||
}
|
||||
}
|
||||
|
||||
value = registration.LifetimeManager.Get(LifetimeContainer);
|
||||
if (LifetimeManager.NoValue != value) return value;
|
||||
|
||||
return pipeline(ref context);
|
||||
};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче