本文整理汇总了C#中Container.TryGetInstance方法的典型用法代码示例。如果您正苦于以下问题:C# Container.TryGetInstance方法的具体用法?C# Container.TryGetInstance怎么用?C# Container.TryGetInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container.TryGetInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: force_the_cached_miss_behavior
public void force_the_cached_miss_behavior()
{
var container = new Container();
container.TryGetInstance<IFancy>().ShouldBeNull();
container.TryGetInstance<IFancy>().ShouldBeNull();
container.TryGetInstance<IFancy>().ShouldBeNull();
container.TryGetInstance<IFancy>().ShouldBeNull();
container.TryGetInstance<IFancy>().ShouldBeNull();
}
示例2: miss_then_hit_after_configure_with_policy_change
public void miss_then_hit_after_configure_with_policy_change()
{
var container = new Container();
container.TryGetInstance<IFancy>().ShouldBeNull();
container.Configure(_ => _.Policies.OnMissingFamily<FancyFamily>());
container.TryGetInstance<IFancy>()
.ShouldBeOfType<Very>();
}
示例3: should_be_able_to_resolve_by_name
public void should_be_able_to_resolve_by_name()
{
var container = new Container(_ =>
{
_.For<ColorRule>().MissingNamedInstanceIs.ConstructedBy(c => new ColorRule(c.RequestedName));
});
container.GetInstance<ColorRule>("Red").Color.ShouldBe("Red");
container.TryGetInstance<ColorRule>("Red").Color.ShouldBe("Red");
container.TryGetInstance<ColorRule>("Blue").Color.ShouldBe("Blue");
container.TryGetInstance<ColorRule>("Green").Color.ShouldBe("Green");
}
示例4: miss_then_hit_after_configure_adds_it
public void miss_then_hit_after_configure_adds_it()
{
var container = new Container();
container.TryGetInstance<IFancy>().ShouldBeNull();
container.Configure(_ =>
{
_.For<IFancy>().Use(new NotReally());
});
container.TryGetInstance<IFancy>()
.ShouldBeOfType<NotReally>();
}
示例5: Repro
public void Repro()
{
var container = new Container(i => {
// Add our two registries. One is shared, the other is specific to this project.
// NOTE: Changing the order of these two will determine which GetInstance call fails.
i.AddRegistry<SharedRegistry>();
i.AddRegistry<MyRegistry>();
});
// One of these will, depending on the order of the two AddRegistry calls above.
container.TryGetInstance<IShared>().ShouldNotBeNull();
container.TryGetInstance<IMine>().ShouldNotBeNull();
}
示例6: Main
static void Main(string[] args)
{
//var container = new Container(x =>
// {
// x.Scan(o =>
// {
// o.TheCallingAssembly();
// o.ExcludeNamespace("HQF.Tutorial.IOC.Common");
// o.AddAllTypesOf<InterfaceA>();
// });
// });
// foreach (var instance in container.Model.InstancesOf<InterfaceA>())
// {
// Debug.WriteLine(instance.Name + " is " + instance.Name);
// Console.WriteLine(instance.Name,instance.PluginType);
// }
var container = new Container(
x =>
{
;
});
var a = container.TryGetInstance<InterfaceA>();
var myClass=new MyClass(a);
myClass.CallPrint();
Console.Read();
}
示例7: Given_structuremap_when_printWhatDoIHave_then_shouldReturnWhatDoIHave
public void Given_structuremap_when_printWhatDoIHave_then_shouldReturnWhatDoIHave()
{
var container = new Container(new Registering());
var printerInstance = container.TryGetInstance<ITypeOfPrinter>();
string blackAndWhitePrintText = printerInstance.Printing();
Assert.Pass(container.WhatDoIHave());
}
示例8: Given_structuremapWithTryGetInstance_when_print_then_shouldReturnAppropriateTypes
public void Given_structuremapWithTryGetInstance_when_print_then_shouldReturnAppropriateTypes()
{
var container = new Container(new Registering());
var printerInstance = container.TryGetInstance<ITypeOfPrinter>();
string blackAndWhitePrintText = printerInstance.Printing();
Assert.Pass(blackAndWhitePrintText);
}
示例9: should_not_add_null_instance
public void should_not_add_null_instance()
{
var container = new Container(x => x.For<ITest>().Use<Test>());
container.Model.Pipeline.Instances.GetAllInstances().Any(i => i == null).ShouldBeFalse();
container.TryGetInstance<ITest>("test").ShouldBeNull();
container.Model.Pipeline.Instances.GetAllInstances().Any(i => i == null).ShouldBeFalse();
}
开发者ID:khellang,项目名称:structuremap,代码行数:8,代码来源:Bug_251_do_not_add_null_values_to_plugin_family_instance_cache.cs
示例10: TryGetInstance_ServiceTypeRegistered_ReturnsInstanceOfExpectedType
public void TryGetInstance_ServiceTypeRegistered_ReturnsInstanceOfExpectedType()
{
// Arrange
var container = new Container();
container.RegisterSingleton<ICommand>(new ConcreteCommand());
// Act
object command;
container.TryGetInstance(typeof(ICommand), out command);
// Assert
AssertThat.IsInstanceOfType(typeof(ConcreteCommand), command);
}
示例11: TryGetInstance_ServiceTypeNotRegistered_ReturnsNull
public void TryGetInstance_ServiceTypeNotRegistered_ReturnsNull()
{
// Arrange
var container = new Container();
// Act
object command;
container.TryGetInstance(typeof(ICommand), out command);
// Assert
Assert.IsNull(command, "TryGetInstance is expected to return null when the type is not registered.");
}
示例12: TryGetInstance_ServiceTypeRegistered_ReturnsInstance
public void TryGetInstance_ServiceTypeRegistered_ReturnsInstance()
{
// Arrange
var container = new Container();
container.RegisterSingleton<ICommand>(new ConcreteCommand());
// Act
object command;
container.TryGetInstance(typeof(ICommand), out command);
// Assert
Assert.IsNotNull(command, "TryGetInstance is expected to return an instance when the type is registered.");
}
示例13: TryGetInstanceOfT_ServiceTypeNotRegistered_ReturnsFalse
public void TryGetInstanceOfT_ServiceTypeNotRegistered_ReturnsFalse()
{
// Arrange
var container = new Container();
// Act
ICommand command;
bool found = container.TryGetInstance<ICommand>(out command);
// Assert
Assert.IsFalse(found, "TryGetInstance<T> is expected to return false when the type is not registered.");
}
示例14: TryGetInstanceOfT_ServiceTypeRegistered_ReturnsTrue
public void TryGetInstanceOfT_ServiceTypeRegistered_ReturnsTrue()
{
// Arrange
var container = new Container();
container.RegisterSingleton<ICommand>(new ConcreteCommand());
// Act
ICommand command;
bool found = container.TryGetInstance<ICommand>(out command);
// Assert
Assert.IsTrue(found, "TryGetInstance<T> is expected to return true when the type is registered.");
}
示例15: complete_miss
public void complete_miss()
{
var container = new Container();
container.TryGetInstance<IFancy>()
.ShouldBeNull();
}