public void AddRegistry(string registryTypeName) { _pluginGraph.Log.Try(() => { Type type = new TypePath(registryTypeName).FindType(); var registry = (Registry) Activator.CreateInstance(type); registry.As<IPluginGraphConfiguration>().Configure(_pluginGraph); }).AndReportErrorAs(290, registryTypeName); }
public void can_parse_assembly_qualified_generics() { Type sampleGenericType = typeof (IConcept<AWidget>); string genericAssemblyQualifiedName = sampleGenericType.AssemblyQualifiedName; var path = new TypePath(genericAssemblyQualifiedName); path.FindType().ShouldEqual(sampleGenericType); }
public void OverrideProfile(TypePath typePath, string instanceKey) { _pluginGraph.Log.WithType(typePath, "while trying to add an override for a Profile", pluginType => { var instance = new ReferencedInstance(instanceKey); _pluginGraph.SetDefault(_lastProfile, pluginType, instance); }); }
public DoctorReport RunReport(string bootstrapperTypeName) { var report = new DoctorReport { Result = DoctorResult.Success }; IBootstrapper bootstrapper; try { var path = new TypePath(bootstrapperTypeName); Type bootstrapperType = path.FindType(); bootstrapper = (IBootstrapper) Activator.CreateInstance(bootstrapperType); } catch (Exception e) { report.Result = DoctorResult.BootstrapperCouldNotBeFound; report.ErrorMessages = e.ToString(); return report; } try { bootstrapper.BootstrapStructureMap(); PluginGraph graph = ObjectFactory.PluginGraph; if (graph.Log.ErrorCount > 0) { report.ErrorMessages = graph.Log.BuildFailureMessage(); report.Result = DoctorResult.ConfigurationErrors; } else { writeConfigurationAndValidate(report, graph); } return report; } catch (StructureMapConfigurationException ex) { report.ErrorMessages = ex.Message; report.Result = DoctorResult.ConfigurationErrors; return report; } catch (Exception ex) { report.Result = DoctorResult.BootstrapperFailure; report.ErrorMessages = ex.ToString(); return report; } }
public void ParseInstanceElement(XmlElement element) { var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); _builder.ConfigureFamily(pluginTypePath, family => { InstanceMemento memento = ConfigurationParser.CreateMemento(element); var instance = memento.ToInstance(this, family.PluginType); family.AddInstance(instance); }); }
public void ParseInstanceElement(XmlElement element) { var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); _builder.ConfigureFamily(pluginTypePath, family => { InstanceMemento memento = _mementoCreator.CreateMemento(element); family.AddInstance(memento); }); }
public Plugin PluginFor(string name) { if (name == null) throw new ArgumentNullException("name"); if (name.Contains(",")) { var pluggedType = new TypePath(name).FindType(); return PluginCache.GetPlugin(pluggedType); } return _aliases.Has(name) ? PluginCache.GetPlugin(_aliases[name]) : null; }
public void ParseAlias(XmlElement element) { var attribute = element.GetAttribute("Key"); var typeName = element.GetAttribute("Type"); if (attribute.IsEmpty() || typeName.IsEmpty()) { throw new MalformedAliasException(element.OuterXml); } _aliases[attribute] = new TypePath(typeName).FindType(); }
public void ParseDefaultElement(XmlElement element) { var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); _builder.ConfigureFamily(pluginTypePath, family => { InstanceScope scope = findScope(element); family.SetScopeTo(scope); InstanceMemento memento = _mementoCreator.CreateMemento(element); family.AddDefaultMemento(memento); }); }
public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action) { try { Type pluginType = pluginTypePath.FindType(); PluginFamily family = _pluginGraph.Families[pluginType]; action(family); } catch (Exception ex) { _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.AssemblyQualifiedName); } }
public void Call_the_action_on_configure_family_if_the_pluginType_is_found() { var typePath = new TypePath(typeof (IGateway)); bool iWasCalled = false; var builder = new GraphBuilder(new PluginGraph()); builder.ConfigureFamily(typePath, f => { Assert.AreEqual(typeof (IGateway), f.PluginType); iWasCalled = true; }); Assert.IsTrue(iWasCalled); }
public void ParseDefaultElement(XmlElement element) { var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); _builder.ConfigureFamily(pluginTypePath, family => { var scope = findScope(element); family.SetScopeTo(scope); InstanceMemento memento = ConfigurationParser.CreateMemento(element); var instance = memento.ToInstance(this, family.PluginType); family.SetDefault(instance); }); }
private void createOverrideInstance(string fullName, XmlElement instanceElement, WriteOverride function, string profileName) { string key = Profile.InstanceKeyForProfile(profileName); InstanceMemento memento = _creator.CreateMemento(instanceElement); memento.InstanceKey = key; var familyPath = new TypePath(fullName); _graphBuilder.ConfigureFamily(familyPath, family => { family.AddInstance(memento); function(fullName, key); }); }
public void AddRegistry(string registryTypeName) { var type = new TypePath(registryTypeName).FindType(); var registry = (Registry) Activator.CreateInstance(type); registry.As<IPluginGraphConfiguration>().Configure(_pluginGraph); }
public void CanBuildTypeCreatedFromType() { var path = new TypePath(GetType()); path.FindType(); }
private Plugin getPluginByType(PluginFamily family) { string pluggedTypeName = getPluggedType(); if (string.IsNullOrEmpty(pluggedTypeName)) { return null; } Type pluggedType = new TypePath(pluggedTypeName).FindType(); return PluginCache.GetPlugin(pluggedType); }
public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action) { var pluginType = pluginTypePath.FindType(); var family = _pluginGraph.Families[pluginType]; action(family); }
public void WithType(TypePath path, string context, Action<Type> action) { try { Type type = path.FindType(); action(type); } catch (StructureMapException ex) { RegisterError(ex); } catch (Exception ex) { RegisterError(131, ex, path.AssemblyQualifiedName, context); } }