Beispiel #1
0
        ///<inheritdoc/>
        public object ResolveOrRegisterInstance(Type t, string name, Func <string, object> factory)
        {
            lock (lockObject)
            {
                var resolver = (InstanceResolver)GetResolver(t);
                if (resolver == null)
                {
                    resolver = new InstanceResolver();
                    values.TryAdd(t, resolver);
                }

                var result = resolver.Resolve(this, name, null);
                if (result == null)
                {
                    result = factory(name);
                    resolver.AddOrUpdate(name, result);
                }
                return(result);
            }
        }
Beispiel #2
0
        ///<inheritdoc/>
        public void RegisterInstance(Type t, object instance, string name = null)
        {
            lock (lockObject)
            {
                IResolver resolver;
                if (this.values.TryGetValue(t, out resolver))
                {
                    if (resolver is InstanceResolver instanceResolver)
                    {
                        instanceResolver.AddOrUpdate(name, instance);
                        return;
                    }
                    else
                    {
                        this.values.TryRemove(t, out resolver);
                    }
                }

                var instResolver = new InstanceResolver();
                this.values.TryAdd(t, instResolver);
                instResolver.AddOrUpdate(name, instance);
            }
        }