本文整理汇总了C#中ServiceContainer.Get方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.Get方法的具体用法?C# ServiceContainer.Get怎么用?C# ServiceContainer.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: The_container_should_allways_return_the_same_instance_if_request_multiple_times
public void The_container_should_allways_return_the_same_instance_if_request_multiple_times()
{
var serviceContainer = new ServiceContainer();
serviceContainer.RegisterService<ITestService, TestService>();
var instance1 = serviceContainer.Get<ITestService>();
var instance2 = serviceContainer.Get<ITestService>();
Assert.AreSame(instance1, instance2);
}
示例2: Collections_should_be_resolved_in_the_registered_order
public void Collections_should_be_resolved_in_the_registered_order()
{
var serviceContainer = new ServiceContainer();
serviceContainer.RegisterCollection<ITestCollectionItem>(new[]
{
typeof(TestCollectionItem1),
typeof(TestCollectionItem2)
});
var list = serviceContainer.Get<ITestCollectionItem[]>();
Assert.IsInstanceOf<TestCollectionItem1>(list[0]);
Assert.IsInstanceOf<TestCollectionItem2>(list[1]);
}
示例3: A_service_should_be_resolveable
public void A_service_should_be_resolveable()
{
var serviceContainer = new ServiceContainer();
serviceContainer.RegisterService<ITestService, TestService>();
Assert.IsNotNull(serviceContainer.Get<ITestService>());
}