本文整理汇总了C#中ObjectContainer.Create方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContainer.Create方法的具体用法?C# ObjectContainer.Create怎么用?C# ObjectContainer.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectContainer
的用法示例。
在下文中一共展示了ObjectContainer.Create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterSingletonObject
public void RegisterSingletonObject()
{
ObjectContainer locator = new ObjectContainer();
locator.RegisterSingleton<object>(c => { return new object(); });
var result = locator.Create<object>();
Assert.IsAssignableFrom<object>(result);
var result2 = locator.Create<object>();
Assert.AreSame(result, result2);
}
示例2: CreateSingletonObject
public void CreateSingletonObject()
{
ObjectContainer locator = new ObjectContainer();
locator.DeclareSingleton(typeof(object));
var result = locator.Create<object>();
Assert.IsAssignableFrom<object>(result);
var result2 = locator.Create<object>();
Assert.AreSame(result, result2);
}
示例3: ObjectContainer
public void RegisterReplacesPreviousRegistration
()
{
ObjectContainer locator = new ObjectContainer();
var log = new Mock<ILogger>();
locator.Register<ILogger>(c => { return log.Object; });
var log2 = new Mock<ILogger>();
locator.Register<ILogger>(c => { return log2.Object; });
var result = locator.Create<ILogger>();
Assert.AreSame(result,log2.Object);
}
示例4: CreateComplexObject
public void CreateComplexObject()
{
ObjectContainer locator = new ObjectContainer();
var dc = new Mock<IDirectoryController>();
var log = new Mock<ILoggerContainer>();
var log1 = new Mock<ILogger>();
var ml = new Mock<IModuleLoader>();
locator.Register<IDirectoryController>(c => { return dc.Object; });
locator.Register<ILoggerContainer>(c => { return log.Object; });
locator.Register<ILogger>(c => { return log1.Object; });
locator.Register<IModuleLoader>(c => { return ml.Object; });
var result = locator.Create<DefaultLoader>();
Assert.IsAssignableFrom<DefaultLoader>(result);
}
示例5: CreateSimpleObject
public void CreateSimpleObject()
{
ObjectContainer locator = new ObjectContainer();
var result = locator.Create<object>();
Assert.IsAssignableFrom<object>(result);
}