本文整理汇总了C#中Castle.MicroKernel.DefaultKernel.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultKernel.Resolve方法的具体用法?C# DefaultKernel.Resolve怎么用?C# DefaultKernel.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Castle.MicroKernel.DefaultKernel
的用法示例。
在下文中一共展示了DefaultKernel.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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>();
}
示例2: tt
public void tt()
{
var kernel = new DefaultKernel();
kernel.Register(AllTypes.Pick()
.FromAssembly(Assembly.GetExecutingAssembly())
.WithService.FirstInterface());
kernel.Resolve<ISomeInterface>();
}
示例3: 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);
}
示例4: DoesNotResolveArraysByDefault
public void DoesNotResolveArraysByDefault()
{
var kernel = new DefaultKernel();
kernel.Register(
Component.For<Thing>(),
Component.For<ISubThing>().ImplementedBy<First>(),
Component.For<ISubThing>().ImplementedBy<Second>(),
Component.For<ISubThing>().ImplementedBy<Third>()
);
var thing = kernel.Resolve<Thing>();
}
示例5: SetUp
public void SetUp()
{
kernel = new DefaultKernel();
kernel.AddFacility<StartableFacility>();
kernel.Register(
Component.For<StartableDisposableAndInitializableComponent>()
.LifeStyle.Transient
);
component = kernel.Resolve<StartableDisposableAndInitializableComponent>();
component.DoSomething();
kernel.ReleaseComponent(component);
calledMethods = component.calledMethods;
}
示例6: ShouldResolveArrayOfDependencies
public void ShouldResolveArrayOfDependencies()
{
var kernel = new DefaultKernel();
kernel.Resolver.AddSubResolver(new ArrayResolver(kernel));
kernel.Register(
Component.For<Thing>(),
Component.For<ISubThing>().ImplementedBy<First>(),
Component.For<ISubThing>().ImplementedBy<Second>(),
Component.For<ISubThing>().ImplementedBy<Third>()
);
var thing = kernel.Resolve<Thing>();
Assert.That(thing.SubThings.Count, Is.EqualTo(3));
Assert.That(thing.SubThings[0], Is.InstanceOf(typeof(First)));
Assert.That(thing.SubThings[1], Is.InstanceOf(typeof(Second)));
Assert.That(thing.SubThings[2], Is.InstanceOf(typeof(Third)));
}
示例7: Three_level_hierarchy
public void Three_level_hierarchy([Values(0, 1, 2)] int parentComponentContainer,
[Values(0, 1, 2)] int childComponentContainer)
{
var subKernel = new DefaultKernel();
var subSubKernel = new DefaultKernel();
Kernel.AddChildKernel(subKernel);
subKernel.AddChildKernel(subSubKernel);
var containers = new[]
{
Kernel,
subKernel,
subSubKernel
};
containers[parentComponentContainer].Register(Component.For<UsesSimpleComponent1>());
containers[childComponentContainer].Register(Component.For<SimpleComponent1>());
subSubKernel.Resolve<UsesSimpleComponent1>();
}
示例8: Parent_component_will_NOT_have_dependencies_from_child
public void Parent_component_will_NOT_have_dependencies_from_child()
{
Kernel.Register(Component.For<DefaultTemplateEngine>(),
Component.For<DefaultSpamService>());
var child = new DefaultKernel();
Kernel.AddChildKernel(child);
child.Register(Component.For<DefaultMailSenderService>());
var spamservice = child.Resolve<DefaultSpamService>();
Assert.IsNotNull(spamservice);
Assert.IsNotNull(spamservice.TemplateEngine);
Assert.IsNull(spamservice.MailSender);
}
示例9: Singleton_withNonSingletonDependencies_doesNotReResolveDependencies
public void Singleton_withNonSingletonDependencies_doesNotReResolveDependencies()
{
Kernel.Register(Component.For(typeof(DefaultSpamService)).Named("spamservice"));
Kernel.Register(Component.For(typeof(DefaultMailSenderService)).Named("mailsender"));
var subkernel1 = new DefaultKernel();
subkernel1.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine"));
Kernel.AddChildKernel(subkernel1);
var subkernel2 = new DefaultKernel();
subkernel2.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine")
.LifeStyle.Is(LifestyleType.Transient));
Kernel.AddChildKernel(subkernel2);
var templateengine1 = subkernel1.Resolve<DefaultTemplateEngine>("templateengine");
var spamservice1 = subkernel1.Resolve<DefaultSpamService>("spamservice");
Assert.IsNull(spamservice1.TemplateEngine);
var templateengine2 = subkernel2.Resolve<DefaultTemplateEngine>("templateengine");
var spamservice2 = subkernel2.Resolve<DefaultSpamService>("spamservice");
Assert.AreSame(spamservice1, spamservice2);
}
示例10: DependenciesSatisfiedAmongContainersUsingEvents
public void DependenciesSatisfiedAmongContainersUsingEvents()
{
IKernel subkernel = new DefaultKernel();
subkernel.Register(Component.For(typeof(DefaultSpamServiceWithConstructor)).Named("spamservice"));
Kernel.Register(Component.For(typeof(DefaultMailSenderService)).Named("mailsender"));
Kernel.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine"));
Kernel.AddChildKernel(subkernel);
var spamservice =
subkernel.Resolve<DefaultSpamServiceWithConstructor>("spamservice");
Assert.IsNotNull(spamservice);
Assert.IsNotNull(spamservice.MailSender);
Assert.IsNotNull(spamservice.TemplateEngine);
}
示例11: Requesting_parent_component_with_child_dependency_from_child_component
public void Requesting_parent_component_with_child_dependency_from_child_component()
{
var subkernel = new DefaultKernel();
Kernel.AddChildKernel(subkernel);
Kernel.Register(Component.For<UsesSimpleComponent1>());
subkernel.Register(Component.For<SimpleComponent1>());
subkernel.Resolve<UsesSimpleComponent1>();
}
示例12: TestStartableCustomDependencies
public void TestStartableCustomDependencies()
{
IKernel kernel = new DefaultKernel();
kernel.ComponentCreated += OnStartableComponentStarted;
kernel.AddFacility("startable", new StartableFacility());
kernel.Register(
Component.For<StartableComponentCustomDependencies>()
.Named("a")
.DependsOn(Property.ForKey("config").Eq(1))
);
Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");
var component = kernel.Resolve<StartableComponentCustomDependencies>("a");
Assert.IsNotNull(component);
Assert.IsTrue(component.Started);
Assert.IsFalse(component.Stopped);
kernel.ReleaseComponent(component);
Assert.IsTrue(component.Stopped);
}
示例13: ChildKernelOverloadsParentKernel2
public void ChildKernelOverloadsParentKernel2()
{
var instance1 = new DefaultTemplateEngine();
var instance2 = new DefaultTemplateEngine();
IKernel subkernel = new DefaultKernel();
Kernel.AddChildKernel(subkernel);
// subkernel added first, then populated with overloaded components after
Kernel.Register(Component.For<DefaultTemplateEngine>().Named("engine").Instance(instance2));
Assert.AreEqual(instance2, Kernel.Resolve<DefaultTemplateEngine>("engine"));
Assert.AreEqual(instance2, subkernel.Resolve<DefaultTemplateEngine>("engine"));
subkernel.Register(Component.For<DefaultTemplateEngine>().Named("engine").Instance(instance1));
Assert.AreEqual(instance1, subkernel.Resolve<DefaultTemplateEngine>("engine"));
Assert.AreEqual(instance2, Kernel.Resolve<DefaultTemplateEngine>("engine"));
}
示例14: TestStartableWithRegisteredCustomDependencies
public void TestStartableWithRegisteredCustomDependencies()
{
IKernel kernel = new DefaultKernel();
kernel.ComponentCreated += OnStartableComponentStarted;
kernel.AddFacility("startable", new StartableFacility());
var dependencies = new Dictionary<string, object> { { "config", 1 } };
kernel.Register(Component.For(typeof(StartableComponentCustomDependencies)).Named("a"));
kernel.RegisterCustomDependencies(typeof(StartableComponentCustomDependencies), dependencies);
Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");
var component = kernel.Resolve<StartableComponentCustomDependencies>("a");
Assert.IsNotNull(component);
Assert.IsTrue(component.Started);
Assert.IsFalse(component.Stopped);
kernel.ReleaseComponent(component);
Assert.IsTrue(component.Stopped);
}
示例15: Do_NOT_UseChildComponentsForParentDependenciesWhenRequestedFromChild
public void Do_NOT_UseChildComponentsForParentDependenciesWhenRequestedFromChild()
{
IKernel subkernel = new DefaultKernel();
Kernel.Register(Component.For(typeof(DefaultSpamService)).Named("spamservice").LifeStyle.Is(LifestyleType.Transient));
Kernel.Register(Component.For(typeof(DefaultMailSenderService)).Named("mailsender"));
Kernel.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine"));
Kernel.AddChildKernel(subkernel);
subkernel.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine"));
var templateengine = Kernel.Resolve<DefaultTemplateEngine>("templateengine");
var sub_templateengine = subkernel.Resolve<DefaultTemplateEngine>("templateengine");
var spamservice = subkernel.Resolve<DefaultSpamService>("spamservice");
Assert.AreNotEqual(spamservice.TemplateEngine, sub_templateengine);
Assert.AreEqual(spamservice.TemplateEngine, templateengine);
spamservice = Kernel.Resolve<DefaultSpamService>("spamservice");
Assert.AreNotEqual(spamservice.TemplateEngine, sub_templateengine);
Assert.AreEqual(spamservice.TemplateEngine, templateengine);
}