Example #1
0
        protected TService ResolveImpl <TService, TFunc>(Func <TFunc, TService> factoryInvoker, string name = null, bool throwIfMissing = true)
        {
            ResolveContext <TService> context = null;
            var          identifier           = new ServiceKey(typeof(TService), typeof(TFunc), name);
            ServiceEntry entry = GetEntry(identifier);

            if (entry.IsNull())
            {
                if (throwIfMissing)
                {
                    throw new ResolutionException(Resources.CouldNotResolveType.Fmt(identifier.ServiceType));
                }

                return(default(TService));
            }

            context = new ResolveContext <TService> {
                Entry     = entry,
                Key       = identifier,
                Container = this,
                Registry  = LateRegister,
                Factory   = Functional.Curry(CreateInstance, entry, (TFunc)entry.Factory, factoryInvoker)
            };

            return(entry.LifetimeStrategy.Resolve(context));
        }
Example #2
0
        protected override ServiceEntry GetEntry(ServiceKey key)
        {
            ServiceEntry entry = base.GetEntry(key);

            if (entry.IsNull() && parentContainer.IsNotNull())
            {
                parentContainer.TryGetEntry(key, out entry);
            }

            return(entry);
        }