private void construct(PluginGraph pluginGraph) { _interceptorLibrary = pluginGraph.InterceptorLibrary; if (!pluginGraph.IsSealed) { pluginGraph.Seal(); } _pluginGraph = pluginGraph; var thisInstance = new ObjectInstance(this); _pluginGraph.FindFamily(typeof(IContainer)).AddInstance(thisInstance); _pluginGraph.ProfileManager.SetDefault(typeof(IContainer), thisInstance); var funcInstance = new FactoryTemplate(typeof(LazyInstance <>)); _pluginGraph.FindFamily(typeof(Func <>)).AddInstance(funcInstance); _pluginGraph.ProfileManager.SetDefault(typeof(Func <>), funcInstance); pluginGraph.Log.AssertFailures(); _pipelineGraph = new PipelineGraph(pluginGraph); }
private void addDefaultToPluginFamily <T>(string name) { ObjectInstance instance = new ObjectInstance(0).WithName(name); PluginFamily family = _pluginGraph.FindFamily(typeof(T)); family.AddInstance(instance); family.DefaultInstanceKey = instance.Name; }
private void assertThatTheFamilyLifecycleIs <T>() { _parser.ParseFamily(_familyElement); PluginFamily family = _graph.FindFamily(thePluginType); Assert.IsInstanceOfType(typeof(T), family.Lifecycle); }
private void setDefault <T, U>(string key) where U : T, new() { PluginFamily family = _pluginGraph.FindFamily(typeof(T)); ConfiguredInstance instance = new ConfiguredInstance(typeof(U)).WithName(key); family.AddInstance(instance); _profile.SetDefault(typeof(T), instance); }
public void SetUp() { _graph = new PluginGraph(); PluginFamily family = _graph.FindFamily(typeof(IService)); family.AddPlugin(typeof(ColorService), "Color"); _graph.FindFamily(typeof(Rule)); }
public void CanGetPluginFamilyFromPluginGraphWithParameters() { var graph = new PluginGraph(); graph.Scan(x => x.TheCallingAssembly()); PluginFamily family1 = graph.FindFamily(typeof(IGenericService <int>)); PluginFamily family2 = graph.FindFamily(typeof(IGenericService <string>)); Assert.AreSame(graph.FindFamily(typeof(IGenericService <int>)), family1); Assert.AreSame(graph.FindFamily(typeof(IGenericService <string>)), family2); }
public void ReadChildArrayProperty() { var graph = new PluginGraph(); graph.FindFamily(typeof(Rule)).AddPlugin(typeof(ComplexRule)); MemoryInstanceMemento memento = ComplexRule.GetMemento(); memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof(ComplexRule).AssemblyQualifiedName); memento.AddChildArray("cars", new InstanceMemento[] { MemoryInstanceMemento.CreateReferencedInstanceMemento("Ford"), MemoryInstanceMemento.CreateReferencedInstanceMemento("Chevy"), MemoryInstanceMemento.CreateReferencedInstanceMemento("Dodge"), }); var instance = (IStructuredInstance)memento.ReadInstance(graph, typeof(Rule)); Instance[] instances = instance.GetChildArray("cars"); Assert.AreEqual(3, instances.Length); assertIsReference(instances[0], "Ford"); assertIsReference(instances[1], "Chevy"); assertIsReference(instances[2], "Dodge"); }
public void ExplicitPluginFamilyDefinitionOverridesImplicitDefinition() { PluginGraph pluginGraph = DataMother.GetPluginGraph("ExplicitPluginFamilyOverridesImplicitPluginFamily.xml"); PluginFamily family = pluginGraph.FindFamily(typeof(GrandChild)); Assert.AreEqual("Fred", family.DefaultInstanceKey); }
public void Process(Type type, PluginGraph graph) { graph.AddType(type); var family = graph.FindFamily(type); family.AddType(type); family.SetScopeTo(InstanceScope.Hybrid); }
public void PutsRightNumberOfPluginsIntoAFamily() { var graph = new PluginGraph(); graph.Scan(x => { x.Assembly("StructureMap.Testing.Widget"); }); graph.FindFamily(typeof(IWidget)).DefaultInstanceKey = "Blue"; graph.Seal(); PluginFamily family = graph.FindFamily(typeof(IWidget)); Assert.IsNotNull(family); Assert.AreEqual("Blue", family.DefaultInstanceKey); Assert.AreEqual(4, family.PluginCount, "3 different IWidget classes are marked as Pluggable"); }
public void AddAnInstanceFromMasterConfigToAFamilyInInclude() { PluginGraph graph = buildGraph(); PluginFamily family = graph.FindFamily(typeof(IStrategy)); Assert.IsNotNull(family.GetMemento("Blue")); Assert.IsNotNull(family.GetMemento("Red")); Assert.IsNotNull(family.GetMemento("DeepTest")); // from include }
public void Set_caching() { var registry = new Registry(); registry.ForRequestedType(typeof(ITarget)).CacheBy(InstanceScope.ThreadLocal); PluginGraph graph = registry.Build(); graph.FindFamily(typeof(ITarget)).Lifecycle.ShouldBeOfType <ThreadLocalStorageLifecycle>(); }
public void CreateTheInferredPluginCorrectly() { // Who needs the Law of Demeter? _graph.Seal(); PluginFamily family = _graph.FindFamily(typeof(IWidget)); Assert.AreEqual(4, family.InstanceCount); }
public void FindPlugins() { var graph = new PluginGraph(); graph.Scan(x => { x.Assembly("StructureMap.Testing.Widget"); x.Assembly("StructureMap.Testing.Widget2"); }); graph.FindFamily(typeof(Rule)); graph.Seal(); PluginFamily family = graph.FindFamily(typeof(Rule)); Assert.IsNotNull(family); Assert.AreEqual(5, family.PluginCount, "There are 5 Rule classes in the two assemblies"); }
public void SetUp() { var graph = new PluginGraph(); graph.Scan(x => x.Assembly("StructureMap.Testing.Widget")); DataMother.WriteDocument("IntegratedTest.XML"); MementoSource source1 = new XmlFileMementoSource("IntegratedTest.XML", "GrandChildren", "GrandChild"); MementoSource source2 = new XmlFileMementoSource("IntegratedTest.XML", "Children", "Child"); MementoSource source3 = new XmlFileMementoSource("IntegratedTest.XML", "Parents", "Parent"); graph.FindFamily(typeof(GrandChild)).AddMementoSource(source1); graph.FindFamily(typeof(Child)).AddMementoSource(source2); graph.FindFamily(typeof(Parent)).AddMementoSource(source3); container = new Container(graph); }
public void PutAnInterceptorIntoTheInterceptionChainOfAPluginFamilyInTheDSL() { var lifecycle = new StubbedLifecycle(); var registry = new Registry(); registry.BuildInstancesOf <IGateway>().LifecycleIs(lifecycle); PluginGraph pluginGraph = registry.Build(); pluginGraph.FindFamily(typeof(IGateway)).Lifecycle.ShouldBeTheSameAs(lifecycle); }
public void BuildPluginFamilyAsSingleton() { var registry = new Registry(); CreatePluginFamilyExpression <IGateway> expression = registry.BuildInstancesOf <IGateway>().Singleton(); Assert.IsNotNull(expression); PluginGraph pluginGraph = registry.Build(); PluginFamily family = pluginGraph.FindFamily(typeof(IGateway)); family.Lifecycle.ShouldBeOfType <SingletonLifecycle>(); }
public void ConfigureFamily(TypePath pluginTypePath, Action <PluginFamily> action) { try { Type pluginType = pluginTypePath.FindType(); PluginFamily family = _pluginGraph.FindFamily(pluginType); action(family); } catch (Exception ex) { _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.AssemblyQualifiedName); } }
public void PicksUpManuallyAddedPlugin() { var graph = new PluginGraph(); graph.Scan(x => { x.Assembly("StructureMap.Testing.Widget"); }); graph.FindFamily(typeof(IWidget)).DefaultInstanceKey = "Blue"; PluginFamily family = graph.FindFamily(typeof(IWidget)); family.AddPlugin(typeof(NotPluggableWidget), "NotPluggable"); graph.Seal(); Assert.IsNotNull(family); Assert.AreEqual( 5, family.PluginCount, "5 different IWidget classes are marked as Pluggable, + the manual add"); }
public void BuildsInterceptionChain() { PluginGraph pluginGraph = DataMother.BuildPluginGraphFromXml( @" <StructureMap> <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='NotPluggable'/> </PluginFamily> <PluginFamily Type='StructureMap.Testing.Widget.Rule' Assembly='StructureMap.Testing.Widget' DefaultKey='Blue'> <Interceptors> <Interceptor Type='Singleton'></Interceptor> </Interceptors> </PluginFamily> </StructureMap> "); pluginGraph.FindFamily(typeof(Rule)).Lifecycle.ShouldBeOfType(typeof(SingletonLifecycle)); // The PluginFamily for IWidget has no intercepters configured pluginGraph.FindFamily(typeof(IWidget)).Lifecycle.ShouldBeNull(); }
public void AsAnotherScope() { var registry = new Registry(); CreatePluginFamilyExpression <IGateway> expression = registry.BuildInstancesOf <IGateway>().CacheBy(InstanceScope.ThreadLocal); Assert.IsNotNull(expression); PluginGraph pluginGraph = registry.Build(); PluginFamily family = pluginGraph.FindFamily(typeof(IGateway)); family.Lifecycle.ShouldBeOfType <ThreadLocalStorageLifecycle>(); }
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 EnumSetter() { var graph = new PluginGraph(); PluginFamily family = graph.FindFamily(typeof(IGridColumn)); family.AddPlugin(typeof(EnumGridColumn)); family.AddInstance(_source.GetMemento("Enum")); var manager = new Container(graph); var column = (EnumGridColumn)manager.GetInstance <IGridColumn>("Enum"); Assert.AreEqual(FontStyleEnum.BodyText, column.FontStyle); }
public void add_type_adds_a_plugin_for_type_once_and_only_once() { var graph = new PluginGraph(); graph.AddType(typeof(IThingy), typeof(BigThingy)); PluginFamily family = graph.FindFamily(typeof(IThingy)); family.PluginCount.ShouldEqual(1); family.FindPlugin(typeof(BigThingy)).ShouldNotBeNull(); graph.AddType(typeof(IThingy), typeof(BigThingy)); family.PluginCount.ShouldEqual(1); }
public void GotPluginsThatAreMarkedAsPluggable() { var registry = new Registry(); registry.Scan(x => x.AssemblyContainingType <IWidget>()); registry.BuildInstancesOf <IWidget>(); PluginGraph pluginGraph = registry.Build(); PluginFamily pluginFamily = pluginGraph.FindFamily(typeof(IWidget)); Plugin plugin = pluginFamily.FindPlugin(typeof(ColorWidget)); Assert.IsNotNull(plugin); }
public void BuildTemplatedFamilyWithOnlyOneTemplateParameter() { var pluginGraph = new PluginGraph(); PluginFamily family = pluginGraph.FindFamily(typeof(IGenericService <>)); family.AddPlugin(typeof(GenericService <>), "Default"); family.AddPlugin(typeof(SecondGenericService <>), "Second"); family.AddPlugin(typeof(ThirdGenericService <>), "Third"); PluginFamily templatedFamily1 = family.CreateTemplatedClone(new[] { typeof(int) }); PluginFamily templatedFamily = templatedFamily1; Assert.IsNotNull(templatedFamily); Assert.AreEqual(typeof(IGenericService <int>), templatedFamily.PluginType); }
public void FindMasterInstances(PluginGraph graph) { var master = new Dictionary <Type, Instance>(); foreach (var pair in _instances) { PluginFamily family = graph.FindFamily(pair.Key); Instance masterInstance = ((IDiagnosticInstance)pair.Value) .FindInstanceForProfile(family, _name, graph.Log); master.Add(pair.Key, masterInstance); } _instances = master; }
public void BuildFamilyAndPluginThenSealAndCreateInstanceManagerWithGenericTypeWithOpenGenericParameters() { var graph = new PluginGraph(); graph.Scan(x => x.TheCallingAssembly()); PluginFamily family = graph.FindFamily(typeof(IGenericService <>)); family.DefaultInstanceKey = "Default"; family.AddPlugin(typeof(GenericService <>), "Default"); graph.Seal(); var manager = new Container(graph); }
public void CreateSetterPropertyCollectionFromExplicitPlugin() { PluginGraph pluginGraph = getPluginGraph(); PluginFamily family = pluginGraph.FindFamily(typeof(IGridColumn)); Plugin plugin = family.FindPlugin("Other"); Assert.AreEqual(2, plugin.Setters.OptionalCount); Assert.AreEqual(5, plugin.Setters.MandatoryCount); Assert.IsTrue(plugin.Setters.IsMandatory("Widget")); Assert.IsTrue(plugin.Setters.IsMandatory("FontStyle")); Assert.IsTrue(plugin.Setters.IsMandatory("ColumnName")); Assert.IsTrue(plugin.Setters.IsMandatory("Rules")); Assert.IsTrue(plugin.Setters.IsMandatory("WrapLines")); }
public void StringSetter() { var graph = new PluginGraph(); PluginFamily family = graph.FindFamily(typeof(IGridColumn)); family.AddPlugin(typeof(StringGridColumn)); InstanceMemento memento = _source.GetMemento("String"); family.AddInstance(memento); var manager = new Container(graph); var column = (StringGridColumn)manager.GetInstance <IGridColumn>("String"); Assert.AreEqual(memento.GetProperty("Name"), column.Name); }