本文整理汇总了C#中Box.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# Box.Resolve方法的具体用法?C# Box.Resolve怎么用?C# Box.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box
的用法示例。
在下文中一共展示了Box.Resolve方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewPerResolveLifeStyleTestByClass
public void NewPerResolveLifeStyleTestByClass()
{
var box = new Box();
box.Register<NoDependenciesClass>(LifeStyle.NewPerResolve);
var obj1 = box.Resolve<NoDependenciesClass>();
var obj2 = box.Resolve<NoDependenciesClass>();
Assert.That(ReferenceEquals(obj1, obj2), Is.False);
}
示例2: DefaultLifeStyleIsSingleForContainerByInterface
public void DefaultLifeStyleIsSingleForContainerByInterface()
{
var box = new Box();
box.Register<ISomething, Something>();
var obj1 = box.Resolve<ISomething>();
var obj2 = box.Resolve<ISomething>();
Assert.That(ReferenceEquals(obj1, obj2), Is.True);
}
示例3: DefaultLifeStyleIsSingleForContainerByClass
public void DefaultLifeStyleIsSingleForContainerByClass()
{
var box = new Box();
box.Register<NoDependenciesClass>();
var obj1 = box.Resolve<NoDependenciesClass>();
var obj2 = box.Resolve<NoDependenciesClass>();
Assert.That(ReferenceEquals(obj1, obj2), Is.True);
}
示例4: DifferentLifeStylesTestByInterface
public void DifferentLifeStylesTestByInterface()
{
var box = new Box();
box.Register<FirstDependencyClass>();
box.Register<ISomethingWithDependency, SomethingWithDependency>(LifeStyle.NewPerResolve);
box.Register<ISomething, Something>(LifeStyle.SingleForContainer);
var obj11 = box.Resolve<ISomethingWithDependency>();
var obj12 = box.Resolve<ISomethingWithDependency>();
Assert.That(ReferenceEquals(obj11, obj12), Is.False);
var obj21 = box.Resolve<ISomething>();
var obj22 = box.Resolve<ISomething>();
Assert.That(ReferenceEquals(obj21, obj22), Is.True);
}
示例5: DifferentLifeStylesTestByClass
public void DifferentLifeStylesTestByClass()
{
var box = new Box();
box.Register<NoDependenciesClass>(LifeStyle.NewPerResolve);
box.Register<FirstDependencyClass>(LifeStyle.SingleForContainer);
box.Register<OneDependencyClass>(LifeStyle.SingleForContainer);
var obj11 = box.Resolve<NoDependenciesClass>();
var obj12 = box.Resolve<NoDependenciesClass>();
Assert.That(ReferenceEquals(obj11, obj12), Is.False);
var obj21 = box.Resolve<OneDependencyClass>();
var obj22 = box.Resolve<OneDependencyClass>();
Assert.That(ReferenceEquals(obj21, obj22), Is.True);
}
示例6: CanResolveByInterface
public void CanResolveByInterface()
{
var box = new Box();
box.Register<ISomething, Something>();
var resolvedObject = box.Resolve<ISomething>();
Assert.That(resolvedObject, Is.Not.Null);
}
示例7: CanResolveByClass
public void CanResolveByClass()
{
var box = new Box();
box.Register<NoDependenciesClass>();
var resolvedObj = box.Resolve<NoDependenciesClass>();
Assert.That(resolvedObj, Is.Not.Null);
}
示例8: CanResolveClassWithOneDependencyByInterface
public void CanResolveClassWithOneDependencyByInterface()
{
var box = new Box();
box.Register<FirstDependencyClass>();
box.Register<ISomethingWithDependency, SomethingWithDependency>();
var obj = box.Resolve<ISomethingWithDependency>();
Assert.That(obj, Is.Not.Null);
Assert.That(obj.FirstDependency, Is.Not.Null);
}
示例9: CanResolveClassWithOneDependency
public void CanResolveClassWithOneDependency()
{
var box = new Box();
box.Register<FirstDependencyClass>();
box.Register<OneDependencyClass>();
var obj = box.Resolve<OneDependencyClass>();
Assert.That(obj, Is.Not.Null);
Assert.That(obj.FirstDependency, Is.Not.Null);
}
示例10: CanResolveClassWithTwoDependencyLevels
public void CanResolveClassWithTwoDependencyLevels()
{
var box = new Box();
box.Register<TopLevelClass>();
box.Register<FirstLevelDependency>();
box.Register<SecondLevelDependency>();
var obj = box.Resolve<TopLevelClass>();
Assert.That(obj, Is.Not.Null);
Assert.That(obj.FirstLevelDependency, Is.Not.Null);
Assert.That(obj.FirstLevelDependency.SecondLevelDependency, Is.Not.Null);
}
示例11: ResolvingOfNotRegisteredClassThrowsException
public void ResolvingOfNotRegisteredClassThrowsException()
{
var box = new Box();
Assert.That(() => box.Resolve<NoDependenciesClass>(), Throws.InstanceOf<TypeNotFoundException>());
}
示例12: ResolvingByClassIfRegisteredByInterfaceThrowsException
public void ResolvingByClassIfRegisteredByInterfaceThrowsException()
{
var box = new Box();
box.Register<ISomething, Something>();
Assert.That(() => box.Resolve<Something>(), Throws.InstanceOf<TypeNotFoundException>());
}
示例13: NewPerResolveLifeStyleTestByInterface
public void NewPerResolveLifeStyleTestByInterface()
{
var box = new Box();
box.Register<ISomething, Something>(LifeStyle.NewPerResolve);
var obj1 = box.Resolve<ISomething>();
var obj2 = box.Resolve<ISomething>();
Assert.That(ReferenceEquals(obj1, obj2), Is.False);
}