本文整理汇总了C#中SimpleContainer.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# SimpleContainer.Resolve方法的具体用法?C# SimpleContainer.Resolve怎么用?C# SimpleContainer.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleContainer
的用法示例。
在下文中一共展示了SimpleContainer.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveConcreteTypeDefault
public void ResolveConcreteTypeDefault()
{
var container = new SimpleContainer();
var instance = container.Resolve<ConcreteType>();
Assert.IsNotNull(instance);
Assert.AreNotSame(container.Resolve<ConcreteType>(), instance);
}
示例2: ResolveConcreteTypeTransient
public void ResolveConcreteTypeTransient()
{
var container = new SimpleContainer();
container.RegisterType<ConcreteType>(false);
var instance = container.Resolve<ConcreteType>();
Assert.AreNotSame(container.Resolve<ConcreteType>(), instance);
}
示例3: ResolveConcreteTypeSingleton
public void ResolveConcreteTypeSingleton()
{
var container = new SimpleContainer();
container.RegisterType<ConcreteType>();
var instance = container.Resolve<ConcreteType>();
Assert.AreSame(container.Resolve<ConcreteType>(), instance);
}
示例4: DefaultSingletonCreation
public void DefaultSingletonCreation()
{
var container = new SimpleContainer();
container.RegisterType<ITypeToResolve, ConcreteType>();
var instance = container.Resolve<ITypeToResolve>();
Assert.AreSame(container.Resolve<ITypeToResolve>(), instance);
}
示例5: NoResolvableConstructor
public void NoResolvableConstructor()
{
var c = new SimpleContainer();
// wyjątek, string nie ma konstruktora bezparametrowego i nie da się rozwikłać żadnego z konstruktorów
c.Resolve<ConcreteWithStringParam>();
}
示例6: CyclicDependencySimple
public void CyclicDependencySimple()
{
var c = new SimpleContainer();
c.RegisterType<ITypeToResolve, ConcreteWithSimpleCyclicDependency>();
c.Resolve<ITypeToResolve>();
}
示例7: ResolvableSecondConstructor
public void ResolvableSecondConstructor()
{
var c = new SimpleContainer();
c.RegisterType<ITypeToResolve, ConcreteType>();
var instance = c.Resolve<ConcreteWithResolvableSecondConstructor>();
Assert.IsNotNull(instance.Arg1);
}
示例8: RegisterInstance
public void RegisterInstance()
{
var c = new SimpleContainer();
var foo1 = new ConcreteType();
c.RegisterInstance<ITypeToResolve>(foo1);
var foo2 = c.Resolve<ITypeToResolve>();
Assert.AreSame(foo1, foo2);
}
示例9: ResolveObjectWithInterface
public void ResolveObjectWithInterface()
{
var container = new SimpleContainer();
container.RegisterType<ITypeToResolve, ConcreteType>();
var instance = container.Resolve<ITypeToResolve>();
Assert.IsInstanceOfType(instance, typeof(ConcreteType));
}
示例10: ResolveObjectWithConstructorParams
public void ResolveObjectWithConstructorParams()
{
var container = new SimpleContainer();
container.RegisterType<ITypeToResolve, ConcreteType>();
container.RegisterType<ITypeToResolveWithConstructorParams, ConcreteTypeWithConstructorParams>();
var instance = container.Resolve<ITypeToResolveWithConstructorParams>();
Assert.IsInstanceOfType(instance, typeof(ConcreteTypeWithConstructorParams));
}
示例11: DependencyContructor
public void DependencyContructor()
{
var c = new SimpleContainer();
c.RegisterType<ITypeToResolveWithConstructorParams, ConcreteTypeWithDependencyConstructorAttr>();
c.RegisterType<ITypeToResolve, ConcreteType>();
var foo = c.Resolve<ITypeToResolveWithConstructorParams>();
Assert.IsNotNull(foo.Arg1);
Assert.IsNull(foo.Arg2);
}
示例12: Main
static void Main(string[] args)
{
SimpleContainer container = new SimpleContainer();
container.RegisterType<Testing>( false );
Testing t1 = container.Resolve<Testing>();
t1.foo();
TestingSingleton t2, t3;
container.RegisterType<TestingSingleton>( true );
t2 = container.Resolve<TestingSingleton>();
t3 = container.Resolve<TestingSingleton>();
Console.WriteLine( t2 == t3 );
IFoo t4, t5;
container.RegisterType<IFoo, TestingWithInterface>( false );
t4 = container.Resolve<IFoo>();
t4.foo();
container.RegisterType<IFoo, TestingWithInterface2>( false );
t5 = container.Resolve<IFoo>();
t5.foo();
Console.ReadKey();
}
示例13: RunWithSimpleConfiguration
private static void RunWithSimpleConfiguration()
{
Console.Out.WriteLine(nameof(Program.RunWithSimpleConfiguration));
var container = new SimpleContainer();
container.Register<IParent>(c => new JasonAsParent());
container.Register<IChild>(c => new DependentChild(c.Resolve<IParent>()));
var child = container.Resolve<IChild>();
for (var i = 0; i < 1000; i++)
{
child.DemandFunds();
}
Console.Out.WriteLine(child.Wallet);
}
示例14: ShowSimpleContainer
static void ShowSimpleContainer()
{
SimpleContainer container = new SimpleContainer();
container.Register<IFoo>( () => new ConsoleFoo() );
container.Register<Bar>(
() => {
IFoo foo = container.Resolve<IFoo>();
return new Bar( foo );
}
);
Bar bar = container.Resolve<Bar>();
bar.Example();
}
示例15: ThrowExceptionIfTypeNotRegistered
public void ThrowExceptionIfTypeNotRegistered()
{
var container = new SimpleContainer();
container.Resolve<ITypeToResolve>();
}