public object GetDefault(Type pluginType, IPipelineGraph pipelineGraph) { if (_defaults.ContainsKey(pluginType)) { return(_defaults[pluginType]); } var instance = pipelineGraph.Instances.GetDefault(pluginType); if (instance == null) { var ex = new StructureMapConfigurationException( "No default Instance is registered and cannot be automatically determined for type '{0}'", pluginType.GetFullName()); if (pipelineGraph.ToModel().HasImplementationsFor(pluginType)) { ex.Context = new WhatDoIHaveWriter(pipelineGraph).GetText(new ModelQuery { PluginType = pluginType }, "No default instance is specified. The current configuration for type {0} is:".ToFormat( pluginType.GetFullName())); } else { ex.Context = "There is no configuration specified for " + pluginType.GetFullName(); } throw ex; } var lifecycle = pipelineGraph.DetermineLifecycle(pluginType, instance); var o = GetObject(pluginType, instance, lifecycle); if (!(lifecycle is UniquePerRequestLifecycle) && pluginType != typeof(IContainer)) { _defaults.Add(pluginType, o); } return(o); }
public virtual object CreateInstance(Type pluginType, string name) { var instance = _pipelineGraph.Instances.FindInstance(pluginType, name); if (instance == null) { var ex = new StructureMapConfigurationException("Could not find an Instance named '{0}' for PluginType {1}", name, pluginType.GetFullName()); ex.Context = new WhatDoIHaveWriter(_pipelineGraph).GetText(new ModelQuery { PluginType = pluginType }, "The current configuration for type {0} is:".ToFormat(pluginType.GetFullName())); throw ex; } return(FindObject(pluginType, instance)); }