public void GetSaoWithSingletonModeAndAop() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/saoSingleton-aop.xml"); ContextRegistry.RegisterContext(ctx); //object saoFactory = ctx.GetObject("&remoteCounter"); //Assert.IsNotNull(saoFactory); object obj = ctx.GetObject("remoteCounter"); Assert.IsNotNull(obj, "Object is null even though a object has been exported."); Assert.IsTrue(AopUtils.IsAopProxy(obj)); Assert.IsTrue((obj is ISimpleCounter), "Object should implement 'ISimpleCounter' interface."); MethodCounter aopCounter = ctx.GetObject("countingBeforeAdvice") as MethodCounter; Assert.IsNotNull(aopCounter); int aopCount = aopCounter.GetCalls("Count"); Assert.AreEqual(0, aopCount); ISimpleCounter sc = (ISimpleCounter)obj; Assert.AreEqual(1, sc.Counter, "Remote object hasn't been activated by the server."); sc.Count(); Assert.AreEqual(2, sc.Counter, "Remote object doesn't work in a 'Singleton' mode."); Assert.AreEqual(1, aopCounter.GetCalls("Count")); }
private void RegisterContextIfNeeded(IApplicationContext childContext) { if (!ContextRegistry.IsContextRegistered(childContext.Name)) { ContextRegistry.RegisterContext(childContext); } }
public static Context Create(string name) { Context context = new Context(name, true); ContextRegistry.RegisterContext(name, context); return(context); }
public void _TestSetUp() { var context = new GenericApplicationContext(); ContextRegistry.Clear(); ContextRegistry.RegisterContext(context); }
public void CanCreateWithDefaults() { string SESSIONFACTORY_OBJECTNAME = ConfigSectionSessionScopeSettings.DEFAULT_SESSION_FACTORY_OBJECT_NAME; // setup expected values MockRepository mocks = new MockRepository(); ISessionFactory expectedSessionFactory = mocks.StrictMock <ISessionFactory>(); IInterceptor expectedEntityInterceptor = null; bool expectedSingleSession = SessionScopeSettings.SINGLESESSION_DEFAULT; FlushMode expectedDefaultFlushMode = SessionScopeSettings.FLUSHMODE_DEFAULT; // create and register context StaticApplicationContext appCtx = new StaticApplicationContext(); appCtx.Name = AbstractApplicationContext.DefaultRootContextName; appCtx.ObjectFactory.RegisterSingleton(SESSIONFACTORY_OBJECTNAME, expectedSessionFactory); ContextRegistry.Clear(); ContextRegistry.RegisterContext(appCtx); ConfigSectionSessionScopeSettings settings = new ConfigSectionSessionScopeSettings(this.GetType(), (IVariableSource)null); Assert.AreEqual(expectedSessionFactory, settings.SessionFactory); Assert.AreEqual(expectedEntityInterceptor, settings.EntityInterceptor); Assert.AreEqual(expectedSingleSession, settings.SingleSession); Assert.AreEqual(expectedDefaultFlushMode, settings.DefaultFlushMode); }
public void InitSpring(string configFilePath) { // Setup this context as the main ApplicationContext IApplicationContext context = new XmlApplicationContext(configFilePath); ContextRegistry.RegisterContext(context); }
public void _TestSetup() { using (new VirtualEnvironmentMock("/somedir/some.file", null, null, "/", true)) { ContextRegistry.Clear(); _context = new MvcApplicationContext("file://objects.xml"); _mvcNamedContext = new MvcApplicationContext("named", false, "file://namedContextObjects.xml"); ContextRegistry.RegisterContext(_context); ContextRegistry.RegisterContext(_mvcNamedContext); _factory = new SpringControllerFactory(); //due to ridiculous internal methods in DefaultControllerFactory, have to set the ControllerTypeCache using this extension method // see http://stackoverflow.com/questions/727181/asp-net-mvc-system-web-compilation-compilationlock for more info _factory.InitializeWithControllerTypes(new[] { typeof(FirstContainerRegisteredController), typeof(SecondContainerRegisteredController), typeof(NotInContainerController), typeof(NamedContextController), }); SpringControllerFactory.ApplicationContextName = string.Empty; } }
public SpringObjectFactory() { applicationContext = new GenericApplicationContext(); ContextRegistry.Clear(); ContextRegistry.RegisterContext(applicationContext); objectDefinitionRegistry = (IObjectDefinitionRegistry)applicationContext.ObjectFactory; }
public virtual void SetUp() { log4net.Config.XmlConfigurator.Configure(); StaticApplicationContext appContext = new StaticApplicationContext(); RegisterObjects(appContext); ContextRegistry.RegisterContext(appContext); }
public void SetUp() { string physDir = AppDomain.CurrentDomain.BaseDirectory + "\\"; IApplicationContext appContext = new XmlApplicationContext(AbstractApplicationContext.DefaultRootContextName, false, RES_OBJECTS); ContextRegistry.RegisterContext(appContext); appContext = new GenericApplicationContext("/controls/", false, appContext); ContextRegistry.RegisterContext(appContext); }
/// <summary> /// Creates the ApplicationContext /// </summary> /// <param name="springConfigurationFiles">Set of spring configuration files (xml)</param> /// <param name="contextName">spring context will be registered with this name</param> public SpringContext(string[] springConfigurationFiles, string contextName) { // check if file exists CheckExistenceOfConfigurationFiles(springConfigurationFiles); // load configurations ApplicationContext = new FastLoadingXmlApplicationContext(contextName, springConfigurationFiles); // and register the context. ContextRegistry.RegisterContext(ApplicationContext); }
public void Test_Init_Spring_Context_With_JsonVariableSource_Should_Throw_Exception_When_JSon_File_Is_Invalid() { /* Given: Spring-config with invalid json-file as JsonVariableSource */ string springConfigReferencingInvalidJsonVariableSource = "..\\..\\Sample\\Invalid\\sample.spring.config.xml"; /* When: Spring context is started */ Action action = () => ContextRegistry.RegisterContext(new XmlApplicationContext(springConfigReferencingInvalidJsonVariableSource)); /* Then: exception should be thrown */ action.ShouldThrow <ObjectCreationException>(); }
public void CanRevertToTypeMatchIfIdMatchUnsuccessful() { MvcApplicationContext context = new MvcApplicationContext("file://objectsMatchByType.xml"); ContextRegistry.Clear(); ContextRegistry.RegisterContext(context); IController controller = _factory.CreateController(new RequestContext(new MockContext(), new RouteData()), "FirstContainerRegistered"); Assert.AreEqual("Should_Be_Matched_By_Type", ((FirstContainerRegisteredController)controller).TestValue); }
private void LoadSpringConfig() { NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser)); NamespaceParserRegistry.RegisterParser(typeof(TxNamespaceParser)); NamespaceParserRegistry.RegisterParser(typeof(AopNamespaceParser)); string[] param = { "~/AppConfig/Config.xml" }; IApplicationContext context = new XmlApplicationContext(param); ContextRegistry.RegisterContext(context); }
public void _TestSetup() { ContextRegistry.Clear(); _context = new MvcApplicationContext("file://objectsMvc.xml"); _mvcNamedContext = new MvcApplicationContext("named", false, "file://namedContextObjectsMvc.xml"); ContextRegistry.RegisterContext(_context); ContextRegistry.RegisterContext(_mvcNamedContext); _resolver = new SpringMvcDependencyResolver(_context); _resolver.ApplicationContextName = string.Empty; }
/// <summary> /// Caches application context. /// </summary> /// <param name="key">Key to use.</param> /// <param name="context">Context to cache.</param> public void AddContext(object key, IConfigurableApplicationContext context) { AssertUtils.ArgumentNotNull(context, "context", "ApplicationContext must not be null"); string keyString = ContextKeyString(key); contextKeyToContextMap.Add(keyString, context); if (RegisterContextWithContextRegistry && !ContextRegistry.IsContextRegistered(context.Name)) { ContextRegistry.RegisterContext(context); } }
public void GetSaoWithLifetimeService() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/saoLifetimeService.xml"); ContextRegistry.RegisterContext(ctx); MarshalByRefObject obj = (MarshalByRefObject)ctx.GetObject("remoteSaoCounter"); ILease lease = (ILease)obj.GetLifetimeService(); Assert.AreEqual(TimeSpan.FromMilliseconds(10000), lease.InitialLeaseTime, "InitialLeaseTime"); Assert.AreEqual(TimeSpan.FromMilliseconds(1000), lease.RenewOnCallTime, "RenewOnCallTime"); Assert.AreEqual(TimeSpan.FromMilliseconds(100), lease.SponsorshipTimeout, "SponsorshipTimeout"); }
public void DisconnectFromClient() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/cao.xml"); ContextRegistry.RegisterContext(ctx); object obj = ctx.GetObject("remoteCaoCounter1"); Assert.IsNotNull(obj, "CAO is null even though a CAO has been registered."); IDisposable cao = obj as IDisposable; Assert.IsNotNull(cao, "CAO should implement 'IDisposable' interface."); }
public void RegistersSimpleObject() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/caoLifetimeService.xml"); ContextRegistry.RegisterContext(ctx); ICaoRemoteFactory caoFactory = Activator.GetObject(typeof(ICaoRemoteFactory), "tcp://localhost:8005/counter2") as ICaoRemoteFactory; Assert.IsNotNull(caoFactory, "Cao factory is null even though it has been registered."); MarshalByRefObject cao = caoFactory.GetObject() as MarshalByRefObject; Assert.IsNotNull(cao); }
public void Test_Init_Spring_Context_With_JsonVariableSource_Should_Correctly_Resolve_Bean_When_JSon_File_Is_Valid() { /* Given: Spring-context with JsonVariableSource */ ContextRegistry.RegisterContext(new XmlApplicationContext("..\\..\\Sample\\Valid\\sample.spring.config.xml")); /* When: Spring context is started */ SampleSpringBean sampleSpringBean = ContextRegistry.GetContext().GetObject <SampleSpringBean>(); /* Then: Bean should be resolved including properties */ sampleSpringBean.Should().NotBeNull(); sampleSpringBean.ApplicationName.Should().Be("Sample Application"); sampleSpringBean.Login.Should().Be("username"); sampleSpringBean.Password.Should().Be("top-secret123!"); }
public void ConfiguresUsingFilename() { Assert.AreEqual(1, ChannelServices.RegisteredChannels.Length); Assert.AreEqual(channel, ChannelServices.RegisteredChannels[0]); ChannelServices.UnregisterChannel(channel); Assert.AreEqual(0, ChannelServices.RegisteredChannels.Length); IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/remotingConfigurer.xml"); ContextRegistry.RegisterContext(ctx); Assert.AreEqual(1, ChannelServices.RegisteredChannels.Length); Assert.AreEqual("tcp", ChannelServices.RegisteredChannels[0].ChannelName); }
public Context(string name) { _name = name; ContextRegistry.RegisterContext(name, this); _dependencies = new Dictionary <Type, object>(); _listedDependencies = new List <object>(); _factories = new Dictionary <Type, IFactoryFacade>(); _autoCompositionTypes = new HashSet <Type>(); EventManager = new EventManager(); EventManager.EventInjectors += OnBlindEventHandler; RegisterDependency <IEventDispatcher>(EventManager); _parentContext = ParentContextStub.STUB; }
public void GetSimpleObject() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/cao.xml"); ContextRegistry.RegisterContext(ctx); object obj = ctx.GetObject("remoteCaoCounter1"); Assert.IsNotNull(obj, "Object is null even though a object has been registered."); Assert.IsTrue((obj is ISimpleCounter), "Object should implement 'ISimpleCounter' interface."); ISimpleCounter sc = (ISimpleCounter)obj; Assert.AreEqual(7, sc.Counter, "Remote object hasn't been activated by the client."); sc.Count(); Assert.AreEqual(8, sc.Counter); }
public void GetSaoWithSingletonMode() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/saoSingleton.xml"); ContextRegistry.RegisterContext(ctx); object obj = ctx.GetObject("remoteSaoSingletonCounter"); Assert.IsNotNull(obj, "Object is null even though a object has been exported."); Assert.IsTrue((obj is ISimpleCounter), "Object should implement 'ISimpleCounter' interface."); ISimpleCounter sc = (ISimpleCounter)obj; Assert.AreEqual(1, sc.Counter, "Remote object hasn't been activated by the server."); sc.Count(); Assert.AreEqual(2, sc.Counter, "Remote object doesn't work in a 'Singleton' mode."); }
public static void RegisterContext(string xmlContext, string rootContextName = SpringAutowire.DefaultRootContextName) { if (!ContextRegistry.IsContextRegistered(rootContextName)) { lock (_lock) { if (!ContextRegistry.IsContextRegistered(rootContextName)) { XmlApplicationContext ctx = new XmlApplicationContext(new XmlApplicationContextArgs { Name = rootContextName, ConfigurationResources = new IResource[] { new StringResource(xmlContext) } }); ContextRegistry.RegisterContext(ctx); } } } }
/// <summary> /// 创建容器 /// <code> /// IApplicationContext Container = ChildContainer.Create(container, contextName, ecs); /// </code> /// </summary> /// <param name="container">IApplicationContext容器</param> /// <param name="contextName">容器名</param> /// <param name="configuration">Configuration配置对象</param> /// <returns></returns> public static IApplicationContext Create(IApplicationContext container, string contextName, Configuration configuration) { string _contextName = contextName.ToLower(); ExeConfigurationSystem config = new ExeConfigurationSystem(configuration); IApplicationContext ctx = config.GetSection(_contextName, container, AbstractApplicationContext.ContextSectionName) as IApplicationContext; if (!ContextRegistry.IsContextRegistered(_contextName) && ctx.Name != "spring.root") { try { ContextRegistry.RegisterContext(ctx); } catch (Exception e) { throw new Exception("Registered ContextName does not exist!Could be a plug-in ContextName for plug-in assembly name (not fullName)", e); } } return(ctx); }
public void GetSaoWithSingletonModeAutowired_SPRNET967() { // register server by hand to avoid duplicate interfaces SPRNET967_SimpleCounterWrapper svr = new SPRNET967_SimpleCounterWrapper(new SimpleCounter(1)); RemotingServices.Marshal(svr, "RemotedSaoSingletonCounter"); // object svc = Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/RemotedSaoSingletonCounter"); // Assert.IsTrue( svc is IObjectDefinition ); // Assert.IsTrue( svc is ISimpleCounter ); IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/saoSingleton-autowired.xml"); ContextRegistry.RegisterContext(ctx); SPRNET967_SimpleCounterClient client = (SPRNET967_SimpleCounterClient)ctx.GetObject("counterClient"); client.Count(); Assert.AreEqual(2, client.Counter); }
private static AbstractApplicationContext GetAbstractApplicationContext() { if (!ContextRegistry.IsContextRegistered(_RootContext)) { lock (lock_init) { if (!ContextRegistry.IsContextRegistered(_RootContext)) { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.Name = _RootContext; XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(ctx); reader.LoadObjectDefinitions(new StringResource("<?xml version=\"1.0\" encoding=\"utf-8\" ?><objects></objects>")); ContextRegistry.RegisterContext(ctx); } } } return(ContextRegistry.GetContext(_RootContext) as AbstractApplicationContext); }
public void WiringWithTransparentProxy() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/autowire.xml"); ContextRegistry.RegisterContext(ctx); TestObject to = (TestObject)ctx.GetObject("kerry3"); Assert.IsNotNull(to, "Object is null even though a object has been configured."); Assert.IsTrue(RemotingServices.IsTransparentProxy(to.Sibling), "IsTransparentProxy"); Assert.AreEqual("Kerry3", to.Name, "Name"); to = (TestObject)ctx.GetObject("objectWithCtorArgRefShortcuts"); Assert.IsTrue(RemotingServices.IsTransparentProxy(to.Spouse), "IsTransparentProxy"); ConstructorDependenciesObject cdo = (ConstructorDependenciesObject)ctx.GetObject("rod2"); Assert.IsTrue(RemotingServices.IsTransparentProxy(cdo.Spouse1), "IsTransparentProxy"); Assert.IsTrue(RemotingServices.IsTransparentProxy(cdo.Spouse2), "IsTransparentProxy"); }
public void SetUp() { //BasicConfigurator.Configure(); string assemblyName = GetType().Assembly.GetName().Name; //ctx = new XmlApplicationContext("assembly://" + assemblyName + "/Spring.Data.NHibernate/NHDAOTests.xml"); string[] contextFiles = new string[] { "assembly://" + assemblyName + "/Spring.Data.NHibernate/Controllers.xml", "assembly://" + assemblyName + "/Spring.Data.NHibernate/Services.xml", "assembly://" + assemblyName + "/Spring.Data.NHibernate/Dao.xml" }; ctx = new XmlApplicationContext(contextFiles); ctx.Name = AbstractApplicationContext.DefaultRootContextName; if (!ContextRegistry.IsContextRegistered(AbstractApplicationContext.DefaultRootContextName)) { ContextRegistry.RegisterContext(ctx); } }