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


C# Container.AddRegistration方法代码示例

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


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

示例1: Build

        public override void Build(Container container)
        {
            var factoryType = container.GetFactoryForType(this.ServiceType.Type);
            var creator = new AbstractFactoryCreator(factoryType);
            var registration = new TransientRegistration(creator);

            container.AddRegistration(new TypeKey(this.ServiceType.Type.TypeHandle, this.ServiceType.Key), registration);
        }
开发者ID:modulexcite,项目名称:Stylet,代码行数:8,代码来源:BuilderAbstractFactoryBinding.cs

示例2: Build

        public override void Build(Container container)
        {
            var creator = new InstanceCreator(this.instance);
            var registration = this.CreateRegistration(container, creator);

            foreach (var serviceType in this.ServiceTypes)
            {
                container.AddRegistration(new TypeKey(serviceType.Type.TypeHandle, serviceType.Key), registration);
            }
        }
开发者ID:modulexcite,项目名称:Stylet,代码行数:10,代码来源:BuilderInstanceBinding.cs

示例3: AddRegistration_SuppliedWithOpenGenericServiceType_ThrowsExpectedException

        public void AddRegistration_SuppliedWithOpenGenericServiceType_ThrowsExpectedException()
        {
            // Arrange
            Container container = new Container();

            var registration = Lifestyle.Transient.CreateRegistration<StructCommandHandler>(container);

            // Act
            Action action = () => container.AddRegistration(typeof(ICommandHandler<>), registration);

            // Assert
            AssertThat.ThrowsWithExceptionMessageContains<ArgumentException>(
                "The supplied type ICommandHandler<TCommand> is an open generic type.",
                action);
            AssertThat.ThrowsWithParamName("serviceType", action);
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:16,代码来源:AddRegistrationTests.cs

示例4: Analyze_MismatchWithSuppressDiagnosticWarning_NoWarning

        public void Analyze_MismatchWithSuppressDiagnosticWarning_NoWarning()
        {
            // Arrange
            var container = new Container();

            container.Register<IUserRepository, InMemoryUserRepository>();

            var registration = 
                Lifestyle.Singleton.CreateRegistration<UserServiceBase, RealUserService>(container);

            container.AddRegistration(typeof(UserServiceBase), registration);

            container.Options.SuppressLifestyleMismatchVerification = true;

            container.Verify(VerificationOption.VerifyOnly);

            registration.SuppressDiagnosticWarning(DiagnosticType.PotentialLifestyleMismatch);

            container.Options.SuppressLifestyleMismatchVerification = false;

            container.Verify(VerificationOption.VerifyOnly);

            // Act
            var results = Analyzer.Analyze(container).OfType<PotentialLifestyleMismatchDiagnosticResult>()
                .ToArray();

            // Assert
            Assert.AreEqual(0, results.Length, Actual(results));
        }
开发者ID:MichaelSagalovich,项目名称:SimpleInjector,代码行数:29,代码来源:PotentialLifestyleMismatchContainerAnalyzerTests.cs

示例5: Container

        public void Analyze_TwoRegistrationsForTheSameImplementationMadeWithTheSameRegistrationInstanceWrappedBySingletonDecorators_DoesNotReturnsAWarning()
        {
            // Arrange
            var container = new Container();

            var reg = Lifestyle.Singleton.CreateRegistration<FooBar>(container);

            container.AddRegistration(typeof(IFoo), reg);
            container.AddRegistration(typeof(IBar), reg);

            container.RegisterDecorator(typeof(IBar), typeof(BarDecorator), Lifestyle.Singleton);

            container.Verify();

            // Act
            var results = Analyzer.Analyze(container).OfType<TornLifestyleDiagnosticResult>().ToArray();

            // Assert
            Assert.AreEqual(0, results.Length, Actual(results));
        }
开发者ID:BrettJaner,项目名称:SimpleInjector,代码行数:20,代码来源:TornLifestyleContainerAnalyzerTests.cs

示例6: Analyze_TwoSingletonRegistrationsMappedOnFourServiceTypes_ReturnsExpectedWarnings

        public void Analyze_TwoSingletonRegistrationsMappedOnFourServiceTypes_ReturnsExpectedWarnings()
        {
            // Arrange
            string expectedMessage1 =
                "The registration for IFoo maps to the same implementation and lifestyle as the " +
                "registrations for IBar and IBarExt do.";

            string expectedMessage2 =
            "The registration for IBar maps to the same implementation and lifestyle as the " +
            "registrations for IFoo and IFooExt do.";

            var container = new Container();

            var fooReg = Lifestyle.Singleton.CreateRegistration<FooBar>(container);
            var barReg = Lifestyle.Singleton.CreateRegistration<FooBar>(container);

            container.AddRegistration(typeof(IFoo), fooReg);
            container.AddRegistration(typeof(IFooExt), fooReg);
            container.AddRegistration(typeof(IBar), barReg);
            container.AddRegistration(typeof(IBarExt), barReg);

            container.Verify(VerificationOption.VerifyOnly);

            // Act
            var results = Analyzer.Analyze(container).OfType<TornLifestyleDiagnosticResult>().ToArray();

            // Assert
            Assert.AreEqual(4, results.Length, Actual(results));

            Assert_ContainsDescription(results, expectedMessage1);
            Assert_ContainsDescription(results, expectedMessage2);
        }
开发者ID:BrettJaner,项目名称:SimpleInjector,代码行数:32,代码来源:TornLifestyleContainerAnalyzerTests.cs

示例7: Analyze_TwoDistinctRegistrationsForSameLifestyle_ReturnsWarning

        public void Analyze_TwoDistinctRegistrationsForSameLifestyle_ReturnsWarning()
        {
            // Arrange
            var container = new Container();

            var fooReg = Lifestyle.Singleton.CreateRegistration<IFoo, FooBar>(container);
            var barReg = Lifestyle.Singleton.CreateRegistration<IBar, FooBar>(container);

            container.AddRegistration(typeof(IFoo), fooReg);
            container.AddRegistration(typeof(IBar), barReg);

            container.Verify(VerificationOption.VerifyOnly);

            // Act
            var results = Analyzer.Analyze(container).OfType<TornLifestyleDiagnosticResult>().ToArray();

            // Assert
            Assert.AreEqual(2, results.Length, Actual(results));
        }
开发者ID:BrettJaner,项目名称:SimpleInjector,代码行数:19,代码来源:TornLifestyleContainerAnalyzerTests.cs

示例8: BindImplementationToServices

        protected void BindImplementationToServices(Container container, Type implementationType)
        {
            if (this.ServiceTypes.Count > 1)
            {
                var firstGenericType = this.ServiceTypes.FirstOrDefault(x => x.Type.IsGenericTypeDefinition);

                if (firstGenericType != null)
                    throw new StyletIoCRegistrationException(String.Format("Cannot create a multiple-service binding with an unbound generic type {0}", firstGenericType.Type.GetDescription()));

                var creator = new TypeCreator(implementationType, container);
                var registration = this.CreateRegistration(container, creator);

                foreach (var serviceType in this.ServiceTypes)
                {
                    container.AddRegistration(new TypeKey(serviceType.Type.TypeHandle, serviceType.Key ?? creator.AttributeKey), registration);
                }
            }
            else
            {
                this.BindImplementationToSpecificService(container, implementationType, this.ServiceTypes[0].Type, this.ServiceTypes[0].Key);
            }
        }
开发者ID:modulexcite,项目名称:Stylet,代码行数:22,代码来源:BuilderBindingBase.cs

示例9: BindImplementationToSpecificService

        // Convenience...
        protected void BindImplementationToSpecificService(Container container, Type implementationType, Type serviceType, string key)
        {
            if (serviceType.IsGenericTypeDefinition)
            {
                var unboundGeneric = new UnboundGeneric(serviceType, implementationType, container, this.RegistrationFactory);
                container.AddUnboundGeneric(new TypeKey(serviceType.TypeHandle, key), unboundGeneric);
            }
            else
            {
                var creator = new TypeCreator(implementationType, container);
                var registration = this.CreateRegistration(container, creator);

                container.AddRegistration(new TypeKey(serviceType.TypeHandle, key ?? creator.AttributeKey), registration);
            }
        }
开发者ID:modulexcite,项目名称:Stylet,代码行数:16,代码来源:BuilderBindingBase.cs


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