コード例 #1
0
 protected override object build(Type pluginType, BuildSession session)
 {
     return(new ClassWithNoArgs
     {
         TheAddress = (Address)session.GetInstance(typeof(Address))
     });
 }
コード例 #2
0
        protected override object build(Type pluginType, BuildSession session)
        {
            var container         = session.GetInstance <IContainer>();
            Func <string, T> func = name => container.GetInstance <T>(name);

            return(func);
        }
コード例 #3
0
        protected override object build(Type pluginType, BuildSession session)
        {
            if (EnumerableInstance.IsEnumerable(pluginType))
            {
                var enumerable = new EnumerableInstance(pluginType, null);
                return(enumerable.Build(pluginType, session));
            }

            return(session.GetInstance(pluginType));
        }
コード例 #4
0
        public void When_calling_GetInstance_if_no_default_can_be_found_throw_202()
        {
            var graph = new RootPipelineGraph(new PluginGraph());

            assertActionThrowsErrorCode(202, delegate
            {
                var session = new BuildSession(graph);
                session.GetInstance(typeof(IGateway));
            });
        }
コード例 #5
0
ファイル: DefaultInstance.cs プロジェクト: visit/structuremap
        protected override object build(Type pluginType, BuildSession session)
        {
            if (EnumerableInstance.IsEnumerable(pluginType))
            {
                var enumerable = new EnumerableInstance(pluginType, null);
                return enumerable.Build(pluginType, session);
            }

            return session.GetInstance(pluginType);
        }
コード例 #6
0
        public void When_calling_GetInstance_if_no_default_can_be_found_throw_202()
        {
            var graph = PipelineGraph.BuildEmpty();


            var ex = Exception <StructureMapConfigurationException> .ShouldBeThrownBy(() => {
                var session = new BuildSession(graph);
                session.GetInstance(typeof(IGateway));
            });

            ex.Context.ShouldContain("There is no configuration specified for StructureMap.Testing.Widget3.IGateway");

            ex.Title.ShouldEqual("No default Instance is registered and cannot be automatically determined for type 'StructureMap.Testing.Widget3.IGateway'");
        }
コード例 #7
0
        public void Can_get_an_instance_using_the_non_generic_method()
        {
            var registry = new Registry();

            registry.For <IFooService>().Use <Service>();

            var graph = registry.Build();

            var session = new BuildSession(graph);

            var instance = session.GetInstance(typeof(IFooService));

            instance.ShouldNotBeNull();
            instance.ShouldBeOfType <Service>();
        }
コード例 #8
0
        public void when_retrieving_an_object_by_name()
        {
            var red   = new ColorService("red");
            var green = new ColorService("green");

            var          graph  = new PluginGraph();
            PluginFamily family = graph.FindFamily(typeof(IService));

            family.AddInstance(new ObjectInstance(red).WithName("red"));
            family.AddInstance(new ObjectInstance(green).WithName("green"));

            var session = new BuildSession(graph);

            session.GetInstance <IService>("red").ShouldBeTheSameAs(red);
        }
コード例 #9
0
        public void when_retrieving_an_object_by_nongeneric_type_and_name()
        {
            var red   = new ColorService("red");
            var green = new ColorService("green");

            var registry = new Registry();

            registry.For <IService>().Add(red).Named("red");
            registry.For <IService>().Add(green).Named("green");
            var graph = registry.Build();

            var session = new BuildSession(graph);

            session.GetInstance(typeof(IService), "red").ShouldBeTheSameAs(red);
        }
コード例 #10
0
        public void When_calling_GetInstance_if_no_default_can_be_found_throw_202()
        {
            var graph = new RootPipelineGraph(new PluginGraph());

            assertActionThrowsErrorCode(202, delegate
            {
                var session = new BuildSession(graph);
                session.GetInstance(typeof (IGateway));
            });
        }
コード例 #11
0
        public void When_calling_GetInstance_if_no_default_can_be_found_throw_202()
        {
            var graph = PipelineGraph.BuildEmpty();

            var ex = Exception<StructureMapConfigurationException>.ShouldBeThrownBy(() =>
            {
                var session = new BuildSession(graph);
                session.GetInstance(typeof (IGateway));
            });

            ex.Context.ShouldContain("There is no configuration specified for StructureMap.Testing.Widget3.IGateway");

            ex.Title.ShouldBe(
                "No default Instance is registered and cannot be automatically determined for type 'StructureMap.Testing.Widget3.IGateway'");
        }
コード例 #12
0
 protected override object build(Type pluginType, BuildSession session)
 {
     return new ClassWithNoArgs
     {
         TheAddress = (Address) session.GetInstance(typeof (Address))
     };
 }
コード例 #13
0
        public void when_retrieving_an_object_by_nongeneric_type_and_name()
        {
            var red = new ColorService("red");
            var green = new ColorService("green");

            var registry = new Registry();
            registry.For<IService>().Add(red).Named("red");
            registry.For<IService>().Add(green).Named("green");
            var graph = registry.Build();

            var session = new BuildSession(graph);
            session.GetInstance(typeof(IService), "red").ShouldBeTheSameAs(red);
        }
コード例 #14
0
        public void when_retrieving_an_object_by_name()
        {
            var red = new ColorService("red");
            var green = new ColorService("green");

            var graph = new PluginGraph();
            PluginFamily family = graph.FindFamily(typeof (IService));
            family.AddInstance(new ObjectInstance(red).WithName("red"));
            family.AddInstance(new ObjectInstance(green).WithName("green"));

            var session = new BuildSession(graph);
            session.GetInstance<IService>("red").ShouldBeTheSameAs(red);
        }
コード例 #15
0
        public void Can_get_an_instance_using_the_non_generic_method()
        {
            var registry = new Registry();
            registry.For<IFooService>().Use<Service>();

            var graph = registry.Build();

            var session = new BuildSession(graph);

            var instance = session.GetInstance(typeof (IFooService));

            instance.ShouldNotBeNull();
            instance.ShouldBeOfType<Service>();
        }
コード例 #16
0
        protected override object build(Type pluginType, BuildSession session)
        {
            var inner = session.GetInstance <DocumentStoreBuilder <T> >().Build();

            return(new DocumentStore <T>(inner));
        }