/// <summary> /// Sets an instance for a binding. /// </summary> /// <param name="binding">The binding to set an instance for.</param> /// <param name="instance">The instance to set.</param> /// <param name="type">The type to set the instance for.</param> /// <param name="name">The name to set the instance for.</param> internal void SetInstance(IBinding binding, object instance, Type type, string name) { if (instance == null) { throw new InvalidOperationException($"Attempted to bind null to instance for binding of type {binding.BaseType}"); } else if (name != null) { if (!InstanceCache.IsCached(type, name)) { InstanceCache.Cache(instance, type, name); } else { throw new InvalidOperationException($"Binding for type {binding.BaseType} with name {binding.Name} attempts to override cached instance for {type}."); } } else { if (!InstanceCache.IsCached(type)) { InstanceCache.Cache(instance, type); } else { throw new InvalidOperationException($"Binding for type {binding.BaseType} attempts to override cached instance for {type}."); } } }