本文整理汇总了C#中Container.TryResolve方法的典型用法代码示例。如果您正苦于以下问题:C# Container.TryResolve方法的具体用法?C# Container.TryResolve怎么用?C# Container.TryResolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container.TryResolve方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryResolveReturnsNullIfNotRegistered
public void TryResolveReturnsNullIfNotRegistered()
{
var container = new Container();
Assert.IsNull(container.TryResolve<IFoo>());
Assert.IsNull(container.TryResolve<IFoo, string>("a1"));
Assert.IsNull(container.TryResolve<IFoo, string, string>("a1", "a2"));
Assert.IsNull(container.TryResolve<IFoo, string, string, string>("a1", "a2", "a3"));
Assert.IsNull(container.TryResolve<IFoo, string, string, string, string>("a1", "a2", "a3", "a4"));
Assert.IsNull(container.TryResolve<IFoo, string, string, string, string, string>("a1", "a2", "a3", "a4", "a5"));
Assert.IsNull(container.TryResolve<IFoo, string, string, string, string, string, string>("a1", "a2", "a3", "a4", "a5", "a6"));
}
示例2: TryResolveServiceWithTypeObject
public void TryResolveServiceWithTypeObject()
{
// Setup
var container = new Container();
container.Register<ServiceBase, ServiceWithNoConstructors>();
// Execute
object service;
var result = container.TryResolve(typeof (ServiceBase), out service);
// Assert
Assert.IsTrue(result);
Assert.IsTrue(service is ServiceWithNoConstructors);
}
示例3: TryResolveUnregisteredService
public void TryResolveUnregisteredService()
{
// Setup
var container = new Container();
// Execute
ServiceBase service;
var result = container.TryResolve(out service);
// Assert
Assert.IsFalse(result);
Assert.IsNull(service);
}
示例4: TryResolveServiceWithDependency
public void TryResolveServiceWithDependency()
{
// Setup
var container = new Container();
container.Register<DependencyBase, Dependency1>();
container.Register<ServiceBase, ServiceWithOneConstructor>();
// Execute
ServiceBase service;
var result = container.TryResolve<ServiceBase>(out service);
// Assert
Assert.IsTrue(result);
Assert.IsTrue(service is ServiceWithOneConstructor);
}
示例5: TryResolveServiceWithName
public void TryResolveServiceWithName()
{
// Setup
var container = new Container();
container.Register<ServiceBase, ServiceWithNoConstructors>("MyService");
// Execute
ServiceBase service;
var result = container.TryResolve(out service);
// Assert
Assert.IsTrue(result);
Assert.IsTrue(service is ServiceWithNoConstructors);
}
示例6: TryResolveServiceThatIsConstructableWithoutRegistration
public void TryResolveServiceThatIsConstructableWithoutRegistration()
{
// Setup
var container = new Container();
container.Register<DependencyBase, Dependency1>();
// Execute
ServiceWithOneConstructor service;
var result = container.TryResolve<ServiceWithOneConstructor>(out service);
// Assert
Assert.IsTrue(result);
Assert.IsTrue(service != null);
}
示例7: TryResolveFuncServiceWithName
public void TryResolveFuncServiceWithName()
{
// Setup
var container = new Container();
container.Register<ServiceBase>(() => new ServiceWithNoConstructors(), "MyService");
// Execute
object service;
var result = container.TryResolve(typeof (ServiceBase), "MyService", out service);
// Assert
Assert.IsTrue(result);
Assert.IsTrue(service is ServiceWithNoConstructors);
}
示例8: TryResolveFuncService
public void TryResolveFuncService()
{
// Setup
var container = new Container();
container.Register<ServiceBase>(() => new ServiceWithNoConstructors());
// Execute
ServiceBase service;
var result = container.TryResolve<ServiceBase>(out service);
// Assert
Assert.IsTrue(result);
Assert.IsInstanceOfType(service, typeof(ServiceWithNoConstructors));
}
示例9: TryResolveComplexService
public void TryResolveComplexService()
{
// Setup
var container = new Container();
container.Register<ComplexService1, ComplexService1>();
container.Register<ComplexService2, ComplexService2>();
container.Register<ComplexService3, ComplexService3>();
container.Register<DependencyBase, Dependency1>();
// Execute
ComplexService1 service;
var result = container.TryResolve<ComplexService1>(out service);
// Assert
Assert.IsTrue(result);
}
示例10: TryResolve
public void TryResolve()
{
// Setup
var container = new Container();
container.Register<ServiceBase, ServiceWithNoConstructors>();
// Execute
ServiceBase serviceBase;
bool result = container.TryResolve(out serviceBase);
// Assert
Assert.IsTrue(result);
Assert.IsInstanceOfType(serviceBase, typeof(ServiceWithNoConstructors));
}