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


C# IocContainer.Compile方法代码示例

本文整理汇总了C#中IocContainer.Compile方法的典型用法代码示例。如果您正苦于以下问题:C# IocContainer.Compile方法的具体用法?C# IocContainer.Compile怎么用?C# IocContainer.Compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IocContainer的用法示例。


在下文中一共展示了IocContainer.Compile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompileDoesntBreakAnything

        public void CompileDoesntBreakAnything()
        {
            // What to do with this ... ?
            // To find out if anything was actually compiled it needs to inspect the Expression/Lambda created

            using (var container = new IocContainer())
            {
                // Arrange
                container.Register<IFoo>(c => new Foo1());
                container.Register<IBar>("bar1name", x => new Bar1());
                container.Register<IFooBar>(y => new FooBar((IFoo)y.Resolve(typeof(IFoo)), (IBar)y.Resolve(typeof(IBar), "bar1name")));
                container.Register<IFooBar>("foobarname", xyz => new FooBar(xyz.Resolve<IFoo>(), xyz.Resolve<IBar>("bar1name")));

                // Act
                container.Compile();

                var foo = container.Resolve<IFoo>();
                var bar = container.Resolve<IBar>("bar1name");
                var foobar1 = container.Resolve<IFooBar>();
                var foobar2 = container.Resolve<IFooBar>("foobarname");

                // Assert
                Assert.AreNotSame(foo, null);
                Assert.AreNotSame(bar, null);
                Assert.AreNotSame(foobar1, null);
                Assert.AreNotSame(foobar2, null);

                Assert.AreNotSame(foobar1.Foo, null);
                Assert.AreNotSame(foobar1.Bar, null);
                Assert.AreNotSame(foobar2.Foo, null);
                Assert.AreNotSame(foobar2.Bar, null);

                Assert.IsInstanceOfType(foo, typeof(Foo1));
                Assert.IsInstanceOfType(bar, typeof(Bar1));
                Assert.IsInstanceOfType(foobar1, typeof(FooBar));
                Assert.IsInstanceOfType(foobar2, typeof(FooBar));

                Assert.IsInstanceOfType(foobar1.Foo, typeof(Foo1));
                Assert.IsInstanceOfType(foobar1.Bar, typeof(Bar1));

                Assert.IsInstanceOfType(foobar2.Foo, typeof(Foo1));
                Assert.IsInstanceOfType(foobar2.Bar, typeof(Bar1));
            }
        }
开发者ID:thanhvc,项目名称:DynamoIOC,代码行数:44,代码来源:ContainerTest.cs

示例2: CompileWorksWithPropertyInjection

        public void CompileWorksWithPropertyInjection()
        {
            // Can Resolve Property Injection !?
            // Make one using Resolve(Type) and one using Resolve<> generic ?

            // There need to be a check that the registration was actually compiled

            using (var container = new IocContainer())
            {
                // Arrange
                container.Register<IFoo>(c => new Foo1());
                container.Register<IBar>(c => new Bar1());
                container.Register<IFooBar>(c => new FooBar() { Foo = c.Resolve<IFoo>(), Bar = c.Resolve<IBar>() });

                // Act
                container.Compile();

                var foo = container.Resolve<IFoo>();
                var bar = container.Resolve<IBar>();
                var foobar = container.Resolve<IFooBar>();

                // Assert
                Assert.AreNotSame(foo, null);
                Assert.AreNotSame(bar, null);
                Assert.AreNotSame(foobar, null);

                Assert.AreNotSame(foobar.Foo, null);
                Assert.AreNotSame(foobar.Bar, null);
            }
        }
开发者ID:thanhvc,项目名称:DynamoIOC,代码行数:30,代码来源:ContainerTest.cs

示例3: CompileThrowsExceptionIfRegistrationsAreNotValid

        public void CompileThrowsExceptionIfRegistrationsAreNotValid()
        {
            using (var container = new IocContainer())
            {
                // Arrange
                container.Register<IFoo>(c => new Foo1());
                container.Register<IBar>("Bar", x => new Bar1());
                container.Register<IFooBar>(y => new FooBar((IFoo)y.Resolve(typeof(IFoo)), (IBar)y.Resolve(typeof(IBar), "Bar")));
                container.Register<IFooBar>("FooBar", xyz => new FooBar(xyz.Resolve<IFoo>(), xyz.Resolve<IBar>()));

                // Act
                container.Compile();
            }
        }
开发者ID:thanhvc,项目名称:DynamoIOC,代码行数:14,代码来源:ContainerTest.cs


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