本文整理汇总了C#中Castle.MicroKernel.DefaultKernel类的典型用法代码示例。如果您正苦于以下问题:C# DefaultKernel类的具体用法?C# DefaultKernel怎么用?C# DefaultKernel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultKernel类属于Castle.MicroKernel命名空间,在下文中一共展示了DefaultKernel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: SimulateRegistration
public static ICollection<IHandler> SimulateRegistration(this IRegistration reg)
{
using (var kernel = new DefaultKernel()) {
kernel.Register(reg);
return kernel.GetAssignableHandlers(typeof (object));
}
}
示例3: MissingManifestResourceConfiguration
public void MissingManifestResourceConfiguration()
{
var store = new DefaultConfigurationStore();
var source = new AssemblyResource("assembly://Castle.Windsor.Tests/missing_config.xml");
IKernel kernel = new DefaultKernel();
new XmlInterpreter(source).ProcessResource(source, store, kernel);
}
示例4: ProperDeserialization
public void ProperDeserialization()
{
var store = new DefaultConfigurationStore();
var interpreter = new XmlInterpreter(new ConfigResource());
IKernel kernel = new DefaultKernel();
interpreter.ProcessResource(interpreter.Source, store, kernel);
Assert.AreEqual(2, store.GetFacilities().Length);
Assert.AreEqual(4, store.GetComponents().Length);
var config = store.GetFacilityConfiguration(typeof(NoopFacility).FullName);
var childItem = config.Children["item"];
Assert.IsNotNull(childItem);
Assert.AreEqual("value", childItem.Value);
config = store.GetFacilityConfiguration(typeof(Noop2Facility).FullName);
Assert.IsNotNull(config);
Assert.AreEqual("value within CDATA section", config.Value);
config = store.GetComponentConfiguration("testidcomponent1");
childItem = config.Children["item"];
Assert.IsNotNull(childItem);
Assert.AreEqual("value1", childItem.Value);
config = store.GetComponentConfiguration("testidcomponent2");
childItem = config.Children["item"];
Assert.IsNotNull(childItem);
Assert.AreEqual("value2", childItem.Value);
}
示例5: Starts_component_without_start_method
public void Starts_component_without_start_method()
{
ClassWithInstanceCount.InstancesCount = 0;
IKernel kernel = new DefaultKernel();
kernel.AddFacility<StartableFacility>(f => f.DeferredTryStart());
kernel.Register(Component.For<ClassWithInstanceCount>().Start());
Assert.AreEqual(1, ClassWithInstanceCount.InstancesCount);
}
示例6: current_property_exposes_the_correct_resolver
public void current_property_exposes_the_correct_resolver()
{
var kernel = new DefaultKernel();
var resolver = new CastleDependencyResolver(kernel);
GlobalHost.DependencyResolver = resolver;
Assert.That(CastleDependencyResolver.Current, Is.EqualTo(GlobalHost.DependencyResolver));
}
示例7: tt
public void tt()
{
var kernel = new DefaultKernel();
kernel.Register(AllTypes.Pick()
.FromAssembly(Assembly.GetExecutingAssembly())
.WithService.FirstInterface());
kernel.Resolve<ISomeInterface>();
}
示例8: get_service_returns_null_for_unregistered_service
public void get_service_returns_null_for_unregistered_service()
{
var kernel = new DefaultKernel();
var resolver = new CastleDependencyResolver(kernel);
var service = resolver.GetService(typeof(object));
Assert.That(service, Is.Null);
}
示例9: get_services_returns_empty_enumerable_for_unregistered_service
public void get_services_returns_empty_enumerable_for_unregistered_service()
{
var kernel = new DefaultKernel();
var resolver = new CastleDependencyResolver(kernel);
var services = resolver.GetServices(typeof(object));
Assert.That(services.Count(), Is.EqualTo(0));
}
示例10: Application_Start
protected void Application_Start(object sender, EventArgs e) {
var kernel = new DefaultKernel();
kernel.Register(Component.For<HttpContextBase>()
.LifeStyle.Transient
.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
kernel.Register(Component.For<SomeService>()
.LifeStyle.HybridPerWebRequestTransient());
kernel.Resolve<SomeService>();
}
示例11: Main
public static void Main(string[] args)
{
IKernel kernel = new DefaultKernel();
kernel.AddFacility("non.opt.props", new NonOptionalPropertiesFacility());
kernel.AddComponent("sql.connmng", typeof(SqlConnectionManager));
SqlConnectionManager connManager = (SqlConnectionManager) kernel["sql.connmng"];
}
示例12: AddChildKernelToTwoParentsThrowsException
public void AddChildKernelToTwoParentsThrowsException()
{
IKernel kernel2 = new DefaultKernel();
IKernel subkernel = new DefaultKernel();
Kernel.AddChildKernel(subkernel);
Assert.AreEqual(Kernel, subkernel.Parent);
kernel2.AddChildKernel(subkernel);
}
示例13: Kernel_should_select_ctor_with_available_dependencies
public void Kernel_should_select_ctor_with_available_dependencies()
{
var kernel = new DefaultKernel();
kernel.AddComponent<Service>();
kernel.AddComponent<ComponentX>();
kernel.AddComponent<ComponentY>();
var service = kernel.Resolve<Service>();
Assert.IsNull(service.A);
Assert.IsNotNull(service.X);
Assert.IsNotNull(service.Y);
}
示例14: Should_Dispose_From_Containers
public virtual void Should_Dispose_From_Containers()
{
DefaultKernel disposableKernel = new DefaultKernel();
using (var disposableLocater = new SiegeContainer(new WindsorAdapter.WindsorAdapter(disposableKernel)))
{
disposableLocater.Register(Given<ITestInterface>.Then<TestCase1>());
Assert.IsTrue(disposableLocater.GetInstance<ITestInterface>() is TestCase1);
}
Assert.IsFalse(disposableKernel.HasComponent(typeof(ITestInterface)));
}
示例15: get_services_returns_registered_service
public void get_services_returns_registered_service()
{
var kernel = new DefaultKernel();
kernel.Register(Component.For<object>().Instance(new object()));
var resolver = new CastleDependencyResolver(kernel);
var services = resolver.GetServices(typeof(object));
Assert.That(services.Count(), Is.EqualTo(1));
}