本文整理汇总了C#中DefaultKernel.GetHandler方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultKernel.GetHandler方法的具体用法?C# DefaultKernel.GetHandler怎么用?C# DefaultKernel.GetHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DefaultKernel
的用法示例。
在下文中一共展示了DefaultKernel.GetHandler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddingDependencyToServiceWithCustomDependency
public void AddingDependencyToServiceWithCustomDependency()
{
var k = new DefaultKernel();
((IKernel)k).Register(Component.For(typeof(NeedClassWithCustomerDependency)).Named("NeedClassWithCustomerDependency"));
((IKernel)k).Register(Component.For(typeof(HasCustomDependency)).Named("HasCustomDependency"));
Assert.AreEqual(HandlerState.WaitingDependency, k.GetHandler("HasCustomDependency").CurrentState);
var hash = new Dictionary<object, object>();
hash["name"] = new CompA();
k.RegisterCustomDependencies("HasCustomDependency", hash);
Assert.AreEqual(HandlerState.Valid, k.GetHandler("HasCustomDependency").CurrentState);
Assert.IsNotNull(k.Resolve(typeof(NeedClassWithCustomerDependency)));
}
示例2: AddingDependencyToServiceWithCustomDependency
public void AddingDependencyToServiceWithCustomDependency()
{
var kernel = new DefaultKernel();
kernel.Register(Component.For<NeedClassWithCustomerDependency>(),
Component.For<HasCustomDependency>().DependsOn(new Dictionary<object, object> { { "name", new CompA() } }));
Assert.AreEqual(HandlerState.Valid, kernel.GetHandler(typeof(HasCustomDependency)).CurrentState);
Assert.IsNotNull(kernel.Resolve(typeof(NeedClassWithCustomerDependency)));
}
示例3: WillAskResolverWhenTryingToResolveDependencyAfterAnotherHandlerWasRegistered
public void WillAskResolverWhenTryingToResolveDependencyAfterAnotherHandlerWasRegistered()
{
FooBarResolver resolver = new FooBarResolver();
IKernel kernel = new DefaultKernel();
kernel.Resolver.AddSubResolver(resolver);
kernel.AddComponent("foo", typeof(Foo));
IHandler handler = kernel.GetHandler("foo");
Assert.AreEqual(HandlerState.WaitingDependency, handler.CurrentState);
resolver.Result = 15;
kernel.RaiseHandlerRegistered(null);//should force reevaluation of state
Assert.AreEqual(HandlerState.Valid, handler.CurrentState);
}
示例4: WillAskResolverWhenTryingToResolveDependencyAfterAnotherHandlerWasRegistered
public void WillAskResolverWhenTryingToResolveDependencyAfterAnotherHandlerWasRegistered()
{
var resolver = new FooBarResolver();
IKernel kernel = new DefaultKernel();
kernel.Resolver.AddSubResolver(resolver);
kernel.Register(Component.For<Foo>());
var handler = kernel.GetHandler(typeof(Foo));
Assert.AreEqual(HandlerState.WaitingDependency, handler.CurrentState);
resolver.Result = 15;
kernel.Register(Component.For<A>());
Assert.AreEqual(HandlerState.Valid, handler.CurrentState);
}
示例5: AddingDependencyToServiceWithCustomDependency
public void AddingDependencyToServiceWithCustomDependency()
{
DefaultKernel k = new DefaultKernel();
k.AddComponent("NeedClassWithCustomerDependency",typeof(NeedClassWithCustomerDependency));
k.AddComponent("HasCustomDependency", typeof(HasCustomDependency));
Assert.AreEqual(HandlerState.WaitingDependency, k.GetHandler("HasCustomDependency").CurrentState);
Hashtable hash = new Hashtable();
hash["name"] = new CompA();
k.RegisterCustomDependencies("HasCustomDependency", hash);
Assert.AreEqual(HandlerState.Valid, k.GetHandler("HasCustomDependency").CurrentState);
Assert.IsNotNull(k.Resolve(typeof(NeedClassWithCustomerDependency)));
}