本文整理汇总了C#中Ninject.StandardKernel.Scan方法的典型用法代码示例。如果您正苦于以下问题:C# StandardKernel.Scan方法的具体用法?C# StandardKernel.Scan怎么用?C# StandardKernel.Scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ninject.StandardKernel
的用法示例。
在下文中一共展示了StandardKernel.Scan方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanMakeBusinessProcessWithDefaultBindingGenerator
public void CanMakeBusinessProcessWithDefaultBindingGenerator()
{
IKernel kernel = new StandardKernel();
kernel.Scan(scanner =>
{
scanner.From(typeof(BusinessProcess).Assembly);
scanner.BindWith<DefaultBindingGenerator>();
});
BusinessProcess bp = kernel.Get<BusinessProcess>();
Assert.IsNotNull(bp);
}
示例2: CanMakeBusinessProcessWithServiceToInterfaceBinder
public void CanMakeBusinessProcessWithServiceToInterfaceBinder()
{
IKernel kernel = new StandardKernel();
kernel.Scan(scanner =>
{
scanner.From(typeof(BusinessProcess).Assembly);
scanner.BindWith<NinjectServiceToInterfaceBinder>();
});
BusinessProcess bp = kernel.Get<BusinessProcess>();
Assert.IsNotNull(bp);
}
示例3: CanGetAllValidators
public void CanGetAllValidators()
{
IKernel kernel = new StandardKernel();
kernel.Scan(scanner =>
{
scanner.From(typeof(IValidator).Assembly);
scanner.WhereTypeInheritsFrom<IValidator>();
scanner.BindWith<NinjectServiceToInterfaceBinder>();
});
var validators = kernel.GetAll<IValidator>();
Assert.IsNotNull(validators);
Assert.AreEqual(3, validators.Count());
}
示例4: CanFilterOutValidatorRegistrations
public void CanFilterOutValidatorRegistrations()
{
IKernel kernel = new StandardKernel();
kernel.Scan(scanner =>
{
scanner.From(typeof(IValidator).Assembly);
scanner.WhereTypeInheritsFrom<IValidator>();
// excluding the FailValidator should leave 2 of them
scanner.Where(t => t != typeof(FailValidator));
scanner.BindWith<NinjectServiceToInterfaceBinder>();
});
var validators = kernel.GetAll<IValidator>();
Assert.IsNotNull(validators);
Assert.AreEqual(2, validators.Count());
}
示例5: CanMakeSingletonInstance
public void CanMakeSingletonInstance()
{
IKernel kernel = new StandardKernel();
kernel.Scan(scanner =>
{
scanner.From(typeof(BusinessProcess).Assembly);
scanner.BindWith<NinjectServiceToInterfaceBinder>();
scanner.InSingletonScope();
});
BusinessProcess businessProcess1 = kernel.Get<BusinessProcess>();
BusinessProcess businessProcess2 = kernel.Get<BusinessProcess>();
Assert.AreSame(businessProcess1, businessProcess2);
}
示例6: CanMakeTransientInstanceWithSingletonDependenciesTwoScans
public void CanMakeTransientInstanceWithSingletonDependenciesTwoScans()
{
IKernel kernel = new StandardKernel();
// scan for types that are registered as singletons
kernel.Scan(scanner =>
{
scanner.From(typeof(BusinessProcess).Assembly);
scanner.Where(t => t != typeof(BusinessProcess));
scanner.BindWith<NinjectServiceToInterfaceBinder>();
scanner.InSingletonScope();
});
// scan for types that are registered as transient
kernel.Scan(scanner =>
{
scanner.From(typeof(BusinessProcess).Assembly);
scanner.Where(t => t == typeof(BusinessProcess));
scanner.BindWith<NinjectServiceToInterfaceBinder>();
scanner.InTransientScope();
});
BusinessProcess businessProcess1 = kernel.Get<BusinessProcess>();
BusinessProcess businessProcess2 = kernel.Get<BusinessProcess>();
Assert.AreNotSame(businessProcess1, businessProcess2);
Assert.AreSame(businessProcess1.CustomerService, businessProcess2.CustomerService);
Assert.AreSame(businessProcess1.OrderService, businessProcess2.OrderService);
}
示例7: CanMakeTransientInstanceWithSingletonDependencies
public void CanMakeTransientInstanceWithSingletonDependencies()
{
IKernel kernel = new StandardKernel();
kernel.Scan(scanner =>
{
scanner.From(typeof(BusinessProcess).Assembly);
// exclude the type 'BusinessProcess' from scanning and singleton
// NInject will auto-resolve it as transient
// I don't know how the reverse would be accomplished
scanner.Where(t => t != typeof(BusinessProcess));
scanner.BindWith<NinjectServiceToInterfaceBinder>();
scanner.InSingletonScope();
});
BusinessProcess businessProcess1 = kernel.Get<BusinessProcess>();
BusinessProcess businessProcess2 = kernel.Get<BusinessProcess>();
Assert.AreNotSame(businessProcess1, businessProcess2);
Assert.AreSame(businessProcess1.CustomerService, businessProcess2.CustomerService);
Assert.AreSame(businessProcess1.OrderService, businessProcess2.OrderService);
}
示例8: CreateKernel
private IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Scan(x => x.WhereTypeIsInNamespace("FabrikamWidgets.Core.Services"));
return kernel;
}