public void ResolvingPrimitivesThroughProperties() { MutableConfiguration config = new MutableConfiguration("component"); MutableConfiguration parameters = new MutableConfiguration("parameters"); config.Children.Add(parameters); parameters.Children.Add(new MutableConfiguration("name", "hammett")); parameters.Children.Add(new MutableConfiguration("address", "something")); parameters.Children.Add(new MutableConfiguration("age", "25")); kernel.ConfigurationStore.AddComponentConfiguration("customer", config); kernel.AddComponent("customer", typeof (ICustomer), typeof (CustomerImpl)); expectedClient = kernel.GetHandler("customer").ComponentModel; expectedModels = new List<DependencyModel>(); foreach (PropertySet prop in kernel.GetHandler("customer").ComponentModel.Properties) { expectedModels.Add(prop.Dependency); } ICustomer customer = (ICustomer) kernel["customer"]; Assert.IsNotNull(customer); }
public void SimpleCase() { String contents = "import Castle.Facilities.AspectSharp.Tests.Components in Castle.Facilities.AspectSharp.Tests " + "import Castle.Facilities.AspectSharp.Tests.Interceptors in Castle.Facilities.AspectSharp.Tests " + " " + " aspect MyAspect for SimpleService " + " " + " pointcut method|property(*)" + " advice(LoggerInterceptor)" + " end" + " " + " end "; MutableConfiguration config = new MutableConfiguration("facility", contents); DefaultConfigurationStore store = new DefaultConfigurationStore(); store.AddFacilityConfiguration("aop", config); WindsorContainer container = new WindsorContainer(store); container.AddFacility( "aop", new AspectSharpFacility() ); container.AddComponent("comp1", typeof(SimpleService)); SimpleService service = container[ typeof(SimpleService) ] as SimpleService; service.DoSomething(); service.DoSomethingElse(); Assert.AreEqual( "Enter DoSomething\r\nEnter DoSomethingElse\r\n", LoggerInterceptor.Messages.ToString() ); }
public void SetUp() { uncaughtException = null; container = new WindsorContainer(); container.AddFacility("sync.facility", new SynchronizeFacility()); container.AddComponent("sync.context", typeof(SynchronizationContext)); container.AddComponent("dummy.form.class", typeof(DummyForm)); container.AddComponent("dummy.form.service", typeof(IDummyForm), typeof(DummyForm)); container.AddComponent("class.in.context", typeof(ClassUsingFormInContext)); container.AddComponent("sync.class.no.context", typeof(SyncClassWithoutContext)); container.AddComponent("sync.class.override.context", typeof(SyncClassOverrideContext)); MutableConfiguration componentNode = new MutableConfiguration("component"); componentNode.Attributes[Constants.SynchronizedAttrib] = "true"; MutableConfiguration synchronizeNode = new MutableConfiguration("synchronize"); synchronizeNode.Attributes["contextType"] = typeof(WindowsFormsSynchronizationContext).AssemblyQualifiedName; MutableConfiguration doWorkMethod = new MutableConfiguration("method"); doWorkMethod.Attributes["name"] = "DoWork"; doWorkMethod.Attributes["contextType"] = typeof(WindowsFormsSynchronizationContext).AssemblyQualifiedName; synchronizeNode.Children.Add(doWorkMethod); componentNode.Children.Add(synchronizeNode); container.AddComponent("generic.class.in.context", typeof(IClassUsingContext<>), typeof(ClassUsingContext<>)); container.Kernel.ConfigurationStore.AddComponentConfiguration("class.needing.context", componentNode); container.AddComponent("class.needing.context", typeof(ClassUsingForm)); }
public void SetUp() { application = new Application(); uncaughtException = null; container = new WindsorContainer(); container.AddFacility<SynchronizeFacility>() .Register(Component.For<SynchronizationContext>(), Component.For<AsynchronousContext>(), Component.For<DummyWindow>().Named("Dummy").Activator<DummyFormActivator>(), Component.For<IDummyWindow>().ImplementedBy<DummyWindow>(), Component.For<ClassUsingWindowInWindowsContext>(), Component.For<ClassUsingWindowInAmbientContext>(), Component.For(typeof(IClassUsingDepedenecyContext<>)).ImplementedBy(typeof(ClassUsingDispatcherContext<>)), Component.For<IWorker>().ImplementedBy<SimpleWorker>(), Component.For<IWorkerWithOuts>().ImplementedBy<AsynchronousWorker>(), Component.For<ManualWorker>() ); var componentNode = new MutableConfiguration("component"); componentNode.Attributes[Constants.SynchronizedAttrib] = "true"; var synchronizeNode = new MutableConfiguration("synchronize"); synchronizeNode.Attributes["contextType"] = typeof(DispatcherSynchronizationContext).AssemblyQualifiedName; var doWorkMethod = new MutableConfiguration("method"); doWorkMethod.Attributes["name"] = "DoWork"; doWorkMethod.Attributes["contextType"] = typeof(DispatcherSynchronizationContext).AssemblyQualifiedName; synchronizeNode.Children.Add(doWorkMethod); componentNode.Children.Add(synchronizeNode); container.Kernel.ConfigurationStore.AddComponentConfiguration("class.needing.context", componentNode); container.Register(Component.For<ClassUsingWindow>().Named("class.needing.context")); }
public void UnsatisfiedConfigValues() { MutableConfiguration config = new MutableConfiguration("component"); MutableConfiguration parameters = new MutableConfiguration("parameters"); config.Children.Add(parameters); parameters.Children.Add(new MutableConfiguration("name", "hammett")); kernel.ConfigurationStore.AddComponentConfiguration("customer", config); kernel.Register(Component.For(typeof(CustomerImpl2)).Named("key")); var exception = Assert.Throws(typeof(HandlerException), () => { object instance = kernel["key"]; }); var expectedMessage = string.Format( "Can't create component 'key' as it has dependencies to be satisfied. {0}key is waiting for the following dependencies: {0}{0}" + "Keys (components with specific keys){0}- name which was not registered. {0}- address which was not registered. {0}" + "- age which was not registered. {0}", Environment.NewLine); Assert.AreEqual(expectedMessage, exception.Message); }
protected override WindsorContainer BuildContainer() { uncaughtException = null; var container = new WindsorContainer(); container.AddFacility<SynchronizeFacility>() .Register(Component.For<SynchronizationContext>(), Component.For<AsynchronousContext>(), Component.For<DummyForm>().Named("Dummy") .Activator<DummyFormActivator>(), Component.For<IDummyForm>().ImplementedBy<DummyForm>(), Component.For<ClassUsingFormInWindowsContext>(), Component.For<ClassUsingFormInAmbientContext>(), Component.For<SyncClassWithoutContext>(), Component.For<SyncClassOverrideContext>(), Component.For(typeof(IClassUsingContext<>)).ImplementedBy(typeof(ClassUsingContext<>)), Component.For<IWorker>().ImplementedBy<SimpleWorker>(), Component.For<IWorkerWithOuts>().ImplementedBy<AsynchronousWorker>(), Component.For<ManualWorker>() ); var componentNode = new MutableConfiguration("component"); componentNode.Attributes[Constants.SynchronizedAttrib] = "true"; var synchronizeNode = new MutableConfiguration("synchronize"); synchronizeNode.Attributes["contextType"] = typeof(WindowsFormsSynchronizationContext).AssemblyQualifiedName; var doWorkMethod = new MutableConfiguration("method"); doWorkMethod.Attributes["name"] = "DoWork"; doWorkMethod.Attributes["contextType"] = typeof(WindowsFormsSynchronizationContext).AssemblyQualifiedName; synchronizeNode.Children.Add(doWorkMethod); componentNode.Children.Add(synchronizeNode); container.Kernel.ConfigurationStore.AddComponentConfiguration("class.needing.context", componentNode); container.Register(Component.For<ClassUsingForm>().Named("class.needing.context")); return container; }
protected override void PopulateBusConfiguration(MutableConfiguration busConfig) { base.PopulateBusConfiguration(busConfig); if (string.IsNullOrEmpty(Path) == false) busConfig.Attribute("path", Path); }
public void TestComponentWithNoInterface() { IKernel kernel = new DefaultKernel(); kernel.ComponentCreated += new ComponentInstanceDelegate(OnNoInterfaceStartableComponentStarted); MutableConfiguration compNode = new MutableConfiguration("component"); compNode.Attributes["id"] = "b"; compNode.Attributes["startable"] = "true"; compNode.Attributes["startMethod"] = "Start"; compNode.Attributes["stopMethod"] = "Stop"; kernel.ConfigurationStore.AddComponentConfiguration("b", compNode); kernel.AddFacility("startable", new StartableFacility()); kernel.Register(Component.For(typeof(NoInterfaceStartableComponent)).Named("b")); Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started"); NoInterfaceStartableComponent component = kernel["b"] as NoInterfaceStartableComponent; Assert.IsNotNull(component); Assert.IsTrue(component.Started); Assert.IsFalse(component.Stopped); kernel.ReleaseComponent(component); Assert.IsTrue(component.Stopped); }
public void ComplexConfigurationParameter() { var key = "key"; var value1 = "value1"; var value2 = "value2"; var confignode = new MutableConfiguration(key); IConfiguration parameters = new MutableConfiguration("parameters"); confignode.Children.Add(parameters); IConfiguration complexParam = new MutableConfiguration("complexparam"); parameters.Children.Add(complexParam); IConfiguration complexNode = new MutableConfiguration("complexparametertype"); complexParam.Children.Add(complexNode); complexNode.Children.Add(new MutableConfiguration("mandatoryvalue", value1)); complexNode.Children.Add(new MutableConfiguration("optionalvalue", value2)); kernel.ConfigurationStore.AddComponentConfiguration(key, confignode); kernel.Register(Component.For(typeof(ClassWithComplexParameter)).Named(key)); var instance = kernel.Resolve<ClassWithComplexParameter>(key); Assert.IsNotNull(instance); Assert.IsNotNull(instance.ComplexParam); Assert.AreEqual(value1, instance.ComplexParam.MandatoryValue); Assert.AreEqual(value2, instance.ComplexParam.OptionalValue); }
public MutableConfiguration CreateChild(string name, string value) { MutableConfiguration child = new MutableConfiguration(name, value); Children.Add(child); return(child); }
public void ConstructorWithArrayParameter() { var confignode = new MutableConfiguration("key"); IConfiguration parameters = new MutableConfiguration("parameters"); confignode.Children.Add(parameters); IConfiguration hosts = new MutableConfiguration("hosts"); parameters.Children.Add(hosts); IConfiguration array = new MutableConfiguration("array"); hosts.Children.Add(array); array.Children.Add(new MutableConfiguration("item", "castle")); array.Children.Add(new MutableConfiguration("item", "uol")); array.Children.Add(new MutableConfiguration("item", "folha")); kernel.ConfigurationStore.AddComponentConfiguration("key", confignode); kernel.Register(Component.For(typeof(ClassWithConstructors)).Named("key")); var instance = kernel.Resolve<ClassWithConstructors>("key"); Assert.IsNotNull(instance); Assert.IsNull(instance.Host); Assert.AreEqual("castle", instance.Hosts[0]); Assert.AreEqual("uol", instance.Hosts[1]); Assert.AreEqual("folha", instance.Hosts[2]); }
private void AddComponent(string key, Type service, Type type, string factoryMethod) { MutableConfiguration config = new MutableConfiguration(key); config.Attributes["factoryId"] = "factory"; config.Attributes["factoryCreate"] = factoryMethod; container.Kernel.ConfigurationStore.AddComponentConfiguration(key, config); container.Kernel.AddComponent(key, service, type); }
public void InvalidProtocol_throws() { var configStore = new DefaultConfigurationStore(); var configuration = new MutableConfiguration("facility"); configuration.Attribute("type", typeof(SolrNetFacility).AssemblyQualifiedName); configuration.CreateChild("solrURL", "ftp://localhost"); configStore.AddFacilityConfiguration(typeof(SolrNetFacility).FullName, configuration); new WindsorContainer(configStore); }
public void InvalidUrl_throws() { var configStore = new DefaultConfigurationStore(); var configuration = new MutableConfiguration("facility"); configuration.Attributes.Add("type", typeof(SolrNetFacility).FullName); configuration.CreateChild("solrURL", "123"); configStore.AddFacilityConfiguration(typeof(SolrNetFacility).FullName, configuration); new WindsorContainer(configStore); }
private void AddComponent(string key, Type service, Type type, string factoryMethod) { var config = new MutableConfiguration(key); config.Attributes["factoryId"] = "factory"; config.Attributes["factoryCreate"] = factoryMethod; Container.Kernel.ConfigurationStore.AddComponentConfiguration(key, config); Container.Kernel.Register(Component.For(service).ImplementedBy(type).Named(key)); }
private ComponentModel AddComponent(string key, Type type, string factoryMethod) { MutableConfiguration config = new MutableConfiguration(key); config.Attributes["factoryId"] = "a"; config.Attributes["factoryCreate"] = factoryMethod; kernel.ConfigurationStore.AddComponentConfiguration(key, config); kernel.AddComponent(key, type); return kernel.GetHandler(key).ComponentModel; }
public void ShouldBeAbleToSupplyValueForNullableParamViaCtor_FromConfig() { var container = new WindsorContainer(); var configuration = new MutableConfiguration("parameters"); configuration.CreateChild("foo", "5"); container.Register(Component.For<ClassTakingNullableViaCtor>().Configuration(configuration)); container.Resolve<ClassTakingNullableViaCtor>(); }
private IConfiguration CreateModuleConfigurationNode() { var config = new MutableConfiguration("array"); foreach (Type type in messageModules) { config.CreateChild("item", "${" + type.FullName + "}"); } return config; }
protected void AddParameter(ComponentModel model, String name, IConfiguration value) { var parameters = EnsureParametersConfiguration(model); var parameter = new MutableConfiguration(name); parameter.Children.Add(value); parameters.Children.Add(parameter); }
private IConfiguration EnsureParametersConfiguration(ComponentModel model) { var parameters = model.Configuration.Children["parameters"]; if (parameters == null) { parameters = new MutableConfiguration("parameters"); model.Configuration.Children.Add(parameters); } return parameters; }
public void FACILITIES66() { container = new WindsorContainer(); IConfiguration confignode = new MutableConfiguration("facility"); confignode.Children.Add(new MutableConfiguration("arfacility")); container.Kernel.ConfigurationStore.AddFacilityConfiguration("arfacility", confignode); container.AddFacility("arfacility", new ActiveRecordFacility()); }
private IConfiguration GetSubscribersNode(IConfiguration configuration) { var node = configuration.Children["subscribers"]; if (node == null) { node = new MutableConfiguration("subscribers"); configuration.Children.Add(node); } return node; }
public void ParseEndpoints_reflects_entries() { var config = new MutableConfiguration("entries"); config.CreateChild("item").Attribute("assembly", "asm1").Attribute("endpoint", "end"); var reg = new RemoteEndpointRegistry(); reg.ParseEndpoints(config); Assert.AreEqual(1, reg.EntriesCount); }
public void setup() { var store = new DefaultConfigurationStore(); var solrSharpConfig = new MutableConfiguration("solrsharp"); solrSharpConfig.Children.Add(new MutableConfiguration("solrUrl", "http://localhost:8983/solr/")); solrSharpConfig.Children.Add(new MutableConfiguration("searcherMode", "ReadWrite")); store.AddFacilityConfiguration("solrsharp", solrSharpConfig); container = new WindsorContainer(store); container.AddFacility("solrsharp", new SolrSharpFacility()); }
public void ShouldBeAbleToSupplyValueForNullableParam_FromConfig() { var container = new WindsorContainer(); var configuration = new MutableConfiguration("parameters"); configuration.CreateChild("SomeVal", "5"); container.Register(Component.For<ClassTakingNullable>().Configuration(configuration)); var s = container.Resolve<ClassTakingNullable>(); Assert.IsNotNull(s.SomeVal); }
public void GlobalJobListeners_with_no_registration_throws() { var c = new WindsorContainer(); var config = new MutableConfiguration("facility"); config.CreateChild("quartz").CreateChild("item", "qwe").Attribute("key", "qq"); config.CreateChild("globalJobListeners").CreateChild("item", "${jobli}"); c.Kernel.ConfigurationStore.AddFacilityConfiguration("quartz", config); c.AddFacility("quartz", new QuartzFacility()); c.Resolve<IScheduler>(); }
public void Basic() { var c = new WindsorContainer(); var config = new MutableConfiguration("facility"); config.CreateChild("quartz").CreateChild("item", "qwe").Attribute("key", "qq"); c.Kernel.ConfigurationStore.AddFacilityConfiguration("quartz", config); c.AddFacility("quartz", new QuartzFacility()); c.Resolve<IJobScheduler>(); c.Resolve<IScheduler>(); }
public void CanReadNHConfigFileAsTheSourceOfSessionFactory() { IConfiguration castleConfiguration = new MutableConfiguration("myConfig"); castleConfiguration.Attributes["nhibernateConfigFile"] = @"Castle.Facilities.NHibernateIntegration.Tests/Issues/Facilities106/factory1.xml"; XmlConfigurationBuilder b = new XmlConfigurationBuilder(); NHibernate.Cfg.Configuration cfg = b.GetConfiguration(castleConfiguration); Assert.IsNotNull(cfg); string str = cfg.Properties["connection.provider"]; Assert.AreEqual("DummyProvider", str); }
public static IConfiguration CreateChild(IConfiguration parent, string name, string value) { IConfiguration config = new MutableConfiguration(name, value); if (parent != null) { parent.Children.Add(config); } return config; }
protected override IConfiguration GetRootConfiguration(IConfiguration root) { IConfiguration parameters = root.Children["parameters"]; if (parameters == null) { parameters = new MutableConfiguration("parameters"); root.Children.Add(parameters); } return parameters; }
private static IConfiguration ObtainSubscribers(IConfiguration config) { IConfiguration subscribers = config.Children["subscribers"]; if (subscribers == null) { subscribers = new MutableConfiguration("subscribers"); config.Children.Add(subscribers); } return subscribers; }