本文整理汇总了C#中Spring.Objects.Factory.Support.RootObjectDefinition类的典型用法代码示例。如果您正苦于以下问题:C# RootObjectDefinition类的具体用法?C# RootObjectDefinition怎么用?C# RootObjectDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RootObjectDefinition类属于Spring.Objects.Factory.Support命名空间,在下文中一共展示了RootObjectDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitFactory
private void InitFactory(DefaultListableObjectFactory factory)
{
Console.WriteLine("init factory");
RootObjectDefinition tee = new RootObjectDefinition(typeof(Tee), true);
tee.IsLazyInit = true;
ConstructorArgumentValues teeValues = new ConstructorArgumentValues();
teeValues.AddGenericArgumentValue("test");
tee.ConstructorArgumentValues = teeValues;
RootObjectDefinition bar = new RootObjectDefinition(typeof(BBar), false);
ConstructorArgumentValues barValues = new ConstructorArgumentValues();
barValues.AddGenericArgumentValue(new RuntimeObjectReference("tee"));
barValues.AddGenericArgumentValue(5);
bar.ConstructorArgumentValues = barValues;
RootObjectDefinition foo = new RootObjectDefinition(typeof(FFoo), false);
MutablePropertyValues fooValues = new MutablePropertyValues();
fooValues.Add("i", 5);
fooValues.Add("bar", new RuntimeObjectReference("bar"));
fooValues.Add("copy", new RuntimeObjectReference("bar"));
fooValues.Add("s", "test");
foo.PropertyValues = fooValues;
factory.RegisterObjectDefinition("foo", foo);
factory.RegisterObjectDefinition("bar", bar);
factory.RegisterObjectDefinition("tee", tee);
}
示例2: ClearWithDynamicProxies
public void ClearWithDynamicProxies()
{
CompositionProxyTypeBuilder typeBuilder = new CompositionProxyTypeBuilder();
typeBuilder.TargetType = typeof(TestObject);
Type proxyType = typeBuilder.BuildProxyType();
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
RootObjectDefinition od1 = new RootObjectDefinition(proxyType, false);
od1.PropertyValues.Add("Name", "Bruno");
of.RegisterObjectDefinition("testObject", od1);
GenericApplicationContext ctx1 = new GenericApplicationContext(of);
ContextRegistry.RegisterContext(ctx1);
ITestObject to1 = ContextRegistry.GetContext().GetObject("testObject") as ITestObject;
Assert.IsNotNull(to1);
Assert.AreEqual("Bruno", to1.Name);
DefaultListableObjectFactory of2 = new DefaultListableObjectFactory();
RootObjectDefinition od2 = new RootObjectDefinition(proxyType, false);
od2.PropertyValues.Add("Name", "Baia");
of2.RegisterObjectDefinition("testObject", od2);
GenericApplicationContext ctx2 = new GenericApplicationContext(of2);
ContextRegistry.Clear();
ITestObject to2 = ctx2.GetObject("testObject") as ITestObject;
Assert.IsNotNull(to2);
Assert.AreEqual("Baia", to2.Name);
}
示例3: ParseInternal
protected override AbstractObjectDefinition ParseInternal(XmlElement element, ParserContext parserContext)
{
ObjectDefinitionBuilder builder = BuildObjectDefinition(element, parserContext);
ManagedList interceptors = null;
XmlElement interceptorsElement = DomUtils.GetChildElementByTagName(element, "interceptors");
if(interceptorsElement != null) {
ChannelInterceptorParser interceptorParser = new ChannelInterceptorParser();
interceptors = interceptorParser.ParseInterceptors(interceptorsElement, new ParserContext(parserContext.ParserHelper, builder.RawObjectDefinition));
}
if(interceptors == null) {
interceptors = new ManagedList();
}
string datatypeAttr = element.GetAttribute("datatype");
if(StringUtils.HasText(datatypeAttr)) {
string[] datatypes = StringUtils.CommaDelimitedListToStringArray(datatypeAttr);
RootObjectDefinition selectorDef = new RootObjectDefinition();
selectorDef.ObjectTypeName = IntegrationNamespaceUtils.SELECTOR_PACKAGE + ".PayloadTypeSelector";
selectorDef.ConstructorArgumentValues.AddGenericArgumentValue(datatypes);
string selectorObjectName = parserContext.ReaderContext.RegisterWithGeneratedName(selectorDef);
RootObjectDefinition interceptorDef = new RootObjectDefinition();
interceptorDef.ObjectTypeName = IntegrationNamespaceUtils.CHANNEL_INTERCEPTOR_PACKAGE + ".MessageSelectingInterceptor";
interceptorDef.ConstructorArgumentValues.AddGenericArgumentValue(new RuntimeObjectReference(selectorObjectName));
string interceptorObjectName = parserContext.ReaderContext.RegisterWithGeneratedName(interceptorDef);
interceptors.Add(new RuntimeObjectReference(interceptorObjectName));
}
builder.AddPropertyValue("interceptors", interceptors);
return builder.ObjectDefinition;
}
示例4: CanProxyFactoryMethodProducts
public void CanProxyFactoryMethodProducts()
{
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.ObjectFactory.AddObjectPostProcessor(new DefaultAdvisorAutoProxyCreator());
CapturingAdvice capturingAdvice = new CapturingAdvice();
ctx.ObjectFactory.RegisterSingleton("logging", new DefaultPointcutAdvisor(TruePointcut.True, capturingAdvice));
// register "factory" object
RootObjectDefinition rod;
rod = new RootObjectDefinition(typeof(TestObjectFactoryObject));
ctx.ObjectFactory.RegisterObjectDefinition("test", rod);
// register product, referencing the factory object
rod = new RootObjectDefinition(typeof(ITestObject));
rod.FactoryObjectName = "test";
rod.FactoryMethodName = "CreateTestObject";
ctx.ObjectFactory.RegisterObjectDefinition("testProduct", rod);
ctx.Refresh();
ITestObjectFactoryObject fo = (ITestObjectFactoryObject) ctx.GetObject("test");
Assert.IsTrue( AopUtils.IsAopProxy(fo) );
Assert.AreEqual("CreateTestObject", ((IMethodInvocation)capturingAdvice.CapturedCalls[0]).Method.Name);
capturingAdvice.CapturedCalls.Clear();
ITestObject to = (ITestObject)ctx.GetObject("testProduct");
Assert.IsTrue( AopUtils.IsAopProxy(to) );
Assert.AreEqual("TheName", to.Name);
Assert.AreEqual("get_Name", ((IMethodInvocation)capturingAdvice.CapturedCalls[0]).Method.Name);
}
示例5: ChokesOnCircularReferenceToPlaceHolder
public void ChokesOnCircularReferenceToPlaceHolder()
{
RootObjectDefinition def = new RootObjectDefinition();
def.ObjectType = typeof (TestObject);
ConstructorArgumentValues args = new ConstructorArgumentValues();
args.AddNamedArgumentValue("name", "${foo}");
def.ConstructorArgumentValues = args;
NameValueCollection properties = new NameValueCollection();
const string expectedName = "ba${foo}r";
properties.Add("foo", expectedName);
IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof (IConfigurableListableObjectFactory));
Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] {"foo"});
Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def);
mocks.ReplayAll();
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
cfg.Properties = properties;
try
{
cfg.PostProcessObjectFactory(mock);
Assert.Fail("Should have raised an ObjectDefinitionStoreException by this point.");
}
catch (ObjectDefinitionStoreException)
{
}
mocks.VerifyAll();
}
示例6: Setup
public void Setup()
{
_applicationContext = new GenericApplicationContext();
var objDef = new RootObjectDefinition(typeof (InitDestroyAttributeObjectPostProcessor));
objDef.Role = ObjectRole.ROLE_INFRASTRUCTURE;
_applicationContext.ObjectFactory.RegisterObjectDefinition("InitDestroyAttributeObjectPostProcessor", objDef);
objDef = new RootObjectDefinition(typeof(PostContructTestObject1));
_applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject1", objDef);
objDef = new RootObjectDefinition(typeof(PostContructTestObject2));
_applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject2", objDef);
objDef = new RootObjectDefinition(typeof(PostContructTestObject3));
_applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject3", objDef);
objDef = new RootObjectDefinition(typeof(PostContructTestObject4));
objDef.Scope = "prototype";
_applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject4", objDef);
objDef = new RootObjectDefinition(typeof(PostContructTestObject5));
_applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject5", objDef);
objDef = new RootObjectDefinition(typeof(PostContructTestObject1));
objDef.InitMethodName = "Init1";
_applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject6", objDef);
_applicationContext.Refresh();
}
示例7: InstantiationWithClassName
public void InstantiationWithClassName()
{
RootObjectDefinition def
= new RootObjectDefinition( typeof( TestObject ).AssemblyQualifiedName, new ConstructorArgumentValues(), new MutablePropertyValues() );
Assert.IsFalse( def.HasObjectType );
Assert.IsNull( def.ObjectType ); // must bail...
}
示例8: createTypeSetPropertiesAndInvokeMethod
public static object createTypeSetPropertiesAndInvokeMethod(Type tTargetType, String sMethodToInvoke,
Dictionary<String, Object> dProperties)
{
string sFactoryObject = "FactoryObject";
string sInvokeResult = "InvokeResult";
var ctx = new GenericApplicationContext();
// create factory Object, add (if required) its properties to it and register it
var rodFactoryObject = new RootObjectDefinition {ObjectType = tTargetType};
if (dProperties != null)
foreach (String sProperty in dProperties.Keys)
rodFactoryObject.PropertyValues.Add(sProperty, dProperties[sProperty]);
ctx.RegisterObjectDefinition(sFactoryObject, rodFactoryObject);
// create object to invoke method and register it
var rodMethodToInvoke = new RootObjectDefinition
{
FactoryMethodName = sMethodToInvoke,
FactoryObjectName = sFactoryObject
};
ctx.RegisterObjectDefinition(sInvokeResult, rodMethodToInvoke);
// when we get the rodMethodToInvoke object, the rodFactoryObject will be created
return ctx.GetObject(sInvokeResult);
}
示例9: ParseInternal
/// <summary>
/// Central template method to actually parse the supplied XmlElement
/// into one or more IObjectDefinitions.
/// </summary>
/// <param name="element">The element that is to be parsed into one or more <see cref="IObjectDefinition"/>s</param>
/// <param name="parserContext">The the object encapsulating the current state of the parsing process;
/// provides access to a <see cref="IObjectDefinitionRegistry"/></param>
/// <returns>
/// The primary IObjectDefinition resulting from the parsing of the supplied XmlElement
/// </returns>
protected override AbstractObjectDefinition ParseInternal(XmlElement element, ParserContext parserContext)
{
ConfigureAutoProxyCreator(parserContext, element);
//Create the TransactionAttributeSource
RootObjectDefinition sourceDef = new RootObjectDefinition(typeof(AttributesTransactionAttributeSource));
sourceDef.Role = ObjectRole.ROLE_INFRASTRUCTURE;
string sourceName = parserContext.ReaderContext.RegisterWithGeneratedName(sourceDef);
//Create the TransactionInterceptor definition.
RootObjectDefinition interceptorDefinition = new RootObjectDefinition(typeof(TransactionInterceptor));
interceptorDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
RegisterTransactionManager(element, interceptorDefinition);
interceptorDefinition.PropertyValues.Add(TxNamespaceUtils.TRANSACTION_ATTRIBUTE_SOURCE, new RuntimeObjectReference(sourceName));
String interceptorName = parserContext.ReaderContext.RegisterWithGeneratedName(interceptorDefinition);
// Create the TransactionAttributeSourceAdvisor definition.
RootObjectDefinition advisorDef = new RootObjectDefinition(typeof(ObjectFactoryTransactionAttributeSourceAdvisor));
advisorDef.Role = ObjectRole.ROLE_INFRASTRUCTURE;
advisorDef.PropertyValues.Add("transactionAttributeSource", new RuntimeObjectReference(sourceName));
advisorDef.PropertyValues.Add("adviceObjectName", interceptorName);
if (element.HasAttribute(ORDER))
{
advisorDef.PropertyValues.Add(ORDER, GetAttributeValue(element, ORDER));
}
return advisorDef;
}
示例10: RegisterAttributeConfigProcessors
/// <summary>
/// Registers the attribute config processors.
/// </summary>
/// <param name="registry">The registry.</param>
public static void RegisterAttributeConfigProcessors(IObjectDefinitionRegistry registry)
{
if (!registry.ContainsObjectDefinition(CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
{
RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(ConfigurationClassPostProcessor));
RegisterPostProcessor(registry, objectDefinition, CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
}
if (!registry.ContainsObjectDefinition(AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
{
RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(AutowiredAttributeObjectPostProcessor));
RegisterPostProcessor(registry, objectDefinition, AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
}
if (!registry.ContainsObjectDefinition(REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
{
RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(RequiredAttributeObjectPostProcessor));
RegisterPostProcessor(registry, objectDefinition, REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
}
if (!registry.ContainsObjectDefinition(INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
{
RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(InitDestroyAttributeObjectPostProcessor));
RegisterPostProcessor(registry, objectDefinition, INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
}
}
示例11: Find
private static NamedObjectDefinition Find( string url, string objectName )
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
RootObjectDefinition rod = new RootObjectDefinition( typeof( Type1 ) );
of.RegisterObjectDefinition( objectName, rod );
return FindWebObjectDefinition( url, of );
}
示例12: VisitPropertyValues
public void VisitPropertyValues()
{
IObjectDefinition od = new RootObjectDefinition();
od.PropertyValues.Add("PropertyName", "$Property");
ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));
odv.VisitObjectDefinition(od);
Assert.AreEqual("Value", od.PropertyValues.GetPropertyValue("PropertyName").Value);
}
示例13: VisitObjectTypeName
public void VisitObjectTypeName()
{
IObjectDefinition od = new RootObjectDefinition();
od.ObjectTypeName = "$Property";
ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));
odv.VisitObjectDefinition(od);
Assert.AreEqual("Value", od.ObjectTypeName);
}
示例14: RegisterAutoProxyCreatorIfNecessary
/// <summary>
/// Registers the internal auto proxy creator if necessary.
/// </summary>
public static void RegisterAutoProxyCreatorIfNecessary(IObjectDefinitionRegistry registry)
{
AssertUtils.ArgumentNotNull(registry, "registry");
if (!registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
{
RootObjectDefinition objectDefinition = new RootObjectDefinition(InfrastructureAutoProxyCreatorType);
objectDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
objectDefinition.PropertyValues.Add("order", int.MaxValue);
registry.RegisterObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME, objectDefinition);
}
}
示例15: RegisterAttributeConfigProcessors
/// <summary>
/// Registers the attribute config processors.
/// </summary>
/// <param name="registry">The registry.</param>
public static void RegisterAttributeConfigProcessors(IObjectDefinitionRegistry registry)
{
if (!registry.ContainsObjectDefinition(CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
{
RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(ConfigurationClassPostProcessor));
RegisterPostProcessor(registry, objectDefinition, CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
}
//AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME
//REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME
}