本文整理汇总了C#中Castle.Core.Configuration.MutableConfiguration类的典型用法代码示例。如果您正苦于以下问题:C# MutableConfiguration类的具体用法?C# MutableConfiguration怎么用?C# MutableConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MutableConfiguration类属于Castle.Core.Configuration命名空间,在下文中一共展示了MutableConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnsatisfiedConfigValues
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);
}
示例2: SetUp
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"));
}
示例3: TestComponentWithNoInterface
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);
}
示例4: ResolvingPrimitivesThroughProperties
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);
}
示例5: SetUp
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));
}
示例6: PopulateBusConfiguration
protected override void PopulateBusConfiguration(MutableConfiguration busConfig)
{
base.PopulateBusConfiguration(busConfig);
if (string.IsNullOrEmpty(Path) == false)
busConfig.Attribute("path", Path);
}
示例7: ComplexConfigurationParameter
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);
}
示例8: BuildContainer
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;
}
示例9: ConstructorWithArrayParameter
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]);
}
示例10: SimpleCase
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() );
}
示例11: InvalidProtocol_throws
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);
}
示例12: InvalidUrl_throws
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);
}
示例13: AddComponent
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));
}
示例14: AddComponent
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);
}
示例15: AddComponent
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;
}