Пример #1
0
        public DependencyNode([NotNull] AutowireContext context)
        {
            Ensure.Any.IsNotNull(context, nameof(context));

            Instance     = context.Node;
            Dependencies = new HashSet <DependencyNode>();

            _resolver          = context;
            _processor         = _ => context.Build();
            _deferredProcessor = null;
        }
Пример #2
0
        public DependencyNode(AutowireContext context)
        {
            Ensure.That(context, nameof(context)).IsNotNull();

            Instance     = context.Node;
            Dependencies = HashSet <DependencyNode>();

            Debug.Assert(Instance != null, "Instance != null");

            _resolver = context;

            _processor = _ => context.Build();
        }
Пример #3
0
        public static IAutowireContext GetAutowireContext(this Node node)
        {
            var current = node;

            while (current != null)
            {
                var target = current.FindDelegate().IfNone(current);
                var type   = target.GetType();

                var attribute = AttributeCache.GetOrCreate(
                    type, _ => type.GetCustomAttribute <AutowireContextAttribute>(true));

                if (attribute != null)
                {
                    return(AutowireContext.GetOrCreate(target));
                }

                current = current.GetParent();
            }

            return(GetRootContext(node));
        }
Пример #4
0
        public static IAutowireContext GetAutowireContext([NotNull] this Node node)
        {
            Ensure.Any.IsNotNull(node, nameof(node));

            var current = node;

            while (current != null)
            {
                var type = current.GetType();

                var attribute = AttributeCache.GetOrCreate(
                    type, _ => type.GetCustomAttribute <AutowireContextAttribute>(true));

                if (attribute != null)
                {
                    return(AutowireContext.GetOrCreate(current));
                }

                current = current.GetParent();
            }

            return(GetRootContext(node));
        }
Пример #5
0
        public static IEnumerable <T> FindServices <T>(this AutowireContext context)
        {
            Ensure.That(context, nameof(context)).IsNotNull();

            return(context.FindService <IEnumerable <T> >().AsEnumerable().Flatten());
        }
Пример #6
0
 internal void Register([NotNull] AutowireContext context) => Register(new DependencyNode(context));
Пример #7
0
 public static IAutowireContext GetRootContext([NotNull] this Node node) =>
 AutowireContext.GetOrCreate(node.GetTree().Root);
Пример #8
0
        public static IAutowireContext GetRootContext(this Node node)
        {
            Ensure.That(node, nameof(node)).IsNotNull();

            return(AutowireContext.GetOrCreate(node.GetTree().Root));
        }