本文整理汇总了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));
}
}
示例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;
}
示例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);
}
}
}
示例5: BuildDescription
private static string BuildDescription(InstanceProducer registration, KnownRelationship[] relationships)
{
string componentName = BuildComponentName(registration, relationships);
string unregisteredTypeName = BuildUnregisteredTypeDescription(relationships);
return componentName + " depends on " + unregisteredTypeName + ".";
}
示例6: BuildDiagnosticResult
private static ContainerRegisteredServiceDiagnosticResult BuildDiagnosticResult(
InstanceProducer registration, KnownRelationship[] relationships)
{
return new ContainerRegisteredServiceDiagnosticResult(
serviceType: registration.ServiceType,
description: BuildDescription(registration, relationships),
relationships: relationships);
}
示例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;
}
示例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());
}
示例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));
}
示例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());
}
示例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());
}
示例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));
}
示例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);
}
示例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<>);
}