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


C# ServiceContainer.AddDefaultServices方法代码示例

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


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

示例1: Test

        private static void Test(string serviceName, Action<IGenerateFactory<ISampleService>> usingFactory, Func<IUsingLambda<ISampleService>, IGenerateFactory<ISampleService>> doInject, Func<string, IServiceContainer, bool> verifyResult)
        {
            var container = new ServiceContainer();

            // HACK: Manually inject the required services into the container
            container.AddDefaultServices();

            Inject(serviceName, usingFactory, doInject, container);
            verifyResult(serviceName, container);
        }
开发者ID:sdether,项目名称:LinFu,代码行数:10,代码来源:FluentExtensionTests.Implementation.cs

示例2: ShouldResolveConstructorWithMostResolvableParametersFromContainer

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

            // Add an ISampleService instance
            container.AddService(mockSampleService.Object);
            container.AddDefaultServices();
            var resolver = container.GetService<IMemberResolver<ConstructorInfo>>();
            Assert.IsNotNull(resolver);

            // The resolver should return the constructor with two ISampleService parameters
            var expectedConstructor =
                typeof (SampleClassWithMultipleConstructors).GetConstructor(new[]
                {
                    typeof (ISampleService),
                    typeof (ISampleService)
                });
            Assert.IsNotNull(expectedConstructor);

            var finderContext = new MethodFinderContext(new Type[0], new object[0], null);
            var result = resolver.ResolveFrom(typeof (SampleClassWithMultipleConstructors), container,
                finderContext);
            Assert.AreSame(expectedConstructor, result);
        }
开发者ID:philiplaureano,项目名称:LinFu,代码行数:25,代码来源:ResolutionTests.cs

示例3: ShouldResolveConstructorWithAdditionalArgument

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

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

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

            // The resolver should return the constructor
            // with the following signature: Constructor(ISampleService, int)
            var expectedConstructor =
                typeof (SampleClassWithAdditionalArgument).GetConstructor(new[] {typeof (ISampleService), typeof (int)});
            Assert.IsNotNull(expectedConstructor);

            var context = new MethodFinderContext(42);
            var result = resolver.ResolveFrom(typeof (SampleClassWithAdditionalArgument), container, context);
            Assert.AreSame(expectedConstructor, result);
        }
开发者ID:philiplaureano,项目名称:LinFu,代码行数:22,代码来源:ResolutionTests.cs

示例4: ShouldResolveClassWithMultipleNonServiceArgumentConstructors

        public void ShouldResolveClassWithMultipleNonServiceArgumentConstructors()
        {
            IServiceContainer container = new ServiceContainer();
            container.AddDefaultServices();
            container.AddService("ClassWithMultipleNonServiceArgumentConstructors",
                typeof (ISampleService), typeof (SampleClassWithMultipleNonServiceArgumentConstructors),
                LifecycleType.OncePerRequest);

            // Match the correct constructor
            var sampleService = container.GetService<ISampleService>("ClassWithMultipleNonServiceArgumentConstructors",
                "test", 42, SampleEnum.One, (decimal) 3.14, 42);
            Assert.IsNotNull(sampleService);
        }
开发者ID:philiplaureano,项目名称:LinFu,代码行数:13,代码来源:ResolutionTests.cs

示例5: ShouldInstantiateObjectWithConstructorAndArguments

        public void ShouldInstantiateObjectWithConstructorAndArguments()
        {
            var targetConstructor = typeof (SampleClassWithMultipleConstructors).GetConstructor(new[]
            {
                typeof
                    (
                    ISampleService
                    )
                ,
                typeof
                    (
                    ISampleService
                    )
            });

            // Create the method arguments
            var mockSampleService = new Mock<ISampleService>();
            var arguments = new object[] {mockSampleService.Object, mockSampleService.Object};

            // Initialize the container
            IServiceContainer container = new ServiceContainer();
            container.AddDefaultServices();

            var constructorInvoke = container.GetService<IMethodInvoke<ConstructorInfo>>();
            var result = constructorInvoke.Invoke(null, targetConstructor, arguments);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(typeof (SampleClassWithMultipleConstructors), result);
        }
开发者ID:philiplaureano,项目名称:LinFu,代码行数:29,代码来源:ResolutionTests.cs

示例6: ShouldInstantiateClassWithNonServiceArguments

        public void ShouldInstantiateClassWithNonServiceArguments()
        {
            var container = new ServiceContainer();
            container.AddDefaultServices();

            container.AddService(typeof (SampleClassWithNonServiceArgument), typeof (SampleClassWithNonServiceArgument));

            var text = "Hello, World!";
            string serviceName = null;
            var result = container.GetService<SampleClassWithNonServiceArgument>(serviceName, text);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Value == text);
        }
开发者ID:philiplaureano,项目名称:LinFu,代码行数:14,代码来源:ResolutionTests.cs


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