From: <jer...@us...> - 2009-12-29 02:55:20
|
Revision: 314 http://structuremap.svn.sourceforge.net/structuremap/?rev=314&view=rev Author: jeremydmiller Date: 2009-12-29 02:55:12 +0000 (Tue, 29 Dec 2009) Log Message: ----------- API cleanup Part 1 Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/InitializationExpression.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Examples.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs trunk/Source/StructureMap.Testing/Query/GenericFamilyConfigurationTester.cs trunk/Source/StructureMap.Testing/Query/InstanceFactoryTypeConfigurationTester.cs trunk/Source/StructureMap.Testing/Query/ModelIntegrationTester.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs Added Paths: ----------- trunk/Source/StructureMap/Configuration/DSL/IRegistry.cs Removed Paths: ------------- trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -32,6 +32,7 @@ /// <summary> /// Define the Default Instance for this PluginType /// </summary> + [Obsolete("Prefer the Use() methods")] public IsExpression<PLUGINTYPE> TheDefault { get { return new InstanceExpression<PLUGINTYPE>(i => registerDefault(i)); } } public InstanceExpression<PLUGINTYPE> MissingNamedInstanceIs { get { return new InstanceExpression<PLUGINTYPE>(i => _alterations.Add(family => family.MissingInstance = i)); } } @@ -135,6 +136,7 @@ /// </summary> /// <param name="scope"></param> /// <returns></returns> + [Obsolete("Change to LifecycleIs(scope)")] public CreatePluginFamilyExpression<PLUGINTYPE> CacheBy(InstanceScope scope) { return alterAndContinue(family => family.SetScopeTo(scope)); @@ -296,6 +298,7 @@ /// </summary> /// <typeparam name="PLUGGEDTYPE"></typeparam> /// <returns></returns> + [Obsolete("Change to Add<T>()")] public CreatePluginFamilyExpression<PLUGINTYPE> AddConcreteType<PLUGGEDTYPE>() { if (!PluginCache.GetPlugin(typeof (PLUGGEDTYPE)).CanBeAutoFilled) @@ -366,9 +369,28 @@ public ObjectInstance Add(PLUGINTYPE @object) { var instance = new ObjectInstance(@object); - _alterations.Add(f => f.AddInstance(instance)); + Add(instance); return instance; } + + /// <summary> + /// Add an Instance to this type created by a Lambda + /// </summary> + /// <param name="func"></param> + /// <returns></returns> + public LambdaInstance<PLUGINTYPE> Add(Func<IContext, PLUGINTYPE> func) + { + var instance = new LambdaInstance<PLUGINTYPE>(func); + Add(instance); + + return instance; + } + + + public void Add(Instance instance) + { + _alterations.Add(f => f.AddInstance(instance)); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -39,6 +39,7 @@ /// </summary> /// <param name="concreteType"></param> /// <returns></returns> + [Obsolete("Change to Use(concreteType)")] public ConfiguredInstance TheDefaultIsConcreteType(Type concreteType) { var instance = new ConfiguredInstance(concreteType); @@ -47,6 +48,10 @@ return instance; } + /// <summary> + /// Use this configured Instance as is + /// </summary> + /// <param name="instance"></param> public void Use(Instance instance) { alterAndContinue(family => @@ -131,10 +136,18 @@ { return alterAndContinue(family => family.AddInstance(instance)); } + + /// <summary> + /// Configure this type as the supplied value + /// </summary> + /// <param name="instance"></param> + /// <returns></returns> + public ObjectInstance Add(object @object) + { + var instance = new ObjectInstance(@object); + Add(instance); - public GenericFamilyExpression Add(object instance) - { - return Add(new ObjectInstance(instance)); + return instance; } @@ -144,6 +157,7 @@ /// </summary> /// <param name="scope"></param> /// <returns></returns> + [Obsolete("Change to LifecycleIs()")] public GenericFamilyExpression CacheBy(InstanceScope scope) { return alterAndContinue(family => family.SetScopeTo(scope)); @@ -261,6 +275,7 @@ /// </summary> /// <param name="concreteType"></param> /// <returns></returns> + [Obsolete("Change to Add(Type)")] public GenericFamilyExpression AddConcreteType(Type concreteType) { var instance = new ConfiguredInstance(concreteType); @@ -276,6 +291,7 @@ /// <param name="concreteType"></param> /// <param name="instanceName"></param> /// <returns></returns> + [Obsolete("Change to Add(Type, [name)]")] public GenericFamilyExpression AddConcreteType(Type concreteType, string instanceName) { return Add(new ConfiguredInstance(concreteType).WithName(instanceName)); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -106,7 +106,16 @@ [Obsolete("Favor For<ISomething>().Use<Something>() or For<ISomething>().Add<Something>()")] SmartInstance<PLUGGEDTYPE> OfConcreteType<PLUGGEDTYPE>() where PLUGGEDTYPE : T; + /// <summary> + /// Build the Instance with the constructor function and setter arguments. Starts + /// the definition of a <see cref="SmartInstance{T}">SmartInstance</see> + /// </summary> + /// <typeparam name="PLUGGEDTYPE"></typeparam> + /// <returns></returns> + SmartInstance<PLUGGEDTYPE> Type<PLUGGEDTYPE>(); + + /// <summary> /// Build the Instance with the constructor function and setter arguments. Use this /// method for open generic types, and favor the generic version of OfConcreteType /// for all other types @@ -117,12 +126,20 @@ ConfiguredInstance OfConcreteType(Type type); /// <summary> + /// Build the Instance with the constructor function and setter arguments. Use this + /// method for open generic types, and favor the generic version of OfConcreteType + /// for all other types + /// </summary> + /// <param name="type"></param> + /// <returns></returns> + ConfiguredInstance Type(Type type); + + /// <summary> /// Create an Instance that builds an object by calling a Lambda or /// an anonymous delegate with no arguments /// </summary> /// <param name="func"></param> /// <returns></returns> - [Obsolete("Prefer For<T>().Use(Func<T> func) or For<T>().Add(Func<T> func)")] LambdaInstance<T> ConstructedBy(Func<T> func); /// <summary> @@ -218,11 +235,21 @@ return returnInstance(new SmartInstance<PLUGGEDTYPE>()); } + public SmartInstance<PLUGGEDTYPE> Type<PLUGGEDTYPE>() + { + return returnInstance(new SmartInstance<PLUGGEDTYPE>()); + } + public ConfiguredInstance OfConcreteType(Type type) { return returnInstance(new ConfiguredInstance(type)); } + public ConfiguredInstance Type(Type type) + { + return returnInstance(new ConfiguredInstance(type)); + } + public ObjectInstance Object(T theObject) { return returnInstance(new ObjectInstance(theObject)); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -35,6 +35,7 @@ /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> + [Obsolete("Prefer the For<T>().**** methods")] public IsExpression<T> Type<T>() { return @@ -76,22 +77,37 @@ /// </summary> /// <param name="concreteType"></param> /// <returns></returns> - public ProfileExpression UseConcreteType(Type concreteType) + [Obsolete("Change to Use(type)")] + public ConfiguredInstance UseConcreteType(Type concreteType) { var instance = new ConfiguredInstance(concreteType); - return Use(instance); + Use(instance); + + return instance; } /// <summary> + /// Use this concreteType for the Instance of this Profile for the PluginType + /// </summary> + /// <param name="concreteType"></param> + /// <returns></returns> + [Obsolete("Change to Use(type)")] + public ConfiguredInstance Use(Type concreteType) + { + var instance = new ConfiguredInstance(concreteType); + Use(instance); + + return instance; + } + + /// <summary> /// Use this Instance for the Profile Instance of this Plugin Type /// </summary> /// <param name="instance"></param> /// <returns></returns> - public ProfileExpression Use(Instance instance) + public void Use(Instance instance) { _registry.addExpression(graph => graph.SetDefault(_parent._profileName, _pluginType, instance)); - - return _parent; } @@ -100,11 +116,38 @@ /// </summary> /// <param name="name"></param> /// <returns></returns> - public ProfileExpression UseNamedInstance(string name) + [Obsolete("Change to Use([name])")] + public void UseNamedInstance(string name) { var instance = new ReferencedInstance(name); - return Use(instance); + Use(instance); } + + /// <summary> + /// Use the named Instance as the Profile Instance for this PluginType + /// </summary> + /// <param name="name"></param> + /// <returns></returns> + public ReferencedInstance Use(string name) + { + var instance = new ReferencedInstance(name); + Use(instance); + + return instance; + } + + /// <summary> + /// For this type and profile, build the object with this Lambda + /// </summary> + /// <param name="func"></param> + /// <returns></returns> + public LambdaInstance<object> Use(Func<IContext, object> func) + { + var instance = new LambdaInstance<object>(func); + Use(instance); + + return instance; + } } #endregion @@ -133,6 +176,7 @@ /// </summary> /// <param name="instanceKey"></param> /// <returns></returns> + [Obsolete("Change to For<T>().Use([name])")] public ProfileExpression UseNamedInstance(string instanceKey) { _registry.addExpression( @@ -142,17 +186,39 @@ } /// <summary> + /// Use a named, preconfigured instance as the default instance for this profile + /// </summary> + /// <param name="instanceKey"></param> + /// <returns></returns> + public void Use(string instanceKey) + { + _registry.addExpression( + graph => graph.SetDefault(_profileName, typeof(T), new ReferencedInstance(instanceKey))); + } + + /// <summary> /// Define the default instance of the PluginType for the containing Profile /// </summary> /// <param name="instance"></param> /// <returns></returns> - public ProfileExpression Use(Instance instance) + public void Use(Instance instance) { instance.Name = "Default Instance for Profile " + _profileName; _registry.addExpression(graph => graph.SetDefault(_profileName, typeof (T), instance)); + } - return _parent; + /// <summary> + /// For this Profile, use an Instance with this Func + /// </summary> + /// <param name="func"></param> + /// <returns></returns> + public LambdaInstance<T> Use(Func<T> func) + { + var instance = new LambdaInstance<T>(func); + Use(instance); + + return instance; } /// <summary> @@ -160,10 +226,12 @@ /// </summary> /// <param name="func"></param> /// <returns></returns> - public ProfileExpression Use(Func<T> func) + public LambdaInstance<T> Use(Func<IContext, T> func) { var instance = new LambdaInstance<T>(func); - return Use(instance); + Use(instance); + + return instance; } /// <summary> @@ -171,10 +239,12 @@ /// </summary> /// <param name="t"></param> /// <returns></returns> - public ProfileExpression Use(T t) + public ObjectInstance Use(T t) { var instance = new ObjectInstance(t); - return Use(instance); + Use(instance); + + return instance; } /// <summary> @@ -182,11 +252,25 @@ /// </summary> /// <typeparam name="CONCRETETYPE"></typeparam> /// <returns></returns> - public ProfileExpression UseConcreteType<CONCRETETYPE>() + [Obsolete("Change to For<T>().Use<CONCRETETYPE>()")] + public void UseConcreteType<CONCRETETYPE>() { var instance = new ConfiguredInstance(typeof (CONCRETETYPE)); - return Use(instance); + Use(instance); } + + /// <summary> + /// For this profile, use this concrete type + /// </summary> + /// <typeparam name="CONCRETETYPE"></typeparam> + /// <returns></returns> + public SmartInstance<CONCRETETYPE> Use<CONCRETETYPE>() + { + var instance = new SmartInstance<CONCRETETYPE>(); + Use(instance); + + return instance; + } } #endregion Added: trunk/Source/StructureMap/Configuration/DSL/IRegistry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/IRegistry.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/IRegistry.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -0,0 +1,235 @@ +using System; +using System.Linq.Expressions; +using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Graph; +using StructureMap.Interceptors; +using StructureMap.Pipeline; + +namespace StructureMap.Configuration.DSL +{ + public interface IRegistry + { + /// <summary> + /// Adds the concreteType as an Instance of the pluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="concreteType"></param> + void AddType(Type pluginType, Type concreteType); + + /// <summary> + /// Adds the concreteType as an Instance of the pluginType with a name + /// </summary> + /// <param name="pluginType"></param> + /// <param name="concreteType"></param> + /// <param name="name"></param> + void AddType(Type pluginType, Type concreteType, string name); + + /// <summary> + /// Add the pluggedType as an instance to any configured pluginType where pluggedType + /// could be assigned to the pluginType + /// </summary> + /// <param name="pluggedType"></param> + void AddType(Type pluggedType); + + /// <summary> + /// Imports the configuration from another registry into this registry. + /// </summary> + /// <typeparam name="T"></typeparam> + void IncludeRegistry<T>() where T : Registry, new(); + + /// <summary> + /// Imports the configuration from another registry into this registry. + /// </summary> + /// <param name="registry"></param> + void IncludeRegistry(Registry registry); + + /// <summary> + /// Expression Builder used to define policies for a PluginType including + /// Scoping, the Default Instance, and interception. BuildInstancesOf() + /// and ForRequestedType() are synonyms + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <returns></returns> + [Obsolete("Change to For<T>()")] + CreatePluginFamilyExpression<PLUGINTYPE> BuildInstancesOf<PLUGINTYPE>(); + + /// <summary> + /// Expression Builder used to define policies for a PluginType including + /// Scoping, the Default Instance, and interception. This method is specifically + /// meant for registering open generic types + /// </summary> + /// <returns></returns> + [Obsolete("Change to For(pluginType)")] + GenericFamilyExpression ForRequestedType(Type pluginType); + + /// <summary> + /// This method is a shortcut for specifying the default constructor and + /// setter arguments for a ConcreteType. ForConcreteType is shorthand for: + /// ForRequestedType[T]().TheDefault.Is.OfConcreteType[T].************** + /// when the PluginType and ConcreteType are the same Type + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + Registry.BuildWithExpression<T> ForConcreteType<T>(); + + /// <summary> + /// Expression Builder used to define policies for a PluginType including + /// Scoping, the Default Instance, and interception. BuildInstancesOf() + /// and ForRequestedType() are synonyms + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <returns></returns> + [Obsolete("Change to For<T>()")] + CreatePluginFamilyExpression<PLUGINTYPE> ForRequestedType<PLUGINTYPE>(); + + /// <summary> + /// Convenience method. Equivalent of ForRequestedType[PluginType]().AsSingletons() + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <returns></returns> + CreatePluginFamilyExpression<PLUGINTYPE> ForSingletonOf<PLUGINTYPE>(); + + /// <summary> + /// Uses the configuration expressions of this Registry to create a PluginGraph + /// object that could be used to initialize a Container. This method is + /// mostly for internal usage, but might be helpful for diagnostics + /// </summary> + /// <returns></returns> + PluginGraph Build(); + + /// <summary> + /// Adds an additional, non-Default Instance to the PluginType T. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + [Obsolete("Prefer For<T>().Add() instead")] + IsExpression<T> InstanceOf<T>(); + + /// <summary> + /// Adds an additional, non-Default Instance to the designated pluginType + /// This method is mostly meant for open generic types + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + [Obsolete("Prefer For(type).Add() instead")] + GenericIsExpression InstanceOf(Type pluginType); + + /// <summary> + /// Expression Builder to define the defaults for a named Profile. Each call + /// to CreateProfile is additive. + /// </summary> + /// <param name="profileName"></param> + /// <returns></returns> + ProfileExpression Profile(string profileName); + + /// <summary> + /// An alternative way to use CreateProfile that uses ProfileExpression + /// as a Nested Closure. This usage will result in cleaner code for + /// multiple declarations + /// </summary> + /// <param name="profileName"></param> + /// <param name="action"></param> + void Profile(string profileName, Action<ProfileExpression> action); + + /// <summary> + /// Registers a new TypeInterceptor object with the Container + /// </summary> + /// <param name="interceptor"></param> + void RegisterInterceptor(TypeInterceptor interceptor); + + /// <summary> + /// Allows you to define a TypeInterceptor inline with Lambdas or anonymous delegates + /// </summary> + /// <param name="match"></param> + /// <returns></returns> + /// <example> + /// IfTypeMatches( ... ).InterceptWith( o => new ObjectWrapper(o) ); + /// </example> + MatchedTypeInterceptor IfTypeMatches(Predicate<Type> match); + + /// <summary> + /// Designates a policy for scanning assemblies to auto + /// register types + /// </summary> + /// <returns></returns> + void Scan(Action<IAssemblyScanner> action); + + /// <summary> + /// Directs StructureMap to always inject dependencies into any and all public Setter properties + /// of the type PLUGINTYPE. + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <returns></returns> + CreatePluginFamilyExpression<PLUGINTYPE> FillAllPropertiesOfType<PLUGINTYPE>(); + + /// <summary> + /// Creates automatic "policies" for which public setters are considered mandatory + /// properties by StructureMap that will be "setter injected" as part of the + /// construction process. + /// </summary> + /// <param name="action"></param> + void SetAllProperties(Action<SetterConvention> action); + + /// <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> + void SelectConstructor<T>(Expression<Func<T>> expression); + + /// <summary> + /// All requests For the "TO" types will be filled by fetching the "FROM" + /// type and casting it to "TO" + /// GetInstance(typeof(TO)) basically becomes (TO)GetInstance(typeof(FROM)) + /// </summary> + /// <typeparam name="FROM"></typeparam> + /// <typeparam name="TO"></typeparam> + void Forward<FROM, TO>() where FROM : class where TO : class; + + /// <summary> + /// Syntactic Sugar for saying ForRequestedType().TheDefault.IsThis( @object ) + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <param name="object"></param> + void Register<PLUGINTYPE>(PLUGINTYPE @object); + + /// <summary> + /// Syntactic Sugar for saying ForRequestedType().TheDefault.IsThis( instance ) + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <param name="instance"></param> + void Register<PLUGINTYPE>(Instance instance); + + /// <summary> + /// Shorthand for ForRequestedType<PLUGINTYPE>() + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <returns></returns> + CreatePluginFamilyExpression<PLUGINTYPE> For<PLUGINTYPE>(); + + /// <summary> + /// Shorthand for ForRequestedType(pluginType) + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + GenericFamilyExpression For(Type pluginType); + + /// <summary> + /// Shortcut to make StructureMap return the default object of U casted to T + /// whenever T is requested. I.e.: + /// For<T>().TheDefault.Is.ConstructedBy(c => c.GetInstance<U>() as T); + /// </summary> + /// <typeparam name="T"></typeparam> + /// <typeparam name="U"></typeparam> + /// <returns></returns> + LambdaInstance<T> Redirect<T, U>() where T : class where U : class; + + /// <summary> + /// Advanced Usage Only! Skips the Registry and goes right to the inner + /// Semantic Model of StructureMap. Use with care + /// </summary> + /// <param name="configure"></param> + void Configure(Action<PluginGraph> configure); + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -8,232 +8,6 @@ namespace StructureMap.Configuration.DSL { - public interface IRegistry - { - /// <summary> - /// Adds the concreteType as an Instance of the pluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="concreteType"></param> - void AddType(Type pluginType, Type concreteType); - - /// <summary> - /// Adds the concreteType as an Instance of the pluginType with a name - /// </summary> - /// <param name="pluginType"></param> - /// <param name="concreteType"></param> - /// <param name="name"></param> - void AddType(Type pluginType, Type concreteType, string name); - - /// <summary> - /// Add the pluggedType as an instance to any configured pluginType where pluggedType - /// could be assigned to the pluginType - /// </summary> - /// <param name="pluggedType"></param> - void AddType(Type pluggedType); - - /// <summary> - /// Imports the configuration from another registry into this registry. - /// </summary> - /// <typeparam name="T"></typeparam> - void IncludeRegistry<T>() where T : Registry, new(); - - /// <summary> - /// Imports the configuration from another registry into this registry. - /// </summary> - /// <param name="registry"></param> - void IncludeRegistry(Registry registry); - - /// <summary> - /// Expression Builder used to define policies for a PluginType including - /// Scoping, the Default Instance, and interception. BuildInstancesOf() - /// and ForRequestedType() are synonyms - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <returns></returns> - [Obsolete("Change to For<T>()")] - CreatePluginFamilyExpression<PLUGINTYPE> BuildInstancesOf<PLUGINTYPE>(); - - /// <summary> - /// Expression Builder used to define policies for a PluginType including - /// Scoping, the Default Instance, and interception. This method is specifically - /// meant for registering open generic types - /// </summary> - /// <returns></returns> - [Obsolete("Change to For(pluginType)")] - GenericFamilyExpression ForRequestedType(Type pluginType); - - /// <summary> - /// This method is a shortcut for specifying the default constructor and - /// setter arguments for a ConcreteType. ForConcreteType is shorthand for: - /// ForRequestedType[T]().TheDefault.Is.OfConcreteType[T].************** - /// when the PluginType and ConcreteType are the same Type - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - Registry.BuildWithExpression<T> ForConcreteType<T>(); - - /// <summary> - /// Expression Builder used to define policies for a PluginType including - /// Scoping, the Default Instance, and interception. BuildInstancesOf() - /// and ForRequestedType() are synonyms - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <returns></returns> - [Obsolete("Change to For<T>()")] - CreatePluginFamilyExpression<PLUGINTYPE> ForRequestedType<PLUGINTYPE>(); - - /// <summary> - /// Convenience method. Equivalent of ForRequestedType[PluginType]().AsSingletons() - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <returns></returns> - CreatePluginFamilyExpression<PLUGINTYPE> ForSingletonOf<PLUGINTYPE>(); - - /// <summary> - /// Uses the configuration expressions of this Registry to create a PluginGraph - /// object that could be used to initialize a Container. This method is - /// mostly for internal usage, but might be helpful for diagnostics - /// </summary> - /// <returns></returns> - PluginGraph Build(); - - /// <summary> - /// Adds an additional, non-Default Instance to the PluginType T. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - [Obsolete("Prefer For<T>().Add() instead")] - IsExpression<T> InstanceOf<T>(); - - /// <summary> - /// Adds an additional, non-Default Instance to the designated pluginType - /// This method is mostly meant for open generic types - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - [Obsolete("Prefer For(type).Add() instead")] - GenericIsExpression InstanceOf(Type pluginType); - - /// <summary> - /// Expression Builder to define the defaults for a named Profile. Each call - /// to CreateProfile is additive. - /// </summary> - /// <param name="profileName"></param> - /// <returns></returns> - ProfileExpression CreateProfile(string profileName); - - /// <summary> - /// An alternative way to use CreateProfile that uses ProfileExpression - /// as a Nested Closure. This usage will result in cleaner code for - /// multiple declarations - /// </summary> - /// <param name="profileName"></param> - /// <param name="action"></param> - void CreateProfile(string profileName, Action<ProfileExpression> action); - - /// <summary> - /// Registers a new TypeInterceptor object with the Container - /// </summary> - /// <param name="interceptor"></param> - void RegisterInterceptor(TypeInterceptor interceptor); - - /// <summary> - /// Allows you to define a TypeInterceptor inline with Lambdas or anonymous delegates - /// </summary> - /// <param name="match"></param> - /// <returns></returns> - /// <example> - /// IfTypeMatches( ... ).InterceptWith( o => new ObjectWrapper(o) ); - /// </example> - MatchedTypeInterceptor IfTypeMatches(Predicate<Type> match); - - /// <summary> - /// Designates a policy for scanning assemblies to auto - /// register types - /// </summary> - /// <returns></returns> - void Scan(Action<IAssemblyScanner> action); - - /// <summary> - /// Directs StructureMap to always inject dependencies into any and all public Setter properties - /// of the type PLUGINTYPE. - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <returns></returns> - CreatePluginFamilyExpression<PLUGINTYPE> FillAllPropertiesOfType<PLUGINTYPE>(); - - /// <summary> - /// Creates automatic "policies" for which public setters are considered mandatory - /// properties by StructureMap that will be "setter injected" as part of the - /// construction process. - /// </summary> - /// <param name="action"></param> - void SetAllProperties(Action<SetterConvention> action); - - /// <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> - void SelectConstructor<T>(Expression<Func<T>> expression); - - /// <summary> - /// All requests For the "TO" types will be filled by fetching the "FROM" - /// type and casting it to "TO" - /// GetInstance(typeof(TO)) basically becomes (TO)GetInstance(typeof(FROM)) - /// </summary> - /// <typeparam name="FROM"></typeparam> - /// <typeparam name="TO"></typeparam> - void Forward<FROM, TO>() where FROM : class where TO : class; - - /// <summary> - /// Syntactic Sugar for saying ForRequestedType().TheDefault.IsThis( @object ) - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <param name="object"></param> - void Register<PLUGINTYPE>(PLUGINTYPE @object); - - /// <summary> - /// Syntactic Sugar for saying ForRequestedType().TheDefault.IsThis( instance ) - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <param name="instance"></param> - void Register<PLUGINTYPE>(Instance instance); - - /// <summary> - /// Shorthand for ForRequestedType<PLUGINTYPE>() - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <returns></returns> - CreatePluginFamilyExpression<PLUGINTYPE> For<PLUGINTYPE>(); - - /// <summary> - /// Shorthand for ForRequestedType(pluginType) - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - GenericFamilyExpression For(Type pluginType); - - /// <summary> - /// Shortcut to make StructureMap return the default object of U casted to T - /// whenever T is requested. I.e.: - /// For<T>().TheDefault.Is.ConstructedBy(c => c.GetInstance<U>() as T); - /// </summary> - /// <typeparam name="T"></typeparam> - /// <typeparam name="U"></typeparam> - /// <returns></returns> - LambdaInstance<T> Redirect<T, U>() where T : class where U : class; - - /// <summary> - /// Advanced Usage Only! Skips the Registry and goes right to the inner - /// Semantic Model of StructureMap. Use with care - /// </summary> - /// <param name="configure"></param> - void Configure(Action<PluginGraph> configure); - } - /// <summary> /// A Registry class provides methods and grammars for configuring a Container or ObjectFactory. /// Using a Registry subclass is the recommended way of configuring a StructureMap Container. @@ -253,7 +27,8 @@ private readonly List<Action> _basicActions = new List<Action>(); /// <summary> - /// Adds the concreteType as an Instance of the pluginType + /// Adds the concreteType as an Instance of the pluginType. Mostly useful + /// for conventions /// </summary> /// <param name="pluginType"></param> /// <param name="concreteType"></param> @@ -263,7 +38,8 @@ } /// <summary> - /// Adds the concreteType as an Instance of the pluginType with a name + /// Adds the concreteType as an Instance of the pluginType with a name. Mostly + /// useful for conventions /// </summary> /// <param name="pluginType"></param> /// <param name="concreteType"></param> @@ -274,8 +50,8 @@ } /// <summary> - /// Add the pluggedType as an instance to any configured pluginType where pluggedType - /// could be assigned to the pluginType + /// Add the pluggedType as an instance to any configured pluginType where pluggedType. + /// Mostly useful for conventions /// </summary> /// <param name="pluggedType"></param> public void AddType(Type pluggedType) @@ -330,7 +106,7 @@ /// <summary> /// This method is a shortcut for specifying the default constructor and /// setter arguments for a ConcreteType. ForConcreteType is shorthand for: - /// ForRequestedType[T]().TheDefault.Is.OfConcreteType[T].************** + /// For[T]().Use[T].************** /// when the PluginType and ConcreteType are the same Type /// </summary> /// <typeparam name="T"></typeparam> @@ -355,7 +131,7 @@ } /// <summary> - /// Convenience method. Equivalent of ForRequestedType[PluginType]().AsSingletons() + /// Convenience method. Equivalent of ForRequestedType[PluginType]().Singletons() /// </summary> /// <typeparam name="PLUGINTYPE"></typeparam> /// <returns></returns> @@ -414,7 +190,8 @@ /// </summary> /// <param name="profileName"></param> /// <returns></returns> - public ProfileExpression CreateProfile(string profileName) + [Obsolete("Change to Profile( [name], Action<ProfileExpression> )")] + public ProfileExpression Profile(string profileName) { var expression = new ProfileExpression(profileName, this); @@ -428,7 +205,7 @@ /// </summary> /// <param name="profileName"></param> /// <param name="action"></param> - public void CreateProfile(string profileName, Action<ProfileExpression> action) + public void Profile(string profileName, Action<ProfileExpression> action) { var expression = new ProfileExpression(profileName, this); action(expression); @@ -525,6 +302,7 @@ /// </summary> /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="object"></param> + [Obsolete("Prefer For<T>().Use(value)")] public void Register<PLUGINTYPE>(PLUGINTYPE @object) { ForRequestedType<PLUGINTYPE>().TheDefault.IsThis(@object); @@ -535,13 +313,16 @@ /// </summary> /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="instance"></param> + [Obsolete("Prefer For<T>().Use(instance)")] public void Register<PLUGINTYPE>(Instance instance) { ForRequestedType<PLUGINTYPE>().TheDefault.IsThis(instance); } /// <summary> - /// Shorthand for ForRequestedType<PLUGINTYPE>() + /// Expression Builder used to define policies for a PluginType including + /// Scoping, the Default Instance, and interception. BuildInstancesOf() + /// and ForRequestedType() are synonyms /// </summary> /// <typeparam name="PLUGINTYPE"></typeparam> /// <returns></returns> @@ -551,9 +332,10 @@ } /// <summary> - /// Shorthand for ForRequestedType(pluginType) + /// Expression Builder used to define policies for a PluginType including + /// Scoping, the Default Instance, and interception. This method is specifically + /// meant for registering open generic types /// </summary> - /// <param name="pluginType"></param> /// <returns></returns> public GenericFamilyExpression For(Type pluginType) { Modified: trunk/Source/StructureMap/InitializationExpression.cs =================================================================== --- trunk/Source/StructureMap/InitializationExpression.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap/InitializationExpression.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -119,7 +119,7 @@ /// </summary> /// <param name="profileName"></param> /// <returns></returns> - ProfileExpression CreateProfile(string profileName); + ProfileExpression Profile(string profileName); /// <summary> /// An alternative way to use CreateProfile that uses ProfileExpression @@ -128,7 +128,7 @@ /// </summary> /// <param name="profileName"></param> /// <param name="action"></param> - void CreateProfile(string profileName, Action<ProfileExpression> action); + void Profile(string profileName, Action<ProfileExpression> action); /// <summary> /// Registers a new TypeInterceptor object with the Container Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap/ObjectFactory.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -400,8 +400,6 @@ } } - - #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -190,12 +190,19 @@ /// </summary> /// <param name="instanceKey"></param> /// <returns></returns> + [Obsolete("Change to Named")] public T WithName(string instanceKey) { Name = instanceKey; return thisInstance; } + public T Named(string instanceKey) + { + Name = instanceKey; + return thisInstance; + } + /// <summary> /// Register an Action to perform on the object created by this Instance /// before it is returned to the caller Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap/StructureMap.csproj 2009-12-29 02:55:12 UTC (rev 314) @@ -337,6 +337,7 @@ <Compile Include="ConfigurationExpression.cs" /> <Compile Include="Configuration\DictionaryReader.cs" /> <Compile Include="Configuration\DSL\Expressions\InstanceExpression.cs" /> + <Compile Include="Configuration\DSL\IRegistry.cs" /> <Compile Include="Configuration\DSL\SetterConvention.cs" /> <Compile Include="Configuration\ITypeReader.cs" /> <Compile Include="Configuration\PrimitiveArrayReader.cs" /> Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -24,14 +24,23 @@ { string theProfileName = "something"; - IContainer manager = new Container(registry => registry.CreateProfile(theProfileName) - .For<IWidget>().Use(delegate { return new AWidget(); }) - .For<Rule>().Use(delegate { return new DefaultRule(); })); + IContainer container = new Container(r => + { + r.Profile(theProfileName, x => + { + x.For<IWidget>().Use(() => new AWidget()); + x.For<Rule>().Use(() => new DefaultRule()); + }); - manager.SetDefaultsToProfile(theProfileName); - Assert.IsInstanceOfType(typeof (AWidget), manager.GetInstance<IWidget>()); - Assert.IsInstanceOfType(typeof (DefaultRule), manager.GetInstance<Rule>()); + + + }); + + container.SetDefaultsToProfile(theProfileName); + + Assert.IsInstanceOfType(typeof (AWidget), container.GetInstance<IWidget>()); + Assert.IsInstanceOfType(typeof (DefaultRule), container.GetInstance<Rule>()); } @@ -42,7 +51,7 @@ IContainer container = new Container(registry => { - registry.CreateProfile(theProfileName, x => + registry.Profile(theProfileName, x => { x.Type<IWidget>().Is.ConstructedBy(() => new AWidget()); x.Type<Rule>().Is.ConstructedBy(() => new DefaultRule()); @@ -61,9 +70,15 @@ { string theProfileName = "something"; - IContainer manager = new Container(registry => registry.CreateProfile(theProfileName) - .For<IWidget>().UseConcreteType<AWidget>() - .For<Rule>().UseConcreteType<DefaultRule>()); + IContainer manager = new Container(registry => + { + registry.Profile(theProfileName, p => + { + p.For<IWidget>().UseConcreteType<AWidget>(); + p.For<Rule>().UseConcreteType<DefaultRule>(); + }); + + }); manager.SetDefaultsToProfile(theProfileName); Assert.IsInstanceOfType(typeof (AWidget), manager.GetInstance<IWidget>()); @@ -77,7 +92,7 @@ var theWidget = new AWidget(); string theProfileName = "something"; - registry.CreateProfile(theProfileName) + registry.Profile(theProfileName) .For<IWidget>().Use(theWidget); PluginGraph graph = registry.Build(); @@ -93,7 +108,7 @@ string theDefaultName = "TheDefaultName"; var registry = new Registry(); - registry.CreateProfile(theProfileName) + registry.Profile(theProfileName) .For<IWidget>().UseNamedInstance(theDefaultName) .For<Rule>().UseNamedInstance("DefaultRule"); @@ -110,7 +125,7 @@ string theProfileName = "TheProfile"; var registry = new Registry(); - registry.CreateProfile(theProfileName) + registry.Profile(theProfileName) .For<IWidget>().UseConcreteType<AWidget>(); PluginGraph graph = registry.Build(); @@ -118,7 +133,7 @@ ProfileManager profileManager = graph.ProfileManager; Instance defaultInstance = profileManager.GetDefault(typeof (IWidget), theProfileName); - Assert.AreEqual(Profile.InstanceKeyForProfile(theProfileName), defaultInstance.Name); + Assert.AreEqual(StructureMap.Pipeline.Profile.InstanceKeyForProfile(theProfileName), defaultInstance.Name); var manager = new Container(graph); manager.SetDefaultsToProfile(theProfileName); Modified: trunk/Source/StructureMap.Testing/Examples.cs =================================================================== --- trunk/Source/StructureMap.Testing/Examples.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap.Testing/Examples.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -430,7 +430,7 @@ // Use the InstanceExpression to define the default Instance // of a PluginType within a Profile - CreateProfile("Connected", x => { x.Type<IService>().Is.OfConcreteType<RemoteService>(); }); + Profile("Connected", x => { x.Type<IService>().Is.OfConcreteType<RemoteService>(); }); } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -161,8 +161,8 @@ { var container = new Container(registry => { - registry.CreateProfile("1").For(typeof (IService<>)).UseConcreteType(typeof (Service<>)); - registry.CreateProfile("2").For(typeof (IService<>)).UseConcreteType(typeof (Service2<>)); + registry.Profile("1").For(typeof (IService<>)).UseConcreteType(typeof (Service<>)); + registry.Profile("2").For(typeof (IService<>)).UseConcreteType(typeof (Service2<>)); }); container.SetDefaultsToProfile("1"); @@ -182,8 +182,8 @@ r.InstanceOf(typeof (IService<>)).Is(typeof (Service<>)).WithName("Service1"); r.InstanceOf(typeof (IService<>)).Is(typeof (Service2<>)).WithName("Service2"); - r.CreateProfile("1").For(typeof (IService<>)).UseNamedInstance("Service1"); - r.CreateProfile("2").For(typeof (IService<>)).UseNamedInstance("Service2"); + r.Profile("1").For(typeof (IService<>)).UseNamedInstance("Service1"); + r.Profile("2").For(typeof (IService<>)).UseNamedInstance("Service2"); }); manager.SetDefaultsToProfile("1"); Modified: trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -89,8 +89,8 @@ x.OfConcreteType<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green"); }); - r.CreateProfile("Red").For<IService>().UseNamedInstance("Red"); - r.CreateProfile("Blue").For<IService>().UseNamedInstance("Blue"); + r.Profile("Red").For<IService>().UseNamedInstance("Red"); + r.Profile("Blue").For<IService>().UseNamedInstance("Blue"); }); assertColorIs(container, "Orange"); Deleted: trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs 2009-12-28 05:21:25 UTC (rev 313) +++ trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs 2009-12-29 02:55:12 UTC (rev 314) @@ -1,419 +0,0 @@ -using System.Collections.Generic; -using NUnit.Framework; -using StructureMap.Pipeline; -using StructureMap.Testing.Pipeline; - -namespace StructureMap.Testing.Graph -{ - [TestFixture] - public class ExplicitArgumentTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - ObjectFactory.Initialize(x => { x.UseDefaultStructureMapConfigFile = false; }); - } - - #endregion - - public interface IExplicitTarget - { - } - - public class RedTarget : IExplicitTarget - { - } - - public class GreenTarget : IExplicitTarget - { - } - - public class ExplicitTarget : IExplicitTarget - { - private readonly string _name; - private readonly IProvider _provider; - - public ExplicitTarget(string name, IProvider provider) - { - _name = name; - _provider = provider; - } - - - public string Name - { - get { return _name; } - } - - public IProvider Provider - { - get { return _provider; } - } - } - - public interface IProvider - { - } - - public class RedProvider : IProvider - { - } - - public class BlueProvider : IProvider - { - } - - [Test] - public void Example() - { - IContainer container = new Container(); - var theTrade = new Trade(); - - var view = container.With(theTrade).GetInstance<TradeView>(); - - view.Trade.ShouldBeTheSameAs(theTrade); - } - - [Test] - public void Explicit_services_are_used_throughout_the_object_graph() - { - var theTrade = new Trade(); - - IContainer container = new Container(r => - { - r.ForRequestedType<IView>().TheDefaultIsConcreteType<TradeView>(); - r.ForRequestedType<Node>().TheDefaultIsConcreteType<TradeNode>(); - }); - - var command = container.With(theTrade).GetInstance<Command>(); - - command.Trade.ShouldBeTheSameAs(theTrade); - command.Node.IsType<TradeNode>().Trade.ShouldBeTheSameAs(theTrade); - command.View.IsType<TradeView>().Trade.ShouldBeTheSameAs(theTrade); - } - - [Test] - public void ExplicitArguments_can_return_child_by_name() - { - var args = new ExplicitArguments(); - var theNode = new Node(); - args.SetArg("node", theNode); - - IConfiguredInstance instance = new ExplicitInstance(typeof (Command), args, null); - - Assert.AreSame(theNode, instance.GetChild("node", typeof (Node), new StubBuildSession())); - } - - [Test] - public void Fill_in_argument_by_name() - { - var container = new Container(x => - { - x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); - }); - - var theNode = new Node(); - var theTrade = new Trade(); - - var command = container - .With("node").EqualTo(theNode) - .With(theTrade) - .GetInstance<Command>(); - - Assert.IsInstanceOfType(typeof (View), command.View); - Assert.AreSame(theNode, command.Node); - Assert.AreSame(theTrade, command.Trade); - } - - [Test] - public void NowDoItWithObjectFactoryItself() - { - ObjectFactory.Initialize(x => - { - x.ForConcreteType<ExplicitTarget>().Configure - .CtorDependency<IProvider>().Is<RedProvider>() - .WithCtorArg("name").EqualTo("Jeremy"); - }); - - // Get the ExplicitTarget without setting an explicit arg for IProvider - var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); - Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); - - // Now, set the explicit arg for IProvider - var theBlueProvider = new BlueProvider(); - var secondTarget = ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>(); - Assert.AreSame(theBlueProvider, secondTarget.Provider); - } - - [Test] - public void NowDoItWithObjectFactoryItself_with_new_API() - { - ObjectFactory.Initialize(x => - { - x.ForRequestedType<ExplicitTarget>().TheDefault.Is.OfConcreteType<ExplicitTarget>() - .CtorDependency<IProvider>().Is(child => child.OfConcreteType<RedProvider>()) - .WithCtorArg("name").EqualTo("Jeremy"); - }); - - // Get the ExplicitTarget without setting an explicit arg for IProvider - ObjectFactory.GetInstance<ExplicitTarget>().Provider.IsType<RedProvider>(); - - // Now, set the explicit arg for IProvider - var theBlueProvider = new BlueProvider(); - ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>() - .Provider.ShouldBeTheSameAs(theBlueProvider); - } - - [Test] - public void OverrideAPrimitiveWithObjectFactory() - { - ObjectFactory.Initialize(x => - { - x.ForConcreteType<ExplicitTarget>().Configure - .CtorDependency<IProvider>().Is<RedProvider>() - .WithCtorArg("name").EqualTo("Jeremy"); - }); - - // Get the ExplicitTarget without setting an explicit arg for IProvider - var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); - Assert.AreEqual("Jeremy", firstTarget.Name); - - // Now, set the explicit arg for IProvider - var secondTarget = ObjectFactory.With("name").EqualTo("Julia").GetInstance<ExplicitTarget>(); - Assert.AreEqual("Julia", secondTarget.Name); - } - - [Test] - public void pass_explicit_service_into_all_instances() - { - // The Container is constructed with 2 instances - // of TradeView - var container = new Container(r => - { - r.ForRequestedType<TradeView>() - .TheDefaultIsConcreteType<TradeView>() - .AddConcreteType<SecuredTradeView>(); - }); - - var theTrade = new Trade(); - - IList<TradeView> views = container.With(theTrade).GetAllInstances<TradeView>(); - - views[0].Trade.ShouldBeTheSameAs(theTrade); - views[1].Trade.ShouldBeTheSameAs(theTrade); - } - - [Test] - public void Pass_in_arguments_as_dictionary() - { - var container = new Container(x => - { - x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); - }); - - var theNode = new Node(); - var theTrade = new Trade(); - - var args = new ExplicitArguments(); - args.Set(theNode); - args.SetArg("trade", theTrade); - - var command = container.GetInstance<Command>(args); - - Assert.IsInstanceOfType(typeof (View), command.View); - Assert... [truncated message content] |