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


C# InstanceProducer类代码示例

本文整理汇总了C#中InstanceProducer的典型用法代码示例。如果您正苦于以下问题:C# InstanceProducer类的具体用法?C# InstanceProducer怎么用?C# InstanceProducer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ThrowWhenProviderToRegisterOverlapsWithExistingProvider

        private void ThrowWhenProviderToRegisterOverlapsWithExistingProvider(
            InstanceProducer producerToRegister)
        {
            // A provider is a superset of the providerToRegister when it can be applied to ALL generic
            // types that the providerToRegister can be applied to as well.
            var overlappingProducers =
                from producer in this.CurrentProducers
                where producer.ImplementationType != null
                where !producer.Registration.WrapsInstanceCreationDelegate
                where !producerToRegister.Registration.WrapsInstanceCreationDelegate
                where producer.ImplementationType == producerToRegister.ImplementationType
                select producer;

            if (overlappingProducers.Any())
            {
                var overlappingProducer = overlappingProducers.FirstOrDefault();

                throw new InvalidOperationException(
                    StringResources.AnOverlappingGenericRegistrationExists(
                        producerToRegister.ServiceType,
                        overlappingProducer.ImplementationType,
                        overlappingProducer.IsConditional,
                        producerToRegister.ImplementationType,
                        producerToRegister.IsConditional));
            }
        }
开发者ID:bcraun,项目名称:SimpleInjector,代码行数:26,代码来源:NonGenericRegistrationEntry.cs

示例2: DisposableTransientComponentDiagnosticResult

 internal DisposableTransientComponentDiagnosticResult(Type serviceType, InstanceProducer registration, 
     string description)
     : base(serviceType, description, DiagnosticType.DisposableTransientComponent,
         DiagnosticSeverity.Warning, registration)
 {
     this.Registration = registration;
 }
开发者ID:MichaelSagalovich,项目名称:SimpleInjector,代码行数:7,代码来源:DisposableTransientComponentDiagnosticResult.cs

示例3: ServiceTypeDecoratorInfo

 internal ServiceTypeDecoratorInfo(Type registeredServiceType, Type implementationType,
     InstanceProducer originalProducer)
 {
     this.registeredServiceType = registeredServiceType;
     this.ImplementationType = implementationType;
     this.OriginalProducer = originalProducer;
 }
开发者ID:bcraun,项目名称:SimpleInjector,代码行数:7,代码来源:ServiceTypeDecoratorInfo.cs

示例4: GetSelfAndDependentProducers

        private static IEnumerable<InstanceProducer> GetSelfAndDependentProducers(InstanceProducer producer,
            HashSet<InstanceProducer> set = null)
        {
            set = set ?? new HashSet<InstanceProducer>(ReferenceEqualityComparer<InstanceProducer>.Instance);

            // Prevent stack overflow exception in case the graph is cyclic.
            if (set.Contains(producer))
            {
                yield break;
            }

            // Return self
            yield return set.AddReturn(producer);

            // Return dependent producers
            foreach (var relationship in producer.GetRelationships())
            {
                yield return set.AddReturn(relationship.Dependency);

                foreach (var dependentProducer in GetSelfAndDependentProducers(relationship.Dependency, set))
                {
                    yield return set.AddReturn(dependentProducer);
                }
            }
        }
开发者ID:bcraun,项目名称:SimpleInjector,代码行数:25,代码来源:Analyzer.cs

示例5: BuildDescription

        private static string BuildDescription(InstanceProducer registration, KnownRelationship[] relationships)
        {
            string componentName = BuildComponentName(registration, relationships);
            string unregisteredTypeName = BuildUnregisteredTypeDescription(relationships);

            return componentName + " depends on " + unregisteredTypeName + ".";
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:7,代码来源:ContainerRegisteredServiceAnalyzer.cs

示例6: BuildDiagnosticResult

 private static ContainerRegisteredServiceDiagnosticResult BuildDiagnosticResult(
     InstanceProducer registration, KnownRelationship[] relationships)
 {
     return new ContainerRegisteredServiceDiagnosticResult(
         serviceType: registration.ServiceType,
         description: BuildDescription(registration, relationships),
         relationships: relationships);
 }
开发者ID:MichaelSagalovich,项目名称:SimpleInjector,代码行数:8,代码来源:ContainerRegisteredServiceAnalyzer.cs

示例7: GetDebugValue

 private static DebuggerViewItem[] GetDebugValue(Type implementationType, InstanceProducer[] dependencies)
 {
     return new[]
     {
         new DebuggerViewItem("ImplementationType", implementationType.ToFriendlyName(), implementationType),
         new DebuggerViewItem("Dependencies", dependencies.Length + " dependencies.", dependencies),
     };
 }
开发者ID:MichaelSagalovich,项目名称:SimpleInjector,代码行数:8,代码来源:SingleResponsibilityViolationDiagnosticResult.cs

示例8: InitializationContext

        internal InitializationContext(InstanceProducer producer, Registration registration)
        {
            // producer will be null when a user calls Registration.BuildExpression() directly, instead of
            // calling InstanceProducer.BuildExpression() or InstanceProducer.GetInstance(). 
            Requires.IsNotNull(registration, nameof(registration));

            this.Producer = producer;
            this.Registration = registration;
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:9,代码来源:InitializationContext.cs

示例9: TornLifestyleDiagnosticResult

 internal TornLifestyleDiagnosticResult(Type serviceType, string description, Lifestyle lifestyle,
     Type implementationType, InstanceProducer[] affectedRegistrations)
     : base(serviceType, description, DiagnosticType.TornLifestyle, DiagnosticSeverity.Warning,
         CreateDebugValue(implementationType, lifestyle, affectedRegistrations))
 {
     this.Lifestyle = lifestyle;
     this.ImplementationType = implementationType;
     this.AffectedRegistrations = new ReadOnlyCollection<InstanceProducer>(affectedRegistrations.ToList());
 }
开发者ID:MichaelSagalovich,项目名称:SimpleInjector,代码行数:9,代码来源:TornLifestyleDiagnosticResult.cs

示例10: Add

        public void Add(InstanceProducer producer)
        {
            this.container.ThrowWhenContainerIsLocked();

            this.ThrowWhenOverlappingRegistrationsExist(producer);

            this.providers.RemoveAll(p => p.ServiceType == producer.ServiceType);

            this.providers.Add(new ClosedToInstanceProducerProvider(producer));
        }
开发者ID:bcraun,项目名称:SimpleInjector,代码行数:10,代码来源:GenericRegistrationEntry.cs

示例11: ShortCircuitedDependencyDiagnosticResult

 internal ShortCircuitedDependencyDiagnosticResult(Type serviceType, string description,
     InstanceProducer registration, KnownRelationship relationship,
     IEnumerable<InstanceProducer> expectedDependencies)
     : base(serviceType, description, DiagnosticType.ShortCircuitedDependency, 
         DiagnosticSeverity.Warning, 
         CreateDebugValue(registration, relationship, expectedDependencies.ToArray()))
 {
     this.Relationship = relationship;
     this.ExpectedDependencies = new ReadOnlyCollection<InstanceProducer>(expectedDependencies.ToList());
 }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:10,代码来源:ShortCircuitedDependencyDiagnosticResult.cs

示例12: AmbiguousLifestylesDiagnosticResult

 internal AmbiguousLifestylesDiagnosticResult(Type serviceType, string description, 
     Lifestyle[] lifestyles, Type implementationType, InstanceProducer diagnosedProducer, 
     InstanceProducer[] conflictingProducers)
     : base(serviceType, description, DiagnosticType.AmbiguousLifestyles, DiagnosticSeverity.Warning,
         CreateDebugValue(implementationType, lifestyles, conflictingProducers))
 {
     this.Lifestyles = new ReadOnlyCollection<Lifestyle>(lifestyles.ToList());
     this.ImplementationType = implementationType;
     this.DiagnosedRegistration = diagnosedProducer;
     this.ConflictingRegistrations = new ReadOnlyCollection<InstanceProducer>(conflictingProducers.ToList());
 }
开发者ID:bluexary,项目名称:SimpleInjector,代码行数:11,代码来源:AmbiguousLifestylesDiagnosticResult.cs

示例13: AddAppliedDecorator

        internal void AddAppliedDecorator(Type decoratorType, Container container, Lifestyle lifestyle, 
            Expression decoratedExpression, IEnumerable<KnownRelationship> decoratorRelationships = null)
        {
            var registration = new ExpressionRegistration(decoratedExpression, decoratorType,
                lifestyle, container);

            registration.ReplaceRelationships(decoratorRelationships ?? Enumerable.Empty<KnownRelationship>());

            var producer = new InstanceProducer(this.registeredServiceType, registration);

            this.appliedDecorators.Add(new DecoratorInfo(decoratorType, producer));
        }
开发者ID:bcraun,项目名称:SimpleInjector,代码行数:12,代码来源:ServiceTypeDecoratorInfo.cs

示例14: CreateDiagnosticResult

        private static TornLifestyleDiagnosticResult CreateDiagnosticResult(
            InstanceProducer diagnosedProducer,
            InstanceProducer[] affectedProducers)
        {
            Type serviceType = diagnosedProducer.ServiceType;
            Type implementationType = diagnosedProducer.Registration.ImplementationType;
            Lifestyle lifestyle = diagnosedProducer.Registration.Lifestyle;
            string description = BuildDescription(diagnosedProducer, affectedProducers);

            return new TornLifestyleDiagnosticResult(serviceType, description, lifestyle, implementationType,
                affectedProducers);
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:12,代码来源:TornLifestyleContainerAnalyzer.cs

示例15: IsAnalyzable

        private static bool IsAnalyzable(InstanceProducer producer)
        {
            // We can't analyze collections, because this would lead to false positives when decorators are
            // applied to the collection. For a decorator, each collection element it decorates is a 
            // dependency, which will make it look as if the decorator has too many dependencies. Since the
            // container will delegate the creation of those elements back to the container, those elements
            // would by them selves still get analyzed, so the only thing we'd miss here is the decorator.
            if (!producer.ServiceType.Info().IsGenericType)
            {
                return true;
            }

            return producer.ServiceType.GetGenericTypeDefinition() != typeof(IEnumerable<>);
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:14,代码来源:SingleResponsibilityViolationsAnalyzer.cs


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