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


C# Container.Get方法代码示例

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


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

示例1: TestContainerGetter

        private IEnumerable<Event> TestContainerGetter(Environment env, Container buf, List<Tuple<char, DateTime>> log)
        {
            yield return buf.Get(1);
              log.Add(Tuple.Create('g', env.Now));

              yield return env.Timeout(TimeSpan.FromSeconds(1));
              yield return buf.Get(1);
              log.Add(Tuple.Create('g', env.Now));
        }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:9,代码来源:ContainerTest.cs

示例2: should_support_instance_configuration

        public void should_support_instance_configuration()
        {
            var container = new Container(x => x.Scan.Types(new[]{typeof(IFoobar1), typeof(Foobar1)}).UseDefaultImplementations(y => y.Lifetime.Singleton()));

            var instance1 = container.Get<IFoobar1>();
            var instance2 = container.Get<IFoobar1>();

            instance1.Should().Be(instance2);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:9,代码来源:use_default_implementation_convention.cs

示例3: singleton_instances_should_always_return_the_same_instance

        public void singleton_instances_should_always_return_the_same_instance()
        {
            var container = new Container(x => x.For<object>().Use<object>().Lifetime.Singleton());

            var o1 = container.Get<object>();
            var o2 = container.Get<object>();

            o1.Should().Be(o2);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:9,代码来源:singleton_lifetime.cs

示例4: JoinedSingletonInstantiation

	    public void JoinedSingletonInstantiation() {
	        var mcd = new ManifestClassDefinition(typeof(TestServiceBaseForManifestClassTest3));
	        var components = mcd.GetComponents().ToArray();
	        var c = new Container();
	        foreach (var component  in components) {
	            c.Register(component);
	        }
	        var srv = c.Get<object>("a");
	        var srv2 = c.Get<object>("b");
            Assert.AreSame(srv,srv2);
	    }
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:11,代码来源:ComponentManifestTest.cs

示例5: the_same_instance_should_be_returned_per_call_to_get

        public void the_same_instance_should_be_returned_per_call_to_get()
        {
            var container = new Container(x => x.For<object>().Use<object>().Lifetime.Context());

            var foo1 = container.Get<Foo>();
            var foo2 = container.Get<Foo>();

            foo1.Object.Should().Be(foo1.Bar.Object);
            foo2.Object.Should().Be(foo2.Bar.Object);
            foo1.Object.Should().NotBe(foo2.Object);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:11,代码来源:context_lifetime.cs

示例6: should_not_resolve_value_type_arrays_unless_the_array_type_is_registered

        public void should_not_resolve_value_type_arrays_unless_the_array_type_is_registered()
        {
            var array = new[] { 1, 2, 3 };
            var container = new Container();

            container.Get<TypeWithArrayOfValueTypeDependency>().Ints.Should().BeNull();

            container.Configure(x => x.For<int>().Add(0));
            container.Get<TypeWithArrayOfValueTypeDependency>().Ints.Should().BeNull();

            container.Configure(x => x.For<int[]>().Use(array));
            container.Get<TypeWithArrayOfValueTypeDependency>().Ints.Should().BeEquivalentTo(array);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:13,代码来源:resolve_array_dependencies.cs

示例7: interceptors_should_not_be_executed_if_instance_is_chached

        public void interceptors_should_not_be_executed_if_instance_is_chached()
        {
            var interceptor = new Interceptor();

            var container = new Container(x => x.For<object>().Use<object>()
                .Intercept(interceptor)
                .Lifetime.Singleton());

            interceptor.ExecuteCount.Should().Be(0);
            container.Get<object>();
            interceptor.ExecuteCount.Should().Be(1);
            container.Get<object>();
            interceptor.ExecuteCount.Should().Be(1);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:14,代码来源:intercept_instance.cs

示例8: should_get_predicated_or_fallback_instance

        public void should_get_predicated_or_fallback_instance()
        {
            var defaultObject = "default";
            var namedObject = "named";

            var container = new Container(x => x.For<object>().Use(y =>
            {
                y.If(z => z.Name != Container.DefaultName)
                    .Use(namedObject);
                y.Else.Use(defaultObject);
            }));

            container.Get<Foobar>().Dependency.Should().Be(defaultObject);
            container.Get<Foobar>("not default").Dependency.Should().Be(namedObject);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:15,代码来源:conditional_instance_factory.cs

示例9: Main

		static void Main(string[] args)
		{
            var kernel = new StandardKernel();
            var container = new Container(kernel);

            Configure.With(container)
                .Commands
                    .UsingJson("JsonDB")
                .Events
                    .UsingJson("JsonDB")
                .Initialize();

            var commandCoordinator = ServiceLocator.Current.GetInstance<ICommandCoordinator>();

			var command = new CreatePerson { Id = Guid.NewGuid(), FirstName = "First", LastName = "Person" };
			var result = commandCoordinator.Handle(command);
			if( !result.Success )
			{
				Console.WriteLine("Handling of command failed");
				Console.WriteLine("Exception : {0}\nStack Trace : {1}", result.Exception.Message, result.Exception.StackTrace);
			}

			var queries = container.Get<IPersonView>();
			var persons = queries.GetAll();
			foreach (var person in persons)
			{
				Console.WriteLine("Person ({0}) - {1} {2}", person.Id, person.FirstName, person.LastName);
			}
		}
开发者ID:TormodHystad,项目名称:Bifrost,代码行数:29,代码来源:Program.cs

示例10: set_property_with_resolvable_type_should_work

        public void set_property_with_resolvable_type_should_work()
        {
            var container = new Container(x => x.For<Foobar>().Use<Foobar>().Set("ResolvableDependency"));
            var instance = container.Get<Foobar>();

            instance.ResolvableDependency.Should().NotBeNull();
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:7,代码来源:property_injection.cs

示例11: should_use_empty_enumerable_if_enumerated_type_is_not_registered_and_not_value_type

        public void should_use_empty_enumerable_if_enumerated_type_is_not_registered_and_not_value_type()
        {
            var container = new Container(x => x.For<TypeWithArrayOfObjectDependency>().Use<TypeWithArrayOfObjectDependency>());

            var instance = container.Get<TypeWithArrayOfObjectDependency>();

            instance.Objects.Should().HaveCount(0);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:8,代码来源:resolve_array_dependencies.cs

示例12: set_property_with_provided_value

        public void set_property_with_provided_value()
        {
            var dependency = new object();
            var container = new Container(x => x.For<Foobar>().Use<Foobar>().Set(y => y.ResolvableDependency, dependency));

            var instance = container.Get<Foobar>();

            instance.ResolvableDependency.Should().Be(dependency);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:9,代码来源:property_injection.cs

示例13: test

        public void test()
        {
            var container = new Container(x =>
                                                            {
                                                                x.For<IGrandParent>().Use<GrandParent>();
                                                                x.For<IParent>().Use<Parent>();
                                                                x.For<IChild>().Use<Child>();
                                                                x.For<IGrandChild>().Use<GrandChild>();
                                                            });

            var tasks = new[]
                        {
                            new Task(() => container.Get<IGrandParent>(), TaskCreationOptions.LongRunning),
                            new Task(() => container.Get<IGrandParent>(), TaskCreationOptions.LongRunning)
                        };
            tasks.ForEach(x => x.Start());
            Task.WaitAll(tasks);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:18,代码来源:resolve_from_multiple_threads_simultaneously.cs

示例14: should_use_provided_instance

        public void should_use_provided_instance()
        {
            var instance = "default instance";
            var container = new Container(x => x.For<object>().Use(instance));

            var o = container.Get<object>();

            o.Should().Be(instance);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:9,代码来源:constant_instance_factory.cs

示例15: provided_lifetime_should_be_executed

        public void provided_lifetime_should_be_executed()
        {
            var lifetime = new Lifetime();
            var container = new Container(x => x.For<object>().Use<object>().Lifetime.Use(lifetime));

            container.Get<object>();

            lifetime.Executed.ShouldBe(true);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:9,代码来源:custom_lifetime.cs


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