本文整理汇总了C#中Container.LazyResolve方法的典型用法代码示例。如果您正苦于以下问题:C# Container.LazyResolve方法的具体用法?C# Container.LazyResolve怎么用?C# Container.LazyResolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container.LazyResolve方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LazyResolveThrowsIfNotRegistered
public void LazyResolveThrowsIfNotRegistered()
{
var container = new Container();
try
{
container.LazyResolve<IFoo>();
Assert.Fail("Should have failed to resolve the lazy func");
}
catch (ResolutionException)
{
}
try
{
container.LazyResolve<IFoo, string>();
Assert.Fail("Should have failed to resolve the lazy func");
}
catch (ResolutionException)
{
}
try
{
container.LazyResolve<IFoo, string, string>();
Assert.Fail("Should have failed to resolve the lazy func");
}
catch (ResolutionException)
{
}
try
{
container.LazyResolve<IFoo, string, string, string>();
Assert.Fail("Should have failed to resolve the lazy func");
}
catch (ResolutionException)
{
}
try
{
container.LazyResolve<IFoo, string, string, string, string>();
Assert.Fail("Should have failed to resolve the lazy func");
}
catch (ResolutionException)
{
}
try
{
container.LazyResolve<IFoo, string, string, string, string, string>();
Assert.Fail("Should have failed to resolve the lazy func");
}
catch (ResolutionException)
{
}
try
{
container.LazyResolve<IFoo, string, string, string, string, string, string>();
Assert.Fail("Should have failed to resolve the lazy func");
}
catch (ResolutionException)
{
}
}
示例2: LazyResolveHonorsReuseScope
public void LazyResolveHonorsReuseScope()
{
var container = new Container();
container.Register<IFoo>(c => new Foo()).ReusedWithin(ReuseScope.Container);
var func = container.LazyResolve<IFoo>();
var f1 = func();
var f2 = func();
Assert.AreSame(f1, f2);
}
示例3: LazyResolveProvidedForRegisteredServices
public void LazyResolveProvidedForRegisteredServices()
{
var container = new Container();
container.Register<IFoo>(c => new Foo()).ReusedWithin(ReuseScope.Container);
var func = container.LazyResolve<IFoo>();
Assert.IsNotNull(func);
}
示例4: LazyResolveAllOverloads
public void LazyResolveAllOverloads()
{
var container = new Container();
container.Register<Bar>(c => new Bar());
container.Register<Bar, string>((c, s) => new Bar(s));
container.Register<Bar, string, string>((c, s1, s2) => new Bar(s1, s2));
container.Register<Bar, string, string, string>((c, s1, s2, s3) => new Bar(s1, s2, s3));
container.Register<Bar, string, string, string, string>((c, s1, s2, s3, s4) => new Bar(s1, s2, s3, s4));
container.Register<Bar, string, string, string, string, string>((c, s1, s2, s3, s4, s5) => new Bar(s1, s2, s3, s4, s5));
container.Register<Bar, string, string, string, string, string, string>((c, s1, s2, s3, s4, s5, s6) => new Bar(s1, s2, s3, s4, s5, s6));
Assert.IsNotNull(container.Resolve<Bar>());
var b = container.LazyResolve<Bar, string>()("a1");
Assert.AreEqual("a1", b.Arg1);
b = container.LazyResolve<Bar, string, string>()("a1", "a2");
Assert.AreEqual("a1", b.Arg1);
Assert.AreEqual("a2", b.Arg2);
b = container.LazyResolve<Bar, string, string, string>()("a1", "a2", "a3");
Assert.AreEqual("a1", b.Arg1);
Assert.AreEqual("a2", b.Arg2);
Assert.AreEqual("a3", b.Arg3);
b = container.LazyResolve<Bar, string, string, string, string>()("a1", "a2", "a3", "a4");
Assert.AreEqual("a1", b.Arg1);
Assert.AreEqual("a2", b.Arg2);
Assert.AreEqual("a3", b.Arg3);
Assert.AreEqual("a4", b.Arg4);
b = container.LazyResolve<Bar, string, string, string, string, string>()("a1", "a2", "a3", "a4", "a5");
Assert.AreEqual("a1", b.Arg1);
Assert.AreEqual("a2", b.Arg2);
Assert.AreEqual("a3", b.Arg3);
Assert.AreEqual("a4", b.Arg4);
Assert.AreEqual("a5", b.Arg5);
b = container.LazyResolve<Bar, string, string, string, string, string, string>()("a1", "a2", "a3", "a4", "a5", "a6");
Assert.AreEqual("a1", b.Arg1);
Assert.AreEqual("a2", b.Arg2);
Assert.AreEqual("a3", b.Arg3);
Assert.AreEqual("a4", b.Arg4);
Assert.AreEqual("a5", b.Arg5);
Assert.AreEqual("a6", b.Arg6);
}