public ActionResult GetMenu() { //TODO Eliminar cuando se descubra una mejor forma IApplicationContext appContext = new XmlApplicationContext(HttpContext.Server.MapPath(@"~/Config/service.xml"), HttpContext.Server.MapPath(@"~/Config/repository.xml")); UsuarioService = (IUsuarioService)appContext.GetObject("UsuarioService"); PerfilMenuService = (IPerfilMenuService)appContext.GetObject("PerfilMenuService"); // List<Usuario> ListUsuario = UsuarioService.ReadUsuarioByUsername(User.Identity.Name).ToList(); Usuario usuario = (Usuario)ListUsuario[0]; IList<PerfilMenu> ListPM = PerfilMenuService.ReadPerfilMenuByPerfilId(usuario.PerfilId).ToList(); IList<Menu> items = new List<Menu>(); foreach (PerfilMenu pm in ListPM) { pm.Menu.Activo = pm.Activo; items.Add(pm.Menu); } MenuViewModel menuViewModel = new MenuViewModel(items, usuario); return PartialView("_Nav", menuViewModel); }
public void TestAutoProxyCreation() { XmlApplicationContext context = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("advisorAutoProxyCreatorCircularReferencesTests.xml", typeof(AdvisorAutoProxyCreatorCircularReferencesTests))); CountingAfterReturningAdvisor countingAdvisor = (CountingAfterReturningAdvisor)context.GetObject("testAdvisor"); // direct deps of AutoProxyCreator are not eligable for proxying Assert.IsFalse(AopUtils.IsAopProxy(context.GetObject("aapc"))); Assert.IsFalse(AopUtils.IsAopProxy(countingAdvisor)); TestObjectFactoryObject testObjectFactory = (TestObjectFactoryObject) context.GetObject("&testObjectFactory"); Assert.IsFalse(AopUtils.IsAopProxy(testObjectFactory)); Assert.IsFalse(AopUtils.IsAopProxy(context.GetObject("someOtherObject"))); // this one is completely independent Assert.IsTrue(AopUtils.IsAopProxy(context.GetObject("independentObject"))); // Asserts SPRNET-1225 - advisor dependencies most not be auto-proxied object testObject = context.GetObject("testObjectFactory"); Assert.IsFalse(AopUtils.IsAopProxy(testObject)); // Asserts SPRNET-1224 - factory product most be cached context.GetObject("testObjectFactory"); testObjectFactory.GetObjectCounter = 0; context.GetObject("testObjectFactory"); Assert.AreEqual(0, testObjectFactory.GetObjectCounter); ICloneable someOtherObject = (ICloneable) context.GetObject("someOtherObject"); someOtherObject.Clone(); ICloneable independentObject = (ICloneable) context.GetObject("independentObject"); independentObject.Clone(); Assert.AreEqual(1, countingAdvisor.GetCalls()); }
public void Main() { var ctx = new XmlApplicationContext("objects.xml"); var o1 = ctx.GetObject("SingletonObject"); var o2 = ctx.GetObject("ProtoTypeObject"); ctx.Dispose(); }
public void CaseInsensitiveContext() { XmlApplicationContext ctx = new XmlApplicationContext(false, "assembly://Spring.Core.Tests/Spring.Context.Support/objects.xml"); Assert.IsTrue(ctx.ContainsObject("goran")); Assert.IsTrue(ctx.ContainsObject("Goran")); Assert.IsTrue(ctx.ContainsObject("GORAN")); Assert.AreEqual(ctx.GetObject("goran"), ctx.GetObject("GORAN")); }
public void Main() { var ctx = new XmlApplicationContext("q11630224/objects.xml"); var report1 = (IReport)ctx.GetObject("report1"); var report2 = (IReport)ctx.GetObject("report1"); Console.WriteLine(UsageTrackingInterceptor.UsageCount); report1.WriteReport(); report2.WriteReport(); Console.WriteLine(UsageTrackingInterceptor.UsageCount); }
public void ComponentsUseSpecifiedName() { _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan2.xml", GetType())); var objectDefinitionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames(); Assert.That(objectDefinitionNames.Count, Is.EqualTo(5 + 4)); Assert.That(_applicationContext.GetObject("Component"), Is.Not.Null); Assert.That(_applicationContext.GetObject("Service"), Is.Not.Null); Assert.That(_applicationContext.GetObject("Repository"), Is.Not.Null); Assert.That(_applicationContext.GetObject("Controller"), Is.Not.Null); Assert.That(_applicationContext.GetObject("Configuration"), Is.Not.Null); }
public void UsingNullFactoryObjectIsAnOptionIfWeMassageContextToAllowForNullReferences() { var ctx = new XmlApplicationContext("objects.xml", "objects-ref1-as-nullobject.xml"); var o2 = (MyClass)ctx.GetObject("MySecondObject"); Assert.IsNotNull(o2.Prop); var o = (MyClass)ctx.GetObject("MyObject"); Assert.IsNotNull(o.Prop); Assert.IsInstanceOf<IMyOtherInterface>(o.Prop); Assert.IsInstanceOf<MyOtherClassNullObject>(o.Prop); }
public void Main() { var ctx = new XmlApplicationContext("objects.xml"); var o = (MyClass)ctx.GetObject("MyObject"); Assert.AreEqual(typeof(MySecondClass), o.TheType); var o2 = (MyClass)ctx.GetObject("MyObject2"); Assert.AreEqual(typeof(MySecondClass), o2.TheType); var o3 = (MyClass)ctx.GetObject("MyObject3"); Assert.AreEqual(typeof(MySecondClass), o3.TheType); }
public void ScanComponentsAndAddToContext() { var prefix = "ComponentScan.ScanComponentsAndAddToContext."; _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan1.xml", GetType())); var objectDefinitionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames(); Assert.That(objectDefinitionNames.Count, Is.EqualTo(5+4)); Assert.That(_applicationContext.GetObject(prefix + "ComponentImpl"), Is.Not.Null); Assert.That(_applicationContext.GetObject(prefix + "ServiceImpl"), Is.Not.Null); Assert.That(_applicationContext.GetObject(prefix + "RepositoryImpl"), Is.Not.Null); Assert.That(_applicationContext.GetObject(prefix + "ControllerImpl"), Is.Not.Null); Assert.That(_applicationContext.GetObject(prefix + "ConfigurationImpl"), Is.Not.Null); }
public void Exe1() { var ctx2 = new StaticApplicationContext(); // var ctx = ContextRegistry.GetContext(); // 全局配置 var ctx = new XmlApplicationContext(System.AppDomain.CurrentDomain.BaseDirectory + "bin/SpringNet/objects.xml"); // 局部配置 //ctx.RegisterPrototype("Person", typeof(Student), null); //ctx.RegisterSingleton("Alice", typeof(Person), null); // 注册可以通过xml配置注册 Person person = ctx.GetObject("Person") as Person; Person alice = ctx.GetObject("Alice") as Person; var a = 1; }
public void Main() { var ctx = new XmlApplicationContext("objects.xml"); var myObject2 = new MyClass() { Name = "MyObject2"}; ctx.ObjectFactory.RegisterSingleton("MyObject2", myObject2); var o = ctx.GetObject("MyObject"); var o2 = (MyClass)ctx.GetObject("MyObject2"); Assert.AreEqual("MyObject2", o2.Name); }
public MainWindow() { InitializeComponent(); IApplicationContext context = new XmlApplicationContext("Config/spring.net.xml"); IUserService userService = (IUserService)context.GetObject("UserService"); IGroupService groupService = (IGroupService)context.GetObject("GroupService"); userService.Login("admin", "123456"); IList<GroupVO> list = groupService.GetListAll(); foreach (GroupVO vo in list) { this.textBox.Text += vo.GroupName + "---"; System.Console.WriteLine("" + vo.GroupName); } }
public void ShouldGetBacklogDistribution() { IApplicationContext context = new XmlApplicationContext(_config); IProbabilityDistribution backlogdist = (IProbabilityDistribution)context.GetObject("backlogdist"); Assert.AreEqual(2, backlogdist.NextValue()); }
/// <summary> /// Metodo que retorna la informacion de los insumos para generar las plantillas de estado de cuenta. /// </summary> /// <param name="IdConcesionario"></param> /// <param name="fecha"></param> /// <returns></returns> public System.Data.DataTable ObtenerInsumosPlantilla(decimal IdConcesionario, DateTime fecha) { DataTable insumo; try { IApplicationContext contexto = new XmlApplicationContext("DataConfiguration.xml"); this.ConsultaDatos = (IConsultasPlantillaDB)contexto.GetObject("DaoConsulta"); insumo = this.ConsultaDatos.ObtenerInsumosPlantilla(IdConcesionario, fecha); } catch (ExcepcionDatosEstadoCuenta excepcion) { throw excepcion; } catch (Exception excepcion) { string mensajeError = "Error presentado en la clase LogicaDatosEstadoCuenta en el método ObtenerInsumosPlantilla" + ". Detalle del error: " + excepcion.Message; throw new ExcepcionLogicaEstadoCuenta(mensajeError, excepcion); } return insumo; }
public void ContainerResolvesSauceBéarnaise() { var context = new XmlApplicationContext("sauce.xml"); SauceBéarnaise sauce = (SauceBéarnaise)context.GetObject("Sauce"); Assert.NotNull(sauce); }
public void ContainerLoadsXmlFromConfig() { var context = new XmlApplicationContext("config://spring/objects"); SauceBéarnaise sauce = (SauceBéarnaise)context.GetObject("Sauce"); Assert.NotNull(sauce); }
public void ShouldGetMachine() { IApplicationContext context = new XmlApplicationContext(_config); Machine machine = (Machine)context.GetObject("machine1"); Assert.IsNotNull(machine); }
public void ShouldGetResourcePool() { IApplicationContext context = new XmlApplicationContext(_config); ResourcePool resourcePool = (ResourcePool)context.GetObject("rp1"); Assert.AreEqual(1,resourcePool.ResourceCount); }
public void ContainerLoadsXmlFromEmbeddedResource() { var context = new XmlApplicationContext("assembly://Ploeh.Samples.Menu.SpringNet/Ploeh.Samples.Menu.SpringNet/sauce.xml"); SauceBéarnaise sauce = (SauceBéarnaise)context.GetObject("Sauce"); Assert.NotNull(sauce); }
public void ShouldGetWorkProcess() { IApplicationContext context = new XmlApplicationContext(_config); WorkProcess backlog = (WorkProcess)context.GetObject("process"); Assert.IsNotNull(backlog); }
public void ContainerLoadsXmlFromFileMoniker() { var context = new XmlApplicationContext("file://sauce.xml"); SauceBéarnaise sauce = (SauceBéarnaise)context.GetObject("Sauce"); Assert.NotNull(sauce); }
private static void PrintOutNameAndConnection(XmlApplicationContext ctx) { foreach (var name in ctx.GetObjectNamesForType(typeof (MyService))) { var svc = (MyService) ctx.GetObject(name); Console.WriteLine("{0} : {1}", name, svc.Connection); } }
public void Main() { var ctx = new XmlApplicationContext("objects.xml","objects2.xml"); var o = (MyClass)ctx.GetObject("MyObject"); Assert.AreEqual("From objects2.xml", o.Name); Console.WriteLine(o); }
public void ShouldGetWorkStation() { IApplicationContext context = new XmlApplicationContext(_config); IWorkStation ws = (IWorkStation)context.GetObject("ws1"); Assert.IsNotNull(ws); }
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 Main() { var ctx = new XmlApplicationContext("abstract-factory.xml"); var o = (Consumer)ctx.GetObject("consumer"); Assert.AreEqual("Illnois", o.Process("Illnois")); Assert.AreEqual("aksalA", o.Process("Alaska")); Assert.AreEqual("nisnocsiW", o.Process("Wisconsin")); }
public MainWindow() { InitializeComponent(); //log4net.Config.XmlConfigurator.Configure(); IApplicationContext context = new XmlApplicationContext("app_dao.xml"); IApplicationDao service = (IApplicationDao)context.GetObject("ApplicationDaoImpl"); System.Console.WriteLine("" + service); //IList userList = service.GetUserNames(); }
public void TestReceivesMessageFromChannelWithSource() { NamespaceParserRegistry.RegisterParser(typeof (IntegrationNamespaceParser)); IApplicationContext ctx = new XmlApplicationContext(@"Channel\Config\DirectChannelParserTests.xml"); object channel = ctx.GetObject("channel"); Assert.That(channel.GetType(), Is.EqualTo(typeof (DirectChannel))); }
public void Main() { var ctx = new XmlApplicationContext("objects.xml"); var o = (MyClass)ctx.GetObject("MyObject"); o.Method1(); Console.WriteLine(o); }
public void GetObjectOnUnknownIdThrowsNoSuchObjectDefinition() { XmlApplicationContext ctx = new XmlApplicationContext(false, "assembly://Spring.Core.Tests/Spring.Context.Support/objects.xml"); string DOES_NOT_EXIST = "does_not_exist"; Assert.IsFalse(ctx.ContainsObject(DOES_NOT_EXIST)); Assert.Throws <NoSuchObjectDefinitionException>(() => ctx.GetObject(DOES_NOT_EXIST)); }
public void Main() { var ctx = new XmlApplicationContext("objects.xml"); var o = (MyClass)ctx.GetObject("MyObject"); Assert.AreEqual(@"c:\\dev\\temp", o.Path); Console.WriteLine(o); }
public void testRendezvous() { NamespaceParserRegistry.RegisterParser(typeof (IntegrationNamespaceParser)); IApplicationContext ctx = new XmlApplicationContext(@"Channel\Config\RendezvousChannelParserTests.xml"); object channel = ctx.GetObject("channel"); Assert.That(channel.GetType(), Is.EqualTo(typeof (RendezvousChannel))); }
public void MultipleConfigLocations() { XmlApplicationContext ctx = new XmlApplicationContext(false, "assembly://Spring.Core.Tests/Spring.Context.Support/contextB.xml", "assembly://Spring.Core.Tests/Spring.Context.Support/contextC.xml", "assembly://Spring.Core.Tests/Spring.Context.Support/contextA.xml"); Assert.IsTrue(ctx.ContainsObject("service")); Assert.IsTrue(ctx.ContainsObject("logicOne")); Assert.IsTrue(ctx.ContainsObject("logicTwo")); Service service = (Service)ctx.GetObject("service"); ctx.Refresh(); Assert.IsTrue(service.ProperlyDestroyed); service = (Service)ctx.GetObject("service"); ctx.Dispose(); Assert.IsTrue(service.ProperlyDestroyed); }
public void ContextWithInvalidLazyType() { XmlApplicationContext ctx = new XmlApplicationContext(false, "assembly://Spring.Core.Tests/Spring.Context.Support/invalidType.xml"); Assert.IsTrue(ctx.ContainsObject("someMessageSource")); ctx.GetObject("someMessageSource"); }
public void ConfigureUsingXmlApplicationContext() { XmlApplicationContext appContext = new XmlApplicationContext(false, ReadOnlyXmlTestResource.GetFilePath("HttpApplicationConfigurerTests.xml", typeof(HttpApplicationConfigurerTests))); TestModule m1 = new TestModule(); TestModule m2 = new TestModule(); TestApplication appObject = new TestApplication(new ModuleEntry[] { new ModuleEntry("TestModule1", m1) , new ModuleEntry("TestModule2", m2), }); HttpApplicationConfigurer.Configure(appContext, appObject); // app configured Assert.AreEqual(appContext.GetObject("testObject"), appObject.TestObject); // modules configured Assert.AreEqual(appContext.GetObject("testObject1"), m1.TestObject); Assert.AreEqual(null, m2.TestObject); }
public void RefreshDisposesExistingObjectFactory_SPRNET479() { string tmp = typeof(DestroyTester).FullName; Console.WriteLine(tmp); IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Core.Tests/Spring.Context.Support/objects.xml"); DestroyTester destroyTester = (DestroyTester)ctx.GetObject("destroyTester"); DisposeTester disposeTester = (DisposeTester)ctx.GetObject("disposeTester"); Assert.IsFalse(destroyTester.IsDestroyed); Assert.IsFalse(disposeTester.IsDisposed); ((IConfigurableApplicationContext)ctx).Refresh(); Assert.IsTrue(destroyTester.IsDestroyed); Assert.IsTrue(disposeTester.IsDisposed); }
public void InnerObjectWithPostProcessing() { try { XmlApplicationContext ctx = new XmlApplicationContext(false, "assembly://Spring.Core.Tests/Spring.Context.Support/innerObjectsWithPostProcessor.xml"); ctx.GetObject("hasInnerObjects"); Assert.Fail("should throw ObjectCreationException"); } catch (ObjectCreationException e) { NoSuchObjectDefinitionException ex = e.InnerException as NoSuchObjectDefinitionException; Assert.IsNotNull(ex); //Pass } }
public void ConfigureObject() { const string objDefLocation = "assembly://Spring.Core.Tests/Spring.Context.Support/objects.xml"; XmlApplicationContext xmlContext = new XmlApplicationContext(new string[] { objDefLocation }); object objGoran = xmlContext.GetObject("goran"); Assert.IsTrue(objGoran is TestObject); TestObject fooGet = objGoran as TestObject; TestObject fooConfigure = new TestObject(); xmlContext.ConfigureObject(fooConfigure, "goran"); Assert.IsNotNull(fooGet); Assert.AreEqual(fooGet.Name, fooConfigure.Name); Assert.AreEqual(fooGet.Age, fooConfigure.Age); Assert.AreEqual(fooGet.ObjectName, fooConfigure.ObjectName); Assert.IsNotNull(fooGet.ObjectName); Assert.AreEqual(xmlContext, fooGet.ApplicationContext); Assert.AreEqual(xmlContext, fooConfigure.ApplicationContext); }