本文整理汇总了C#中Container.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Container.Create方法的具体用法?C# Container.Create怎么用?C# Container.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container.Create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Dependency
public void Dependency()
{
var container = new Container();
container.Bind<IRepository>().To<ConcreteRepository>();
container.Bind<IService>().To<ConcreteService>();
Assert.That(container.Create<IService>(), Is.TypeOf<ConcreteService>());
}
示例2: CanCreateInstanceOfConcreteTypeFromInterfaceWhenNotConfiguredIfOnlyOneImplementationExists
public void CanCreateInstanceOfConcreteTypeFromInterfaceWhenNotConfiguredIfOnlyOneImplementationExists() {
var container = new Container();
var inst = container.Create<ISomeInterface>();
Assert.IsNotNull(inst);
Assert.IsInstanceOfType(inst, typeof(SomeClass));
}
示例3: BindTo
public void BindTo()
{
var container = new Container();
container.Bind<IRepository>().To<ConcreteRepository>();
Assert.That(container.Create<IRepository>(), Is.TypeOf<ConcreteRepository>());
}
示例4: CanCreateInstanceOfConcreteType
public void CanCreateInstanceOfConcreteType() {
var container = new Container();
var inst = container.Create<SomeClass>();
Assert.IsNotNull(inst);
Assert.IsInstanceOfType(inst, typeof(SomeClass));
}
示例5: Register
public void Register()
{
var container = new Container();
container.Register<IRepository>(() => new ConcreteRepository());
Assert.That(container.Create<IRepository>(), Is.TypeOf<ConcreteRepository>());
}
示例6: CanCreateInstanceOfConcreteTypeFromInterface
public void CanCreateInstanceOfConcreteTypeFromInterface() {
var container = new Container();
container.Configure<ISomeInterface>().ToUse(typeof(SomeClass));
var inst = container.Create<ISomeInterface>();
Assert.IsNotNull(inst);
Assert.IsInstanceOfType(inst, typeof(SomeClass));
}
示例7: Main
private static void Main(string[] args)
{
if (args.Length == 0)
{
args = new[] { "10", "+", "20", "-", "30", "+", "1" };
}
var container = new Container();
var calculator = (ICalculator)container.Create("ICalculator");
int result = calculator.Evaluate(args);
Console.WriteLine(result);
}
示例8: CanCreateInstanceUsingConstructorInjection
public void CanCreateInstanceUsingConstructorInjection() {
var container = new Container();
var A = container.Create<A>();
Assert.IsNotNull(A);
Assert.IsNotNull(A.B);
Assert.IsNotNull(A.B.C);
}
示例9: ThrowsExceptionWhenNotConfiguredAndMoreThanOneImplementationExists
public void ThrowsExceptionWhenNotConfiguredAndMoreThanOneImplementationExists() {
var container = new Container();
var inst = container.Create<IManyInterface>();
}
示例10: ThrowsExceptionWhenNotConfiguredAndNoImplementationsExists
public void ThrowsExceptionWhenNotConfiguredAndNoImplementationsExists() {
var container = new Container();
var inst = container.Create<INoneInterface>();
}