• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Zenject.InjectContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Zenject.InjectContext的典型用法代码示例。如果您正苦于以下问题:C# InjectContext类的具体用法?C# InjectContext怎么用?C# InjectContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InjectContext类属于Zenject命名空间,在下文中一共展示了InjectContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetAllInstancesWithInjectSplit

        public IEnumerator<List<object>> GetAllInstancesWithInjectSplit(
            InjectContext context, List<TypeValuePair> args)
        {
            Assert.IsNotNull(context);

            var gameObjectRunner = _prefabInstantiator.Instantiate(args);

            // First get instance
            bool hasMore = gameObjectRunner.MoveNext();

            var gameObject = gameObjectRunner.Current;

            var allComponents = gameObject.GetComponentsInChildren(_componentType);

            Assert.That(allComponents.Length >= 1,
                "Expected to find at least one component with type '{0}' on prefab '{1}'",
                _componentType, _prefabInstantiator.GetPrefab().name);

            yield return allComponents.Cast<object>().ToList();

            // Now do injection
            while (hasMore)
            {
                hasMore = gameObjectRunner.MoveNext();
            }
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:26,代码来源:GetFromPrefabComponentProvider.cs


示例2: CreateInjectContext

 public InjectContext CreateInjectContext(
     DiContainer container, InjectContext currentContext, object targetInstance, string concreteIdentifier)
 {
     return new InjectContext(
         container, MemberType, Identifier, Optional,
         ObjectType, targetInstance, MemberName, currentContext, concreteIdentifier);
 }
开发者ID:RainsSoft,项目名称:Zenject,代码行数:7,代码来源:InjectableInfo.cs


示例3: GetInstance

        public override object GetInstance(InjectContext context)
        {
            Assert.That(_componentType.DerivesFromOrEqual(context.MemberType));

            return context.Container.InstantiateComponentOnNewGameObjectExplicit(
                _componentType, _componentType.Name(), new List<TypeValuePair>(), context);
        }
开发者ID:Aszan,项目名称:Zenject,代码行数:7,代码来源:GameObjectTransientProvider.cs


示例4: GetAllInstancesWithInjectSplit

        public IEnumerator<List<object>> GetAllInstancesWithInjectSplit(InjectContext context, List<TypeValuePair> args)
        {
            Assert.IsNotNull(context);

            object instance;

            // We still want to make sure we can get the game object during validation
            var gameObj = GetGameObject(context);

            if (!_container.IsValidating || DiContainer.CanCreateOrInjectDuringValidation(_componentType))
            {
                instance = gameObj.AddComponent(_componentType);
            }
            else
            {
                instance = new ValidationMarker(_componentType);
            }

            // Note that we don't just use InstantiateComponentOnNewGameObjectExplicit here
            // because then circular references don't work
            yield return new List<object>() { instance };

            var injectArgs = new InjectArgs()
            {
                ExtraArgs = _extraArguments.Concat(args).ToList(),
                UseAllArgs = true,
                Context = context,
                ConcreteIdentifier = _concreteIdentifier,
            };

            _container.InjectExplicit(instance, _componentType, injectArgs);

            Assert.That(injectArgs.ExtraArgs.IsEmpty());
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:34,代码来源:AddToGameObjectComponentProviderBase.cs


示例5: GetAllInstancesWithInjectSplit

        public IEnumerator<List<object>> GetAllInstancesWithInjectSplit(InjectContext context, List<TypeValuePair> args)
        {
            Assert.IsNotNull(context);

            bool autoInject = false;

            var instanceType = GetTypeToCreate(context.MemberType);

            var injectArgs = new InjectArgs()
            {
                ExtraArgs = _extraArguments.Concat(args).ToList(),
                Context = context,
                ConcreteIdentifier = _concreteIdentifier,
                UseAllArgs = false,
            };

            var instance = _container.InstantiateExplicit(
                instanceType, autoInject, injectArgs);

            // Return before property/field/method injection to allow circular dependencies
            yield return new List<object>() { instance };

            injectArgs.UseAllArgs = true;

            _container.InjectExplicit(instance, instanceType, injectArgs);
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:26,代码来源:TransientProvider.cs


示例6: GetComponent

        public object GetComponent(Type componentType, InjectContext context)
        {
            if (_rootObj == null)
            {
                Assert.IsNotNull(_id.ResourcePath);

                var prefab = (GameObject)Resources.Load(_id.ResourcePath);
                Assert.IsNotNull(prefab, "Could not find prefab at resource path '{0}'", _id.ResourcePath);

                _rootObj = (GameObject)GameObject.Instantiate(prefab);

                // Note that we always want to cache _container instead of using context.Container
                // since for singletons, the container they are accessed from should not determine
                // the container they are instantiated with
                // Transients can do that but not singletons

                _rootObj.transform.SetParent(_container.DefaultParent, false);

                _rootObj.SetActive(true);

                _container.InjectGameObject(_rootObj, true, false, new object[0], context);
            }

            var component = _rootObj.GetComponentInChildren(componentType);

            if (component == null)
            {
                throw new ZenjectResolveException(
                    "Could not find component with type '{0}' in given singleton prefab".Fmt(componentType));
            }

            return component;
        }
开发者ID:terrehbyte,项目名称:RitualNow,代码行数:33,代码来源:PrefabResourceSingletonLazyCreator.cs


示例7: ValidateBinding

        public IEnumerable<ZenjectResolveException> ValidateBinding(
            Type componentType, InjectContext context)
        {
            if (!ContainsComponent(componentType))
            {
                yield return new ZenjectResolveException(
                    "Could not find component of type '{0}' in prefab with name '{1}' \nObject graph:\n{2}"
                    .Fmt(componentType.Name(), _id.Prefab.name, context.GetObjectGraphString()));
                yield break;
            }

            // In most cases componentType will be a MonoBehaviour but we also want to allow interfaces
            // And in that case we can't validate it
            if (!componentType.IsAbstract())
            {
                // Note that we always want to cache _container instead of using context.Container
                // since for singletons, the container they are accessed from should not determine
                // the container they are instantiated with
                // Transients can do that but not singletons
                foreach (var err in _container.ValidateObjectGraph(componentType, context))
                {
                    yield return err;
                }
            }
        }
开发者ID:Aszan,项目名称:Zenject,代码行数:25,代码来源:PrefabSingletonLazyCreator.cs


示例8: GetAllInstancesWithInjectSplit

        public IEnumerator<List<object>> GetAllInstancesWithInjectSplit(InjectContext context, List<TypeValuePair> args)
        {
            Assert.IsNotNull(context);

            if (_instances != null)
            {
                yield return _instances;
                yield break;
            }

            // This should only happen with constructor injection
            // Field or property injection should allow circular dependencies
            Assert.That(!_isCreatingInstance,
            "Found circular dependency when creating type '{0}'",
            _creator.GetInstanceType(context));

            _isCreatingInstance = true;

            var runner = _creator.GetAllInstancesWithInjectSplit(context, args);

            // First get instance
            bool hasMore = runner.MoveNext();

            _instances = runner.Current;
            Assert.IsNotNull(_instances);
            _isCreatingInstance = false;

            yield return _instances;

            // Now do injection
            while (hasMore)
            {
                hasMore = runner.MoveNext();
            }
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:35,代码来源:CachedProvider.cs


示例9: GetAllInstancesWithInjectSplit

        public IEnumerator<List<object>> GetAllInstancesWithInjectSplit(InjectContext context, List<TypeValuePair> args)
        {
            Assert.IsEmpty(args);
            Assert.IsNotNull(context);

            if (_container.IsValidating)
            {
                yield return new List<object>() { new ValidationMarker(context.MemberType) };
            }
            else
            {
                var result = _method(context);

                if (result == null)
                {
                    Assert.That(context.MemberType.IsPrimitive,
                        "Invalid value returned from FromMethod.  Expected non-null.");
                }
                else
                {
                    Assert.That(result.GetType().DerivesFromOrEqual(context.MemberType));
                }

                yield return new List<object>() { result };
            }
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:26,代码来源:MethodProviderUntyped.cs


示例10: GetInstance

        public override object GetInstance(InjectContext context)
        {
            Assert.That(_componentType.DerivesFromOrEqual(context.MemberType));

            if (_instance == null)
            {
                // This is valid sometimes
                //Assert.That(!_container.IsValidating,
                    //"Tried to instantiate a MonoBehaviour with type '{0}' during validation. Object graph: {1}", _componentType, DiContainer.GetCurrentObjectGraph());

                // Note that we always want to cache _container instead of using context.Container
                // since for singletons, the container they are accessed from should not determine
                // the container they are instantiated with
                // Transients can do that but not singletons

                var name = string.IsNullOrEmpty(_name) ? _componentType.Name() : _name;

                // We don't use the generic version here to avoid duplicate generic arguments to binder
                _instance = _container.InstantiateComponentOnNewGameObjectExplicit(
                    _componentType, name, new List<TypeValuePair>(), context);
                Assert.IsNotNull(_instance);
            }

            return _instance;
        }
开发者ID:JoshFisk,项目名称:Zenject,代码行数:25,代码来源:GameObjectSingletonProvider.cs


示例11: GetInstance

 public override object GetInstance(InjectContext context)
 {
     var obj = context.Container.InstantiateExplicit(
         GetTypeToInstantiate(context.MemberType), new List<TypeValuePair>(), context, null, true);
     Assert.That(obj != null);
     return obj;
 }
开发者ID:Aszan,项目名称:Zenject,代码行数:7,代码来源:TransientProvider.cs


示例12: GetSubContext

        InjectContext GetSubContext(InjectContext parent)
        {
            var subContext = parent.CreateSubContext(_contractType, _identifier);

            subContext.Optional = _isOptional;

            return subContext;
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:8,代码来源:ResolveProvider.cs


示例13: GetAllInstancesWithInjectSplit

        public IEnumerator<List<object>> GetAllInstancesWithInjectSplit(InjectContext context, List<TypeValuePair> args)
        {
            Assert.IsEmpty(args);
            Assert.IsNotNull(context);

            Assert.That(_instanceType.DerivesFromOrEqual(context.MemberType));

            yield return new List<object>() { _instance };
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:9,代码来源:InstanceProvider.cs


示例14: GetInstance

        public override object GetInstance(InjectContext context)
        {
            Assert.That(_componentType.DerivesFromOrEqual(context.MemberType));

            var name = string.IsNullOrEmpty(_name) ? _componentType.Name() : _name;

            return context.Container.InstantiateComponentOnNewGameObjectExplicit(
                _componentType, name, new List<TypeValuePair>(), context);
        }
开发者ID:JoshFisk,项目名称:Zenject,代码行数:9,代码来源:GameObjectTransientProvider.cs


示例15: GetAllInstancesWithInjectSplit

        public IEnumerator<List<object>> GetAllInstancesWithInjectSplit(InjectContext context, List<TypeValuePair> args)
        {
            Assert.IsEmpty(args);
            Assert.IsNotNull(context);

            Assert.That(_contractType.DerivesFromOrEqual(context.MemberType));

            yield return _container.ResolveAll(GetSubContext(context)).Cast<object>().ToList();
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:9,代码来源:ResolveProvider.cs


示例16: GetInstance

        public override object GetInstance(InjectContext context)
        {
            var obj = Resources.Load(_resourcePath, _concreteType);

            Assert.IsNotNull(obj,
                "Could not find resource at path '{0}' with type '{1}'", _resourcePath, _concreteType);

            return obj;
        }
开发者ID:Aszan,项目名称:Zenject,代码行数:9,代码来源:ResourceProvider.cs


示例17: GetAllInstancesWithInjectSplit

        public IEnumerator<List<object>> GetAllInstancesWithInjectSplit(InjectContext context, List<TypeValuePair> args)
        {
            Assert.IsNotNull(context);

            var subContainer = _subContainerCreator.CreateSubContainer(args);

            var subContext = CreateSubContext(context, subContainer);

            yield return subContainer.ResolveAll(subContext).Cast<object>().ToList();
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:10,代码来源:SubContainerDependencyProvider.cs


示例18: GetAllInstancesWithInjectSplit

        public IEnumerator<List<object>> GetAllInstancesWithInjectSplit(
            InjectContext context, List<TypeValuePair> args)
        {
            Assert.IsEmpty(args);

            yield return new List<object>()
            {
                _container.CreateEmptyGameObject(_gameObjectName, _groupName)
            };
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:10,代码来源:EmptyGameObjectProvider.cs


示例19: GetInstance

        public object GetInstance(InjectContext context)
        {
            if (_instance == null)
            {
                InitInstance(context);
                Assert.IsNotNull(_instance);
            }

            return _instance;
        }
开发者ID:terrehbyte,项目名称:RitualNow,代码行数:10,代码来源:TypeSingletonLazyCreator.cs


示例20: ValidateBinding

 public IEnumerable<ZenjectResolveException> ValidateBinding(InjectContext context)
 {
     // Note that we always want to cache _container instead of using context.Container
     // since for singletons, the container they are accessed from should not determine
     // the container they are instantiated with
     // Transients can do that but not singletons
     foreach (var err in _container.ValidateObjectGraph(_id.ConcreteType, context))
     {
         yield return err;
     }
 }
开发者ID:Aszan,项目名称:Zenject,代码行数:11,代码来源:GameObjectSingletonLazyCreator.cs



注:本文中的Zenject.InjectContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Networking.Packet类代码示例发布时间:2022-05-26
下一篇:
C# Zenject.DiContainer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap