protected override object build(Type pluginType, BuildSession session) { return(new ClassWithNoArgs { TheAddress = (Address)session.GetInstance(typeof(Address)) }); }
protected override object build(Type pluginType, BuildSession session) { var container = session.GetInstance <IContainer>(); Func <string, T> func = name => container.GetInstance <T>(name); return(func); }
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)); }
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)); }); }
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); }
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'"); }
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>(); }
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); }
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); }
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)); }); }
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'"); }
protected override object build(Type pluginType, BuildSession session) { return new ClassWithNoArgs { TheAddress = (Address) session.GetInstance(typeof (Address)) }; }
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); }
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); }
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>(); }
protected override object build(Type pluginType, BuildSession session) { var inner = session.GetInstance <DocumentStoreBuilder <T> >().Build(); return(new DocumentStore <T>(inner)); }