示例#1
0
        public object Create(Type type, params object[] parameters)
        {
            Type implType = null;

            if (true != TypeMapping?.FindMapping(type, out implType))
            {
                implType = type;
            }
            return(DynamicActivator.Create(implType, ServicesProvider, parameters));
        }
示例#2
0
        private bool TryRegisterInstance(Type serviceType)
        {
            if (builded)
            {
                throw new InvalidOperationException();
            }

            if (serviceType == typeof(IServicesProvider))
            {
                return(false);
            }

            if (servicesProvider.TryResolveInstance(serviceType, out var service) && service != null)
            {
                return(true);
            }

            foreach (var reg in registrations)
            {
                if (reg.Resolves(serviceType))
                {
                    if (reg.Instance != null)
                    {
                        servicesProvider.RegisterInstance(serviceType, reg.Instance);
                        return(true);
                    }

                    if (reg.Type != null)
                    {
                        service = DynamicActivator.Create(reg.Type, this);

                        foreach (var type in reg.ResolutionTypes)
                        {
                            servicesProvider.RegisterInstance(type, service);
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }