public CreateObjectDefinition ( string typeName, string parent, |
||
typeName | string | The |
parent | string | The name of the parent object definition (if any). |
domain | The |
|
return |
public void DoesNotResolveTypeNameToFullTypeInstanceIfAppDomainIsNull() { DefaultObjectDefinitionFactory factory = new DefaultObjectDefinitionFactory(); IConfigurableObjectDefinition definition = factory.CreateObjectDefinition( typeof (TestObject).FullName, null, null); Assert.IsNotNull(definition, "CreateObjectDefinition with no parent is returning null (it must never do so)."); Assert.AreEqual(typeof (TestObject).FullName, definition.ObjectTypeName); Assert.AreEqual(0, definition.PropertyValues.PropertyValues.Count, "Must not have any property values as none were passed in."); Assert.AreEqual(0, definition.ConstructorArgumentValues.ArgumentCount, "Must not have any ctor args as none were passed in."); }
public void CreateChildDefinition() { DefaultObjectDefinitionFactory factory = new DefaultObjectDefinitionFactory(); IConfigurableObjectDefinition definition = factory.CreateObjectDefinition( typeof (TestObject).FullName, "Aimee Mann", AppDomain.CurrentDomain); Assert.IsNotNull(definition, "CreateObjectDefinition with no parent is returning null (it must never do so)."); Assert.AreEqual(typeof (TestObject), definition.ObjectType); Assert.AreEqual(0, definition.PropertyValues.PropertyValues.Count, "Must not have any property values as none were passed in."); Assert.AreEqual(0, definition.ConstructorArgumentValues.ArgumentCount, "Must not have any ctor args as none were passed in."); }
public void CreateChildDefinition() { DefaultObjectDefinitionFactory factory = new DefaultObjectDefinitionFactory(); IConfigurableObjectDefinition definition = factory.CreateObjectDefinition( typeof(TestObject).FullName, "Aimee Mann", AppDomain.CurrentDomain); Assert.IsNotNull(definition, "CreateObjectDefinition with no parent is returning null (it must never do so)."); Assert.AreEqual(typeof(TestObject), definition.ObjectType); Assert.AreEqual(0, definition.PropertyValues.PropertyValues.Length, "Must not have any property values as none were passed in."); Assert.AreEqual(0, definition.ConstructorArgumentValues.ArgumentCount, "Must not have any ctor args as none were passed in."); }
public void DoesNotResolveTypeNameToFullTypeInstanceIfAppDomainIsNull() { DefaultObjectDefinitionFactory factory = new DefaultObjectDefinitionFactory(); IConfigurableObjectDefinition definition = factory.CreateObjectDefinition( typeof(TestObject).FullName, null, null); Assert.IsNotNull(definition, "CreateObjectDefinition with no parent is returning null (it must never do so)."); Assert.AreEqual(typeof(TestObject).FullName, definition.ObjectTypeName); Assert.AreEqual(0, definition.PropertyValues.PropertyValues.Length, "Must not have any property values as none were passed in."); Assert.AreEqual(0, definition.ConstructorArgumentValues.ArgumentCount, "Must not have any ctor args as none were passed in."); }
// process PerRequest, Singleton and AutowiredAttribute attributes public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { // register all singleton and per request attribute //(from type in assembly.GetTypes() // let attributes = type.GetCustomAttributes(typeof(SingletonAttribute), false) // where attributes != null && attributes.Length > 0 // select new { CreateType = type, Attribute = attributes.Cast<SingletonAttribute>().First() }) // .ToList() // .ForEach(x => // { // string name = x.CreateType.Name; // if (x.Attribute.Type != null) name = x.Attribute.Type.Name; // if (x.Attribute.Name != null) name = x.Attribute.Name; // object singletonObj = factory.Autowire(x.CreateType, AutoWiringMode.No, false); // factory.RegisterSingleton(name, singletonObj); // }); //// register all perrequest attribute //(from type in assembly.GetTypes() // let attributes = type.GetCustomAttributes(typeof(PerRequestAttribute), false) // where attributes != null && attributes.Length > 0 // select new { CreateType = type, Attribute = attributes.Cast<PerRequestAttribute>().First() }) // .ToList() // .ForEach(x => // { // var defaultFactory = new DefaultObjectDefinitionFactory(); // AbstractObjectDefinition def = defaultFactory.CreateObjectDefinition(x.CreateType.FullName + "," + x.CreateType.Assembly.GetName(), null, AppDomain.CurrentDomain); // string name = x.CreateType.Name; // if (x.Attribute.Type != null) name = x.Attribute.Type.Name; // if (x.Attribute.Name != null) name = x.Attribute.Name; // factory.RegisterObjectDefinition(name, def); // }); // register all perrequest and singleton attribute (from type in assembly.GetTypes() let attributes = type.GetCustomAttributes(false) from attribute in attributes where attributes != null && attributes.Length > 0 && (attribute is PerRequestAttribute || attribute is SingletonAttribute) select new { CreateType = type, Attribute = attribute }) .ToList() .ForEach(x => { dynamic objX = x; var defaultFactory = new DefaultObjectDefinitionFactory(); AbstractObjectDefinition def = defaultFactory.CreateObjectDefinition(x.CreateType.FullName + "," + x.CreateType.Assembly.GetName(), null, AppDomain.CurrentDomain); string name = objX.CreateType.Name; if (objX.Attribute.Type != null) name = objX.Attribute.Type.Name; if (objX.Attribute.Name != null) name = objX.Attribute.Name; if(objX.Attribute is SingletonAttribute) { def.IsSingleton = true; } ConstructorArgumentValues cav = def.ConstructorArgumentValues; object[] constructValues = objX.Attribute.ConstructorArgs; if(constructValues!=null && constructValues.Length>0) { for(int i=0;i<constructValues.Length;i++) { cav.AddIndexedArgumentValue(i,constructValues[i]); } } factory.RegisterObjectDefinition(name, def); }); } }