diff --git a/BoDi/BoDi.cs b/BoDi/BoDi.cs index 069ff88..5b47390 100644 --- a/BoDi/BoDi.cs +++ b/BoDi/BoDi.cs @@ -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 registrations = new Dictionary(); private readonly List resolvedKeys = new List(); private readonly Dictionary objectPool = new Dictionary(); public event Action ObjectCreated; public IObjectContainer BaseContainer => baseContainer; + public ObjectContainer(IObjectContainer baseContainer = null) { @@ -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)) { @@ -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;