Skip to content

Commit

Permalink
attempt to syncroot
Browse files Browse the repository at this point in the history
  • Loading branch information
leotsarev committed Mar 20, 2020
1 parent b58523a commit b61f589
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions BoDi/BoDi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,15 @@ private object ChangeType(string name, Type keyType)

private bool isDisposed = false;
private readonly ObjectContainer baseContainer;
protected object SyncRootForChilds => new object();

private readonly Dictionary<RegistrationKey, IRegistration> registrations = new Dictionary<RegistrationKey, IRegistration>();
private readonly List<RegistrationKey> resolvedKeys = new List<RegistrationKey>();
private readonly Dictionary<RegistrationKey, object> objectPool = new Dictionary<RegistrationKey, object>();

public event Action<object> ObjectCreated;
public IObjectContainer BaseContainer => baseContainer;


public ObjectContainer(IObjectContainer baseContainer = null)
{
Expand Down Expand Up @@ -778,7 +781,12 @@ private object Resolve(Type typeToResolve, ResolutionList resolutionPath, string
}

if (baseContainer != null)
return baseContainer.GetRegistrationResult(keyToResolve);
{
lock (baseContainer.SyncRootForChilds)
{
return baseContainer.GetRegistrationResult(keyToResolve);
}
}

if (IsSpecialNamedInstanceDictionaryKey(keyToResolve))
{
Expand Down Expand Up @@ -845,7 +853,21 @@ private object ResolveObject(RegistrationKey keyToResolve, ResolutionList resolu

var resolutionPathForResolve = registrationToUse.Key == this ?
resolutionPath : new ResolutionList();
var result = registrationToUse.Value.Resolve(registrationToUse.Key, keyToResolve, resolutionPathForResolve);

object result;

if (registrationToUse.Key == this)
{
result = registrationToUse.Value.Resolve(registrationToUse.Key, keyToResolve, resolutionPathForResolve);
}
else
{
lock (registrationToUse.Key.SyncRootForChilds)
{
result = registrationToUse.Value.Resolve(registrationToUse.Key, keyToResolve, resolutionPathForResolve);
}
}

if (isImplicitTypeRegistration) // upon successful implicit registration, we register the rule, so that sub context can also get the same resolved value
AddRegistration(keyToResolve, registrationToUse.Value);
return result;
Expand Down

0 comments on commit b61f589

Please sign in to comment.