本文整理匯總了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());
}