本文整理汇总了C#中Zenject.DiContainer.CreateSubContainer方法的典型用法代码示例。如果您正苦于以下问题:C# DiContainer.CreateSubContainer方法的具体用法?C# DiContainer.CreateSubContainer怎么用?C# DiContainer.CreateSubContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zenject.DiContainer
的用法示例。
在下文中一共展示了DiContainer.CreateSubContainer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLocal1
public void TestLocal1()
{
var rootContainer = new DiContainer();
var sub1 = rootContainer.CreateSubContainer();
rootContainer.Bind<Test0>().AsSingle();
sub1.Bind<Test1>().AsSingle();
Assert.Throws(() => sub1.Resolve<Test1>());
}
示例2: TestAny
public void TestAny()
{
var rootContainer = new DiContainer();
var sub1 = rootContainer.CreateSubContainer();
rootContainer.Bind<Test0>().AsSingle();
sub1.Bind<Test4>().AsSingle();
Assert.IsNotNull(sub1.Resolve<Test4>());
}
示例3: TestLocal1
public void TestLocal1()
{
var rootContainer = new DiContainer();
var sub1 = rootContainer.CreateSubContainer();
rootContainer.Bind<Test0>().ToSingle();
sub1.Bind<Test1>().ToSingle();
Assert.Throws<ZenjectResolveException>(() => sub1.Resolve<Test1>());
Assert.That(sub1.ValidateResolve<Test1>().Any());
}
示例4: Test1
public void Test1()
{
DiContainer parentContainer = new DiContainer();
parentContainer.Bind<Foo>().ToTransient();
// ToTransient should always use the DiContainer given by the inject context
var subContainer = parentContainer.CreateSubContainer();
subContainer.Bind<int>().ToInstance<int>(5);
var foo = subContainer.Resolve<Foo>();
Assert.AreEqual(foo.Value, 5);
}
示例5: RebindingInSubContainer
public void RebindingInSubContainer()
{
DiContainer parentContainer = new DiContainer();
parentContainer.Bind<IHaveMessage>().ToSingle<Welcome>();
Assert.AreEqual("Welcome", parentContainer.Resolve<IHaveMessage>().GetMessage());
DiContainer childContainer = parentContainer.CreateSubContainer();
childContainer.Rebind<IHaveMessage>().ToSingle<Bye>();
Assert.AreEqual("Bye", childContainer.Resolve<IHaveMessage>().GetMessage());
Assert.AreEqual("Welcome", parentContainer.Resolve<IHaveMessage>().GetMessage());
}
示例6: RebindingInSubContainer2
public void RebindingInSubContainer2()
{
DiContainer parentContainer = new DiContainer();
parentContainer.Bind<IHaveMessage>().ToSingle<Welcome>();
Assert.AreEqual("Welcome", parentContainer.Resolve<IHaveMessage>().GetMessage());
DiContainer childContainer = parentContainer.CreateSubContainer();
User user = new User();
childContainer.Inject(user);
Assert.AreEqual("Welcome", user.SayIt());
user.Rebind();
Assert.AreEqual("Bye", user.SayIt());
parentContainer.Inject(user);
Assert.AreEqual("Welcome", user.SayIt());
}
示例7: Construct
public void Construct(
DiContainer parentContainer,
[InjectOptional]
InstallerExtraArgs installerExtraArgs)
{
Assert.IsNull(_container);
_container = parentContainer.CreateSubContainer();
var componentInjecter = new InitialComponentsInjecter(
_container, GetInjectableComponents().ToList());
foreach (var component in componentInjecter.Components)
{
if (component is MonoKernel)
{
Assert.That(component == _kernel,
"Found MonoKernel derived class that is not hooked up to GameObjectContext. If you use MonoKernel, you must indicate this to GameObjectContext by dragging and dropping it to the Kernel field in the inspector");
}
}
_container.IsInstalling = true;
try
{
InstallBindings(installerExtraArgs, componentInjecter);
}
finally
{
_container.IsInstalling = false;
}
Log.Debug("GameObjectContext: Injecting into child components...");
componentInjecter.LazyInjectComponents();
Assert.That(_dependencyRoots.IsEmpty());
_dependencyRoots.AddRange(_container.ResolveDependencyRoots());
Log.Debug("GameObjectContext: Initialized successfully");
}
示例8: TestParent2
public void TestParent2()
{
var rootContainer = new DiContainer();
var sub1 = rootContainer.CreateSubContainer();
var sub2 = sub1.CreateSubContainer();
rootContainer.Bind<Test0>().AsSingle();
sub2.Bind<Test2>().AsSingle();
Assert.Throws(() => sub2.Resolve<Test2>());
}
示例9: TestLocal2
public void TestLocal2()
{
var rootContainer = new DiContainer();
var sub1 = rootContainer.CreateSubContainer();
sub1.Bind<Test0>().ToSingle();
sub1.Bind<Test1>().ToSingle();
Assert.IsNotNull(sub1.Resolve<Test1>());
Assert.That(sub1.ValidateResolve<Test1>().IsEmpty());
}
示例10: TestParentAny1
public void TestParentAny1()
{
var rootContainer = new DiContainer();
var sub1 = rootContainer.CreateSubContainer();
var sub2 = sub1.CreateSubContainer();
rootContainer.Bind<Test0>().ToSingle();
sub2.Bind<Test3>().ToSingle();
Assert.IsNotNull(sub2.Resolve<Test3>());
Assert.That(sub2.ValidateResolve<Test3>().IsEmpty());
}