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


C# ServiceContainer.AutoCreate方法代码示例

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


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

示例1: ShouldAutoInjectClassCreatedWithAutoCreate

        public void ShouldAutoInjectClassCreatedWithAutoCreate()
        {
            // Configure the container
            var container = new ServiceContainer();
            container.LoadFromBaseDirectory("*.dll");

            var sampleService = new Mock<ISampleService>();
            container.AddService(sampleService.Object);

            var instance = (SampleClassWithInjectionProperties)container.AutoCreate(typeof(SampleClassWithInjectionProperties));

            // The container should initialize the SomeProperty method to match the mock ISampleService instance
            Assert.IsNotNull(instance.SomeProperty);
            Assert.AreSame(instance.SomeProperty, sampleService.Object);
        }
开发者ID:sdether,项目名称:LinFu,代码行数:15,代码来源:PropertyInjectionTests.cs

示例2: ContainerMustInjectFactoryInstances

        public void ContainerMustInjectFactoryInstances()
        {
            var mockFactory = new Mock<IFactory<ISampleService>>();
            mockFactory.Expect(f => f.CreateInstance(It.IsAny<IFactoryRequest>())).Returns(new SampleClass());

            var container = new ServiceContainer();
            container.AddFactory(mockFactory.Object);

            var instance =
                (SampleClassWithFactoryDependency) container.AutoCreate(typeof (SampleClassWithFactoryDependency));

            Assert.IsNotNull(instance);

            IFactory<ISampleService> factory = instance.Factory;
            factory.CreateInstance(null);

            mockFactory.VerifyAll();
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:18,代码来源:InversionOfControlTests.cs

示例3: ShouldInjectConstructorWithNamedParameterTypes

        public void ShouldInjectConstructorWithNamedParameterTypes()
        {
            var mockDefaultSampleService = new Mock<ISampleService>();
            var mockOtherSampleService = new Mock<ISampleService>();
            var container = new ServiceContainer();

            // Add the default service
            container.AddService(mockDefaultSampleService.Object);

            // Add the expected service instance
            container.AddService("OtherService", mockOtherSampleService.Object);

            var serviceInstance =
                (SampleClassWithNamedParameters) container.AutoCreate(typeof (SampleClassWithNamedParameters));

            Assert.AreEqual(mockOtherSampleService.Object, serviceInstance.ServiceInstance);
        }
开发者ID:philiplaureano,项目名称:LinFu,代码行数:17,代码来源:ResolutionTests.cs

示例4: ShouldCreateTypeWithAdditionalParameters

        public void ShouldCreateTypeWithAdditionalParameters()
        {
            var mockSampleService = new Mock<ISampleService>();
            IServiceContainer container = new ServiceContainer();

            // Add an ISampleService instance
            container.AddService(mockSampleService.Object);

            var resolver = container.GetService<IMemberResolver<ConstructorInfo>>();
            Assert.IsNotNull(resolver);

            var instance =
                container.AutoCreate(typeof (SampleClassWithAdditionalArgument), 42) as
                    SampleClassWithAdditionalArgument;
            Assert.IsNotNull(instance);
            Assert.IsTrue(instance.Argument == 42);
        }
开发者ID:philiplaureano,项目名称:LinFu,代码行数:17,代码来源:ResolutionTests.cs


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