public void SetFilledTypes_3() { PluginCache.ResetAll(); PluginCache.AddFilledType(typeof(IGateway)); Plugin plugin = PluginCache.GetPlugin(typeof(ClassWithProperties)); plugin.Setters.IsMandatory("Engine").ShouldBeFalse(); plugin.Setters.IsMandatory("Car").ShouldBeFalse(); plugin.Setters.IsMandatory("Gateway").ShouldBeTrue(); }
/// <summary> /// Inline definition of a dependency on an Array of the CHILD type. I.e. CHILD[]. /// This method can be used for either constructor arguments or setter properties /// </summary> /// <typeparam name="CHILD"></typeparam> /// <returns></returns> public ArrayDefinitionExpression <CHILD> EnumerableOf <CHILD>() { if (typeof(CHILD).IsArray) { throw new ApplicationException("Please specify the element type in the call to TheArrayOf"); } Plugin plugin = PluginCache.GetPlugin(typeof(T)); string propertyName = plugin.FindArgumentNameForEnumerableOf(typeof(CHILD)); return(TheArrayOf <CHILD>(propertyName)); }
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 fill_all_properties_of_types_in_namespace_by_generic() { var container = new Container( x => { x.SetAllProperties(policy => { policy.WithAnyTypeFromNamespaceContainingType <IService>(); }); }); Plugin plugin = PluginCache.GetPlugin(typeof(ClassWithNamedProperties)); plugin.Setters.IsMandatory("Age").ShouldBeFalse(); plugin.Setters.IsMandatory("FirstName").ShouldBeFalse(); plugin.Setters.IsMandatory("LastName").ShouldBeFalse(); plugin.Setters.IsMandatory("Gateway").ShouldBeTrue(); plugin.Setters.IsMandatory("Service").ShouldBeTrue(); }
public void fill_all_properties_matching_a_certain_name() { var container = new Container( x => { x.SetAllProperties(policy => { policy.NameMatches(name => name.EndsWith("Name")); }); }); Plugin plugin = PluginCache.GetPlugin(typeof(ClassWithNamedProperties)); plugin.Setters.IsMandatory("Age").ShouldBeFalse(); plugin.Setters.IsMandatory("FirstName").ShouldBeTrue(); plugin.Setters.IsMandatory("LastName").ShouldBeTrue(); plugin.Setters.IsMandatory("Gateway").ShouldBeFalse(); plugin.Setters.IsMandatory("Service").ShouldBeFalse(); }
public CreatePluginFamilyExpression <PLUGINTYPE> AddConcreteType <PLUGGEDTYPE>() { if (!PluginCache.GetPlugin(typeof(PLUGGEDTYPE)).CanBeAutoFilled) { throw new StructureMapException(231); } _alterations.Add(family => { string name = PluginCache.GetPlugin(typeof(PLUGGEDTYPE)).ConcreteKey; SmartInstance <PLUGGEDTYPE> instance = new SmartInstance <PLUGGEDTYPE>().WithName(name); family.AddInstance(instance); }); return(this); }
public void fill_all_properties_of_a_certain_type() { var container = new Container(x => { x.SetAllProperties(policy => { policy.OfType <string>(); policy.OfType <IGateway>(); }); }); Plugin plugin = PluginCache.GetPlugin(typeof(ClassWithNamedProperties)); plugin.Setters.IsMandatory("Age").ShouldBeFalse(); plugin.Setters.IsMandatory("FirstName").ShouldBeTrue(); plugin.Setters.IsMandatory("LastName").ShouldBeTrue(); plugin.Setters.IsMandatory("Gateway").ShouldBeTrue(); plugin.Setters.IsMandatory("Service").ShouldBeFalse(); }
public CreatePluginFamilyExpression <PLUGINTYPE> TheDefaultIsConcreteType <CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE { Type concreteType = typeof(CONCRETETYPE); ExpressionValidator.ValidatePluggabilityOf(concreteType).IntoPluginType(_pluginType); if (!PluginCache.GetPlugin(concreteType).CanBeAutoFilled) { throw new StructureMapException(231); } return(alterAndContinue(family => { ConfiguredInstance instance = new ConfiguredInstance(concreteType).WithName(concreteType.AssemblyQualifiedName); family.AddInstance(instance); family.DefaultInstanceKey = instance.Name; })); }
/// <summary> /// Use to programmatically select the constructor function of a concrete /// class. Applies globally to all Containers in a single AppDomain. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="expression"></param> public void SelectConstructor <T>(Expression <Func <T> > expression) { PluginCache.GetPlugin(typeof(T)).UseConstructor(expression); }
public ConstructorInstance(Type pluggedType) : this(PluginCache.GetPlugin(pluggedType)) { }
private string getArgumentNameForType <CTORTYPE>() { Plugin plugin = PluginCache.GetPlugin(getConcreteType(null)); return(plugin.FindArgumentNameForType <CTORTYPE>()); }
public static ReferencedInstance GetReferenceTo(this Type type) { string key = PluginCache.GetPlugin(type).ConcreteKey; return(new ReferencedInstance(key)); }
public Func <IArguments, T> CreateBuilder() { Plugin plugin = PluginCache.GetPlugin(typeof(T)); return(CreateBuilder(plugin)); }