当前位置: 首页>>代码示例>>C#>>正文


C# SimpleContainer.Resolve方法代码示例

本文整理汇总了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);
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:8,代码来源:L9Tests.cs

示例2: ResolveConcreteTypeTransient

        public void ResolveConcreteTypeTransient()
        {
            var container = new SimpleContainer();
            container.RegisterType<ConcreteType>(false);

            var instance = container.Resolve<ConcreteType>();

            Assert.AreNotSame(container.Resolve<ConcreteType>(), instance);
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:9,代码来源:L9Tests.cs

示例3: ResolveConcreteTypeSingleton

        public void ResolveConcreteTypeSingleton()
        {
            var container = new SimpleContainer();
            container.RegisterType<ConcreteType>();

            var instance = container.Resolve<ConcreteType>();

            Assert.AreSame(container.Resolve<ConcreteType>(), instance);
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:9,代码来源:L9Tests.cs

示例4: DefaultSingletonCreation

        public void DefaultSingletonCreation()
        {
            var container = new SimpleContainer();

            container.RegisterType<ITypeToResolve, ConcreteType>();

            var instance = container.Resolve<ITypeToResolve>();
            Assert.AreSame(container.Resolve<ITypeToResolve>(), instance);
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:9,代码来源:L9Tests.cs

示例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>();
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:7,代码来源:L10Tests.cs

示例6: CyclicDependencySimple

        public void CyclicDependencySimple()
        {
            var c = new SimpleContainer();

            c.RegisterType<ITypeToResolve, ConcreteWithSimpleCyclicDependency>();
            c.Resolve<ITypeToResolve>();
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:7,代码来源:L10Tests.cs

示例7: ResolvableSecondConstructor

        public void ResolvableSecondConstructor()
        {
            var c = new SimpleContainer();

            c.RegisterType<ITypeToResolve, ConcreteType>();
            var instance = c.Resolve<ConcreteWithResolvableSecondConstructor>();
            Assert.IsNotNull(instance.Arg1);
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:8,代码来源:L10Tests.cs

示例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);
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:9,代码来源:L10Tests.cs

示例9: ResolveObjectWithInterface

        public void ResolveObjectWithInterface()
        {
            var container = new SimpleContainer();

            container.RegisterType<ITypeToResolve, ConcreteType>();

            var instance = container.Resolve<ITypeToResolve>();

            Assert.IsInstanceOfType(instance, typeof(ConcreteType));
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:10,代码来源:L9Tests.cs

示例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));
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:10,代码来源:L9Tests.cs

示例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);
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:10,代码来源:L10Tests.cs

示例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();
 }
开发者ID:voter101,项目名称:ooad_ii,代码行数:20,代码来源:Program.cs

示例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);
        }
开发者ID:JasonBock,项目名称:DependenciesDemystified,代码行数:17,代码来源:Program.cs

示例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();
        }
开发者ID:smaclell,项目名称:di-intro,代码行数:16,代码来源:Program.cs

示例15: ThrowExceptionIfTypeNotRegistered

        public void ThrowExceptionIfTypeNotRegistered()
        {
            var container = new SimpleContainer();

            container.Resolve<ITypeToResolve>();
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:6,代码来源:L9Tests.cs


注:本文中的SimpleContainer.Resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。