Exemple #1
0
        private object ResolveInstance(ContainerEntry entry)
        {
            switch (entry.Lifetime)
            {
            case Lifetime.Singleton: return(entry.Instance);

            case Lifetime.None: return(entry.FactoryMethod(this));

            default: throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
        private ContainerEntry GetOrCreateEntry(Type service, string name)
        {
            var entry = GetEntry(service, name);

            if (entry == null)
            {
                entry = new ContainerEntry(this)
                {
                    ServiceType = service, Name = name
                };
                entries.Add(entry);
            }
            else
            {
                throw new InvalidOperationException($"An entry of type {service.FullName} was already registered with the name {name}.");
            }

            return(entry);
        }