Exemple #1
0
        public bool Register(Type type, ICreateFactory itemFactory, int priority, bool includeBase = true)
        {
            if (providers.TryGetValue(type, out var tuple))
            {
                if (tuple.Item1 > priority)
                {
                    return(false);
                }
            }

            providers[type] = new Tuple <int, ICreateFactory>(priority, itemFactory);

            if (includeBase)
            {
                var baseType = type.GetTypeInfo().BaseType;
                if (baseType != null && baseType != typeof(object))
                {
                    Register(baseType, itemFactory, priority, includeBase);
                }

                foreach (var interf in type.GetTypeInfo().GetInterfaces())
                {
                    Register(interf, itemFactory, priority, includeBase);
                }
            }

            return(true);
        }
Exemple #2
0
 public bool TryResolve <T>(out ICreateFactory createFactory)
 {
     createFactory = null;
     if (TryResolve(typeof(T), out createFactory))
     {
         return(true);
     }
     return(false);
 }
        public ICreateFactory Resolve(Type type)
        {
            ICreateFactory value = null;

            if (Any(r => r.TryResolve(type, out value)))
            {
                return(value);
            }

            throw new KeyNotFoundException($"Instance for type '{type.Name}' not found");
        }
        public bool TryResolve <T>(out ICreateFactory createFactory)
        {
            createFactory = null;
            ICreateFactory val = null;

            if (Any(r => r.TryResolve <T>(out val)))
            {
                createFactory = val;
                return(true);
            }
            return(false);
        }
Exemple #5
0
        public bool TryResolve(Type type, out ICreateFactory createFactory)
        {
            createFactory = null;
            if (providers.TryGetValue(type, out var tuple))
            {
                createFactory = tuple.Item2;
                return(true);
            }

            var resolved = Parent?.TryResolve(type, out createFactory) ?? false;

            if (resolved && AddFromParent)
            {
                Register(type, createFactory, false);
            }

            return(resolved);
        }
Exemple #6
0
 public bool Register(Type type, ICreateFactory itemFactory, bool includeBase = true)
 {
     return(Register(type, itemFactory, 0, includeBase));
 }
Exemple #7
0
 public HomeController(ICreateFactory iCreateFactory, ISearchFactory iSearchFactory)
 {
     _iCreateFactory = iCreateFactory;
     _iSearchFactory = iSearchFactory;
 }