Beispiel #1
0
        private IFactoryExpression GetFactoryExpression(Type serviceType)
        {
            if (_factoryFinder.TryGetFactory(serviceType, out var factoryExpression))
            {
                return(factoryExpression);
            }

            var delegateInfo = serviceType.AsDelegate();

            if (delegateInfo != null)
            {
                return(new ServiceFactory(delegateInfo).Resolve(_factoryFinder));
            }

            if (serviceType.GetTypeInfo().IsGenericType)
            {
                if (typeof(Lazy <>) == serviceType.GetGenericTypeDefinition())
                {
                    return(new LazyService(serviceType).Resolve(_factoryFinder));
                }

                return(new GenericService(serviceType).Resolve(_factoryFinder));
            }

            throw new NotRegisteredServiceException(serviceType);
        }
Beispiel #2
0
        public IFactoryExpression Resolve(IFactoryFinder factoryFinder)
        {
            if (factoryFinder.TryGetFactory(_type, out var factoryExpression))
            {
                return(factoryExpression);
            }

            if (_type.GetTypeInfo().IsGenericType)
            {
                return(new GenericService(_type).Resolve(factoryFinder));
            }

            throw new NotRegisteredDependencyException(_type);
        }