本文整理汇总了C#中Spring.Objects.Factory.Support.DefaultListableObjectFactory类的典型用法代码示例。如果您正苦于以下问题:C# DefaultListableObjectFactory类的具体用法?C# DefaultListableObjectFactory怎么用?C# DefaultListableObjectFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultListableObjectFactory类属于Spring.Objects.Factory.Support命名空间,在下文中一共展示了DefaultListableObjectFactory类的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: 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]);
}
示例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: LoadConfiguration
/// <summary>
/// Load all registered configuration into spring. This method should only be called internally by the FluentApplicationContext, i.e. you shouldn't call it.
/// </summary>
/// <param name="objectFactory">The object factory.</param>
public static void LoadConfiguration(DefaultListableObjectFactory objectFactory)
{
// This check is mainly for backward compability and avoid people trying to register their configuration twice.
if (!_configurationRegistry.ContainsConfiguration())
{
if (_assembliesList.Count == 0)
{
_assembliesList.Add(() => AppDomain.CurrentDomain.GetAssemblies());
}
IList<Type> applicationContextConfigurerTypes = new List<Type>();
// only load the configuration once (in case the assembly was registered twice)
foreach (Type type in from assemblies in _assembliesList
from assembly in assemblies()
from type in assembly.GetTypes()
where type.GetInterfaces().Contains(typeof (ICanConfigureApplicationContext))
where !applicationContextConfigurerTypes.Contains(type)
select type)
{
applicationContextConfigurerTypes.Add(type);
}
// load each class containing configuration.
foreach (ICanConfigureApplicationContext contextConfigurer in
applicationContextConfigurerTypes.Select(applicationContextConfigurerType => (ICanConfigureApplicationContext) Activator.CreateInstance(applicationContextConfigurerType)))
{
contextConfigurer.Configure();
}
}
_configurationRegistry.LoadObjectDefinitions(objectFactory);
}
示例5: SetUp
protected void SetUp()
{
parent = new DefaultListableObjectFactory();
IDictionary<string, object> m = new Dictionary<string, object>();
m["name"] = "Albert";
parent.RegisterObjectDefinition("father", new RootObjectDefinition(typeof(TestObject), new MutablePropertyValues(m)));
m = new Dictionary<string, object>();
m["name"] = "Roderick";
parent.RegisterObjectDefinition("rod", new RootObjectDefinition(typeof(TestObject), new MutablePropertyValues(m)));
// for testing dynamic ctor arguments + parent.GetObject() call propagation
parent.RegisterObjectDefinition("namedfather", new RootObjectDefinition(typeof(TestObject), false));
parent.RegisterObjectDefinition("typedfather", new RootObjectDefinition(typeof(TestObject), false));
// add unsupported IObjectDefinition implementation...
//UnsupportedObjectDefinitionImplementation unsupportedDefinition = new UnsupportedObjectDefinitionImplementation();
//parent.RegisterObjectDefinition("unsupportedDefinition", unsupportedDefinition);
XmlObjectFactory factory;
factory = new XmlObjectFactory(new ReadOnlyXmlTestResource("test.xml", GetType()), parent);
// TODO: should this be allowed?
//this.factory.RegisterObjectDefinition("typedfather", new RootObjectDefinition(typeof(object), false));
factory.AddObjectPostProcessor(new AnonymousClassObjectPostProcessor());
factory.AddObjectPostProcessor(new LifecycleObject.PostProcessor());
factory.PreInstantiateSingletons();
base.ObjectFactory = factory;
}
示例6: 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 );
}
示例7: Can_Create_Custom_Scan_Routine
public void Can_Create_Custom_Scan_Routine()
{
var scanner = new ScanOverridingAssemblyObjectDefinitionScanner();
var registry = new DefaultListableObjectFactory();
scanner.ScanAndRegisterTypes(registry);
Assert.That(registry.ObjectDefinitionCount, Is.EqualTo(1), "found multiple definitions");
Assert.That(registry.GetObject<ComponentScan.ScanComponentsAndAddToContext.ConfigurationImpl>(), Is.Not.Null,
"correct single defintion was not registered");
}
开发者ID:spring-projects,项目名称:spring-net-codeconfig,代码行数:9,代码来源:AssemblyObjectDefinitionScannerTests.cs
示例8: LoadObjectDefinitions
protected override void LoadObjectDefinitions(DefaultListableObjectFactory objectFactory)
{
//wrap the objectFactory with our own proxy so that we keep track of the objects ids defined in the Spring.NET context
callbacks.Add(new BeanohObjectFactoryMethodInterceptor(objectFactory));
ProxyGenerator generator = new ProxyGenerator();
DefaultListableObjectFactory wrapper = (DefaultListableObjectFactory)generator.CreateClassProxy(objectFactory.GetType(), callbacks.ToArray());
//delegate to our proxy
base.LoadObjectDefinitions(wrapper);
}
示例9: 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);
}
示例10: StaticEventWiring
public virtual void StaticEventWiring()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("event-wiring.xml", GetType()));
TestEventHandler staticHandler = factory["staticEventListener"] as TestEventHandler;
// raise the event... handlers should be notified at this point (obviously)
TestObject.OnStaticClick();
Assert.IsTrue(staticHandler.EventWasHandled,
"The instance handler did not get notified when the static event was raised (and was probably not wired up in the first place).");
}
示例11: 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"));
}
}
示例12: BailsIfTargetNotFound
public void BailsIfTargetNotFound()
{
using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
{
SaoExporter saoExporter = new SaoExporter();
saoExporter.ObjectFactory = of;
saoExporter.TargetName = "DOESNOTEXIST";
saoExporter.ServiceName = "RemotedSaoSingletonCounter";
saoExporter.AfterPropertiesSet();
}
}
示例13: EventWiringInstanceSinkToPrototypeSource
public virtual void EventWiringInstanceSinkToPrototypeSource()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("event-wiring-prototypes.xml", GetType()));
TestEventHandler instanceHandler = factory["instanceSink"] as TestEventHandler;
ITestObject source = factory["source"] as ITestObject;
// raise the event... handlers should be notified at this point (obviously)
source.OnClick();
Assert.IsTrue(instanceHandler.EventWasHandled,
"The instance handler did not get notified when the instance event was raised (and was probably not wired up in the first place).");
}
示例14: 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);
}
示例15: 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;
}