本文整理汇总了C#中Spring.Objects.Factory.Support.DefaultListableObjectFactory.RegisterObjectDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultListableObjectFactory.RegisterObjectDefinition方法的具体用法?C# DefaultListableObjectFactory.RegisterObjectDefinition怎么用?C# DefaultListableObjectFactory.RegisterObjectDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spring.Objects.Factory.Support.DefaultListableObjectFactory
的用法示例。
在下文中一共展示了DefaultListableObjectFactory.RegisterObjectDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoesNotAcceptInfrastructureAdvisorsDuringScanning
public void DoesNotAcceptInfrastructureAdvisorsDuringScanning()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
GenericObjectDefinition infrastructureAdvisorDefinition = new GenericObjectDefinition();
infrastructureAdvisorDefinition.ObjectType = typeof (TestAdvisor);
infrastructureAdvisorDefinition.PropertyValues.Add("Name", "InfrastructureAdvisor");
infrastructureAdvisorDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
of.RegisterObjectDefinition("infrastructure", infrastructureAdvisorDefinition);
GenericObjectDefinition regularAdvisorDefinition = new GenericObjectDefinition();
regularAdvisorDefinition.ObjectType = typeof (TestAdvisor);
regularAdvisorDefinition.PropertyValues.Add("Name", "RegularAdvisor");
// regularAdvisorDefinition.Role = ObjectRole.ROLE_APPLICATION;
of.RegisterObjectDefinition("regular", regularAdvisorDefinition);
TestAdvisorAutoProxyCreator apc = new TestAdvisorAutoProxyCreator();
apc.ObjectFactory = of;
object[] advisors = apc.GetAdvicesAndAdvisorsForObject(typeof (object), "dummyTarget");
Assert.AreEqual(1, advisors.Length);
Assert.AreEqual( "RegularAdvisor", ((TestAdvisor)advisors[0]).Name );
Assert.AreEqual(1, apc.CheckedAdvisors.Count);
Assert.AreEqual("regular", apc.CheckedAdvisors[0]);
}
示例2: SetUp
public void SetUp()
{
_singletonDefinition = new RootObjectDefinition(typeof (TestObject), AutoWiringMode.No);
_singletonDefinitionWithFactory = new RootObjectDefinition(_singletonDefinition);
_singletonDefinitionWithFactory.FactoryMethodName = "GetObject";
_singletonDefinitionWithFactory.FactoryObjectName = "TestObjectFactoryDefinition";
_testObjectFactory = new RootObjectDefinition(typeof (TestObjectFactory), AutoWiringMode.No);
DefaultListableObjectFactory myFactory = new DefaultListableObjectFactory();
myFactory.RegisterObjectDefinition("SingletonObjectDefinition", SingletonDefinition);
myFactory.RegisterObjectDefinition("SingletonDefinitionWithFactory", SingletonDefinitionWithFactory);
myFactory.RegisterObjectDefinition("TestObjectFactoryDefinition", TestObjectFactoryDefinition);
_factory = myFactory;
}
示例3: 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);
}
示例4: 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 );
}
示例5: SunnyDayReplaceMethod
public void SunnyDayReplaceMethod()
{
RootObjectDefinition replacerDef = new RootObjectDefinition(typeof (NewsFeedFactory));
RootObjectDefinition managerDef = new RootObjectDefinition(typeof (ReturnsNullNewsFeedManager));
managerDef.MethodOverrides.Add(new ReplacedMethodOverride("CreateNewsFeed", "replacer"));
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
factory.RegisterObjectDefinition("manager", managerDef);
factory.RegisterObjectDefinition("replacer", replacerDef);
INewsFeedManager manager = (INewsFeedManager) factory["manager"];
NewsFeed feed1 = manager.CreateNewsFeed();
Assert.IsNotNull(feed1, "The CreateNewsFeed() method is not being replaced.");
Assert.AreEqual(NewsFeedFactory.DefaultName, feed1.Name);
NewsFeed feed2 = manager.CreateNewsFeed();
// NewsFeedFactory always yields a new NewsFeed (see class definition below)...
Assert.IsFalse(ReferenceEquals(feed1, feed2));
}
示例6: _TestSetUp
public void _TestSetUp()
{
DefaultListableObjectFactory parentFactory = new DefaultListableObjectFactory();
_factory = new DefaultListableObjectFactory(parentFactory);
RootObjectDefinition rodA = new RootObjectDefinition(_expectedtype);
RootObjectDefinition rodB = new RootObjectDefinition(_expectedtype);
RootObjectDefinition rodC = new RootObjectDefinition(_expectedtype);
RootObjectDefinition rod2A = new RootObjectDefinition(_expectedtype);
RootObjectDefinition rod2C = new RootObjectDefinition(_expectedtype);
_factory.RegisterObjectDefinition("objA", rodA);
_factory.RegisterObjectDefinition("objB", rodB);
_factory.RegisterObjectDefinition("objC", rodC);
parentFactory.RegisterObjectDefinition("obj2A", rod2A);
parentFactory.RegisterObjectDefinition("objB", rodB);
parentFactory.RegisterObjectDefinition("obj2C", rod2C);
}
示例7: CanCreateHostTwice
public void CanCreateHostTwice()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
string svcRegisteredName = System.Guid.NewGuid().ToString();
of.RegisterObjectDefinition(svcRegisteredName, new RootObjectDefinition(new RootObjectDefinition(typeof(Service))));
SpringServiceHost ssh = new SpringServiceHost(svcRegisteredName, of, true);
SpringServiceHost ssh1 = new SpringServiceHost(svcRegisteredName, of, true);
}
示例8: AddPersistenceExceptionTranslation
protected override void AddPersistenceExceptionTranslation(ProxyFactory pf, IPersistenceExceptionTranslator pet)
{
if (AttributeUtils.FindAttribute(pf.TargetType, typeof(RepositoryAttribute)) != null)
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
of.RegisterObjectDefinition("peti", new RootObjectDefinition(typeof(PersistenceExceptionTranslationInterceptor)));
of.RegisterSingleton("pet", pet);
pf.AddAdvice((PersistenceExceptionTranslationInterceptor) of.GetObject("peti"));
}
}
示例9: ProxyObjectWithoutInterface
public void ProxyObjectWithoutInterface()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
of.RegisterObjectDefinition("bar", new RootObjectDefinition(typeof(ObjectWithoutInterface)));
TestAutoProxyCreator apc = new TestAutoProxyCreator(of);
of.AddObjectPostProcessor(apc);
ObjectWithoutInterface o = of.GetObject("bar") as ObjectWithoutInterface;
Assert.IsTrue(AopUtils.IsAopProxy(o));
o.Foo();
Assert.AreEqual(1, apc.NopInterceptor.Count);
}
示例10: ConvertsWriteConcernCorrectly
public void ConvertsWriteConcernCorrectly()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
factory.RegisterCustomConverter(typeof(WriteConcern), new WriteConcernTypeConverter());
RootObjectDefinition definition = new RootObjectDefinition(typeof(MongoFactoryObject));
definition.PropertyValues.Add("Url", "mongodb://localhost");
definition.PropertyValues.Add("WriteConcern", "Acknowledged");
factory.RegisterObjectDefinition("factory", definition);
MongoFactoryObject obj = factory.GetObject<MongoFactoryObject>("&factory");
Assert.That(ReflectionUtils.GetInstanceFieldValue(obj, "_writeConcern"),
Is.EqualTo(WriteConcern.Acknowledged));
}
示例11: ExportSingleCall
public void ExportSingleCall()
{
using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
{
of.RegisterObjectDefinition("simpleCounter", new RootObjectDefinition(typeof(SimpleCounter), false));
SaoExporter saoExporter = new SaoExporter();
saoExporter.ObjectFactory = of;
saoExporter.TargetName = "simpleCounter";
saoExporter.ServiceName = "RemotedSaoSingleCallCounter";
saoExporter.AfterPropertiesSet();
of.RegisterSingleton("simpleCounterExporter", saoExporter); // also tests SaoExporter.Dispose()!
AssertExportedService(saoExporter.ServiceName, 0);
}
}
示例12: ShouldAllowConfigurationClassInheritance
public void ShouldAllowConfigurationClassInheritance()
{
var factory = new DefaultListableObjectFactory();
factory.RegisterObjectDefinition("DerivedConfiguration", new GenericObjectDefinition
{
ObjectType = typeof(DerivedConfiguration)
});
var processor = new ConfigurationClassPostProcessor();
processor.PostProcessObjectFactory(factory);
// we should get singleton instances only
TestObject testObject = (TestObject) factory.GetObject("DerivedDefinition");
string singletonParent = (string) factory.GetObject("BaseDefinition");
Assert.That(testObject.Value, Is.SameAs(singletonParent));
}
开发者ID:spring-projects,项目名称:spring-net-codeconfig,代码行数:18,代码来源:ConfigurationClassPostProcessorTests.cs
示例13: GetTargetSource
/// <summary>
/// Create a special TargetSource for the given object, if any.
/// </summary>
/// <param name="objectType">the type of the object to create a TargetSource for</param>
/// <param name="name">the name of the object</param>
/// <param name="factory">the containing factory</param>
/// <returns>
/// a special TargetSource or null if this TargetSourceCreator isn't
/// interested in the particular object
/// </returns>
public ITargetSource GetTargetSource(Type objectType, string name, IObjectFactory factory)
{
AbstractPrototypeTargetSource prototypeTargetSource = CreatePrototypeTargetSource(objectType, name, factory);
if (prototypeTargetSource == null)
{
return null;
}
else
{
if (!(factory is IObjectDefinitionRegistry))
{
if (logger.IsWarnEnabled)
logger.Warn("Cannot do autopooling with a IObjectFactory that doesn't implement IObjectDefinitionRegistry");
return null;
}
IObjectDefinitionRegistry definitionRegistry = (IObjectDefinitionRegistry) factory;
RootObjectDefinition definition = (RootObjectDefinition) definitionRegistry.GetObjectDefinition(name);
if (logger.IsInfoEnabled)
logger.Info("Configuring AbstractPrototypeBasedTargetSource...");
// Infinite cycle will result if we don't use a different factory,
// because a GetObject() call with this objectName will go through the autoproxy
// infrastructure again.
// We to override just this object definition, as it may reference other objects
// and we're happy to take the parent's definition for those.
DefaultListableObjectFactory objectFactory = new DefaultListableObjectFactory(factory);
// Override the prototype object
objectFactory.RegisterObjectDefinition(name, definition);
// Complete configuring the PrototypeTargetSource
prototypeTargetSource.TargetObjectName = name;
prototypeTargetSource.ObjectFactory = objectFactory;
return prototypeTargetSource;
}
}
示例14: AutowireWithParent
public void AutowireWithParent()
{
XmlObjectFactory xof = new XmlObjectFactory(new ReadOnlyXmlTestResource("autowire.xml", GetType()));
DefaultListableObjectFactory lbf = new DefaultListableObjectFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add("Name", "kerry");
lbf.RegisterObjectDefinition("Spouse", new RootObjectDefinition(typeof(TestObject), pvs));
xof.ParentObjectFactory = lbf;
DoTestAutowire(xof);
}
示例15: GetObjectWithCtorArgsOnPrototypeOutOfOrderArgs
public void GetObjectWithCtorArgsOnPrototypeOutOfOrderArgs()
{
using (DefaultListableObjectFactory lof = new DefaultListableObjectFactory())
{
RootObjectDefinition prototype
= new RootObjectDefinition(typeof(TestObject));
prototype.IsSingleton = false;
lof.RegisterObjectDefinition("prototype", prototype);
try
{
TestObject to2 = lof.GetObject("prototype", new object[] { 35, "Mark" }) as TestObject;
Assert.IsNotNull(to2);
Assert.AreEqual(35, to2.Age);
Assert.AreEqual("Mark", to2.Name);
}
catch (ObjectCreationException ex)
{
Assert.IsTrue(ex.Message.IndexOf("'Object of type 'System.Int32' cannot be converted to type 'System.String'") >= 0);
}
}
}