public override IHandler GetHandler(Type service)
        {
            _ = service ?? throw new ArgumentNullException(nameof(service));

            if (selectors != null)
            {
                var selectorsOpinion = GetSelectorsOpinion(null, service);
                if (selectorsOpinion != null)
                {
                    return(selectorsOpinion);
                }
            }
            if (HandlerByServiceCache.TryGetValue(service, out var handler))
            {
                return(handler);
            }

            if (service.GetTypeInfo().IsGenericType&& service.GetTypeInfo().IsGenericTypeDefinition == false)
            {
                var openService = service.GetGenericTypeDefinition();
                if (HandlerByServiceCache.TryGetValue(openService, out handler) && handler.Supports(service))
                {
                    return(handler);
                }

                var handlerCandidates = base.GetHandlers(openService);
                return(handlerCandidates.First(x => x.Supports(service)));
            }

            return(null);
        }
Ejemplo n.º 2
0
        public override IHandler GetHandler(Type service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (selectors != null)
            {
                var selectorsOpinion = GetSelectorsOpinion(null, service);
                if (selectorsOpinion != null)
                {
                    return(selectorsOpinion);
                }
            }
            IHandler handler;

            if (HandlerByServiceCache.TryGetValue(service, out handler))
            {
                return(handler);
            }

            if (service.GetTypeInfo().IsGenericType&& service.GetTypeInfo().IsGenericTypeDefinition == false)
            {
                var openService = service.GetGenericTypeDefinition();
                if (HandlerByServiceCache.TryGetValue(openService, out handler) && handler.Supports(service))
                {
                    return(handler);
                }

                //use original, priority-based GetHandlers
                var handlerCandidates = base.GetHandlers(openService);
                foreach (var handlerCandidate in handlerCandidates)
                {
                    if (handlerCandidate.Supports(service))
                    {
                        return(handlerCandidate);
                    }
                }
            }

            return(null);
        }