当前位置: 首页>>代码示例>>C#>>正文


C# Container.TryGetInstance方法代码示例

本文整理汇总了C#中Container.TryGetInstance方法的典型用法代码示例。如果您正苦于以下问题:C# Container.TryGetInstance方法的具体用法?C# Container.TryGetInstance怎么用?C# Container.TryGetInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Container的用法示例。


在下文中一共展示了Container.TryGetInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: force_the_cached_miss_behavior

 public void force_the_cached_miss_behavior()
 {
     var container = new Container();
     container.TryGetInstance<IFancy>().ShouldBeNull();
     container.TryGetInstance<IFancy>().ShouldBeNull();
     container.TryGetInstance<IFancy>().ShouldBeNull();
     container.TryGetInstance<IFancy>().ShouldBeNull();
     container.TryGetInstance<IFancy>().ShouldBeNull();
 }
开发者ID:slahn,项目名称:structuremap,代码行数:9,代码来源:try_get_instance.cs

示例2: miss_then_hit_after_configure_with_policy_change

        public void miss_then_hit_after_configure_with_policy_change()
        {
            var container = new Container();
            container.TryGetInstance<IFancy>().ShouldBeNull();

            container.Configure(_ => _.Policies.OnMissingFamily<FancyFamily>());

            container.TryGetInstance<IFancy>()
                .ShouldBeOfType<Very>();
        }
开发者ID:slahn,项目名称:structuremap,代码行数:10,代码来源:try_get_instance.cs

示例3: should_be_able_to_resolve_by_name

        public void should_be_able_to_resolve_by_name()
        {
            var container = new Container(_ =>
            {
                _.For<ColorRule>().MissingNamedInstanceIs.ConstructedBy(c => new ColorRule(c.RequestedName));
            });

            container.GetInstance<ColorRule>("Red").Color.ShouldBe("Red");

            container.TryGetInstance<ColorRule>("Red").Color.ShouldBe("Red");
            container.TryGetInstance<ColorRule>("Blue").Color.ShouldBe("Blue");
            container.TryGetInstance<ColorRule>("Green").Color.ShouldBe("Green");
        }
开发者ID:slahn,项目名称:structuremap,代码行数:13,代码来源:Bug_416_missing_name_instance_in_try_get_instance.cs

示例4: miss_then_hit_after_configure_adds_it

        public void miss_then_hit_after_configure_adds_it()
        {
            var container = new Container();
            container.TryGetInstance<IFancy>().ShouldBeNull();

            container.Configure(_ =>
            {
                _.For<IFancy>().Use(new NotReally());
            });

            container.TryGetInstance<IFancy>()
                .ShouldBeOfType<NotReally>();
        }
开发者ID:slahn,项目名称:structuremap,代码行数:13,代码来源:try_get_instance.cs

示例5: Repro

        public void Repro()
        {
            var container = new Container(i => {
                // Add our two registries. One is shared, the other is specific to this project.
                // NOTE: Changing the order of these two will determine which GetInstance call fails.
                i.AddRegistry<SharedRegistry>();
                i.AddRegistry<MyRegistry>();
            });

            // One of these will, depending on the order of the two AddRegistry calls above.
            container.TryGetInstance<IShared>().ShouldNotBeNull();
            container.TryGetInstance<IMine>().ShouldNotBeNull();
        }
开发者ID:goraw,项目名称:structuremap,代码行数:13,代码来源:UseSingleImplementationConventionInMultipleScans.cs

示例6: Main

        static void Main(string[] args)
        {
            //var container = new Container(x =>
            // {
            //     x.Scan(o =>
            //     {
            //         o.TheCallingAssembly();
            //         o.ExcludeNamespace("HQF.Tutorial.IOC.Common");
            //         o.AddAllTypesOf<InterfaceA>();
            //     });
            // });

            // foreach (var instance in container.Model.InstancesOf<InterfaceA>())
            // {
            //     Debug.WriteLine(instance.Name + " is " + instance.Name);

            //     Console.WriteLine(instance.Name,instance.PluginType);
            // }
           
            var container = new Container(
                x =>
                {
                    ;
                });
            var a = container.TryGetInstance<InterfaceA>();

            var myClass=new MyClass(a);
            myClass.CallPrint();
            

            Console.Read();
        }
开发者ID:huoxudong125,项目名称:HQF.Tutorial.IOC,代码行数:32,代码来源:Program.cs

示例7: Given_structuremap_when_printWhatDoIHave_then_shouldReturnWhatDoIHave

 public void Given_structuremap_when_printWhatDoIHave_then_shouldReturnWhatDoIHave()
 {
     var container = new Container(new Registering());
     var printerInstance = container.TryGetInstance<ITypeOfPrinter>();
     string blackAndWhitePrintText = printerInstance.Printing();
     Assert.Pass(container.WhatDoIHave());
 }
开发者ID:JohanWe,项目名称:Code-Sample,代码行数:7,代码来源:TestStructuremap.cs

示例8: Given_structuremapWithTryGetInstance_when_print_then_shouldReturnAppropriateTypes

 public void Given_structuremapWithTryGetInstance_when_print_then_shouldReturnAppropriateTypes()
 {
     var container = new Container(new Registering());
     var printerInstance = container.TryGetInstance<ITypeOfPrinter>();
     string blackAndWhitePrintText = printerInstance.Printing();
     Assert.Pass(blackAndWhitePrintText);
 }
开发者ID:JohanWe,项目名称:Code-Sample,代码行数:7,代码来源:TestStructuremap.cs

示例9: should_not_add_null_instance

        public void should_not_add_null_instance()
        {
            var container = new Container(x => x.For<ITest>().Use<Test>());

            container.Model.Pipeline.Instances.GetAllInstances().Any(i => i == null).ShouldBeFalse();
            container.TryGetInstance<ITest>("test").ShouldBeNull();
            container.Model.Pipeline.Instances.GetAllInstances().Any(i => i == null).ShouldBeFalse();
        }
开发者ID:khellang,项目名称:structuremap,代码行数:8,代码来源:Bug_251_do_not_add_null_values_to_plugin_family_instance_cache.cs

示例10: TryGetInstance_ServiceTypeRegistered_ReturnsInstanceOfExpectedType

        public void TryGetInstance_ServiceTypeRegistered_ReturnsInstanceOfExpectedType()
        {
            // Arrange
            var container = new Container();

            container.RegisterSingleton<ICommand>(new ConcreteCommand());

            // Act
            object command;

            container.TryGetInstance(typeof(ICommand), out command);

            // Assert
            AssertThat.IsInstanceOfType(typeof(ConcreteCommand), command);
        }
开发者ID:jamesqo,项目名称:SimpleInjector,代码行数:15,代码来源:ResolvingExtensionsTests.cs

示例11: TryGetInstance_ServiceTypeNotRegistered_ReturnsNull

        public void TryGetInstance_ServiceTypeNotRegistered_ReturnsNull()
        {
            // Arrange
            var container = new Container();

            // Act
            object command;

            container.TryGetInstance(typeof(ICommand), out command);

            // Assert
            Assert.IsNull(command, "TryGetInstance is expected to return null when the type is not registered.");
        }
开发者ID:jamesqo,项目名称:SimpleInjector,代码行数:13,代码来源:ResolvingExtensionsTests.cs

示例12: TryGetInstance_ServiceTypeRegistered_ReturnsInstance

        public void TryGetInstance_ServiceTypeRegistered_ReturnsInstance()
        {
            // Arrange
            var container = new Container();

            container.RegisterSingleton<ICommand>(new ConcreteCommand());

            // Act
            object command;

            container.TryGetInstance(typeof(ICommand), out command);

            // Assert
            Assert.IsNotNull(command, "TryGetInstance is expected to return an instance when the type is registered.");
        }
开发者ID:jamesqo,项目名称:SimpleInjector,代码行数:15,代码来源:ResolvingExtensionsTests.cs

示例13: TryGetInstanceOfT_ServiceTypeNotRegistered_ReturnsFalse

        public void TryGetInstanceOfT_ServiceTypeNotRegistered_ReturnsFalse()
        {
            // Arrange
            var container = new Container();

            // Act
            ICommand command;

            bool found = container.TryGetInstance<ICommand>(out command);

            // Assert
            Assert.IsFalse(found, "TryGetInstance<T> is expected to return false when the type is not registered.");
        }
开发者ID:jamesqo,项目名称:SimpleInjector,代码行数:13,代码来源:ResolvingExtensionsTests.cs

示例14: TryGetInstanceOfT_ServiceTypeRegistered_ReturnsTrue

        public void TryGetInstanceOfT_ServiceTypeRegistered_ReturnsTrue()
        {
            // Arrange
            var container = new Container();

            container.RegisterSingleton<ICommand>(new ConcreteCommand());

            // Act
            ICommand command;

            bool found = container.TryGetInstance<ICommand>(out command);

            // Assert
            Assert.IsTrue(found, "TryGetInstance<T> is expected to return true when the type is registered.");
        }
开发者ID:jamesqo,项目名称:SimpleInjector,代码行数:15,代码来源:ResolvingExtensionsTests.cs

示例15: complete_miss

 public void complete_miss()
 {
     var container = new Container();
     container.TryGetInstance<IFancy>()
         .ShouldBeNull();
 }
开发者ID:slahn,项目名称:structuremap,代码行数:6,代码来源:try_get_instance.cs


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