本文整理汇总了C#中IComponentRegistration类的典型用法代码示例。如果您正苦于以下问题:C# IComponentRegistration类的具体用法?C# IComponentRegistration怎么用?C# IComponentRegistration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IComponentRegistration类属于命名空间,在下文中一共展示了IComponentRegistration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstanceLookup
public InstanceLookup(
IComponentRegistration registration,
IResolveOperation context,
ISharingLifetimeScope mostNestedVisibleScope,
IEnumerable<Parameter> parameters)
{
Parameters = parameters;
ComponentRegistration = registration;
_context = context;
try
{
_activationScope = ComponentRegistration.Lifetime.FindScope(mostNestedVisibleScope);
}
catch (DependencyResolutionException ex)
{
var services = new StringBuilder();
foreach (var s in registration.Services)
{
services.Append("- ");
services.AppendLine(s.Description);
}
var message = String.Format(CultureInfo.CurrentCulture, ComponentActivationResources.UnableToLocateLifetimeScope, registration.Activator.LimitType, services);
throw new DependencyResolutionException(message, ex);
}
}
示例2: AttachToComponentRegistration
protected override void AttachToComponentRegistration(IComponentRegistry registry, IComponentRegistration registration)
{
registration.Preparing += (s, e) =>
{
e.Parameters = new [] { loggerParameter }.Concat(e.Parameters);
};
}
示例3: AttachToComponentRegistration
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry,
IComponentRegistration registration)
{
registration.Preparing += RegistrationOnPreparing;
registration.Activating += RegistrationOnActivating;
base.AttachToComponentRegistration(componentRegistry, registration);
}
示例4: AttachToComponentRegistration
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
registration.Preparing += (sender, args) =>
{
args.Parameters = args.Parameters.Union( new[] { new NamedParameter(@"basePoint", _basePoint) } );
};
}
示例5: AttachToComponentRegistration
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
var implementationType = registration.Activator.LimitType;
foreach (var autoWireType in autoWireTypes)
{
var constructors = implementationType.GetConstructorsWithDependency(autoWireType);
if (constructors.Any())
{
registration.Preparing += (sender, e) =>
{
var parameter = new TypedParameter(autoWireType,
e.Context.Resolve(autoWireType, new TypedParameter(typeof(Type), implementationType)));
e.Parameters = e.Parameters.Concat(new[] { parameter });
};
}
else
{
var props = implementationType.GetPropertiesWithDependency(autoWireType);
if (props.Any())
{
registration.Activated += (s, e) =>
{
foreach (var prop in props)
{
prop.SetValue(e.Instance,
e.Context.Resolve(autoWireType));
}
};
}
}
}
foreach (var serviceType in typebasedServiceTypes)
{
var constructorInjectors = BuildConstructorServiceInjectors(implementationType, serviceType).ToArray();
if (constructorInjectors.Any())
{
registration.Preparing += (s, e) =>
{
foreach (var ci in constructorInjectors)
ci(e);
};
return;
}
// build an array of actions on this type to assign loggers to member properties
var injectors = BuildPropertyServiceInjectors(implementationType, serviceType).ToArray();
if (injectors.Any())
{
registration.Activated += (s, e) =>
{
foreach (var injector in injectors)
injector(e.Context, e.Instance);
};
}
}
}
示例6: PreparingEventArgs
/// <summary>
/// Initializes a new instance of the <see cref="PreparingEventArgs"/> class.
/// </summary>
/// <param name="service">Service which is preparing</param>
/// <param name="context">The context.</param>
/// <param name="component">The component.</param>
/// <param name="parameters">The parameters.</param>
public PreparingEventArgs(Service service, IComponentContext context, IComponentRegistration component, IEnumerable<Parameter> parameters)
{
_service = Enforce.ArgumentNotNull(service, "service");
_context = Enforce.ArgumentNotNull(context, "context");
_component = Enforce.ArgumentNotNull(component, "component");
_parameters = Enforce.ArgumentNotNull(parameters, "parameters");
}
示例7: AttachToComponentRegistration
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
var type = registration.Activator.LimitType; // AF2.0+
// .Descriptor.BestKnownImplementationType; // AF1.2+
// we hook preparing to inject the logger into the constructor
registration.Preparing += OnComponentPreparing;
// build the list of actions for type and assign loggers to properties
var injectors = BuildLogPropertyInjectors(type);
// no logger properties, no need to hook up the event
// ReSharper disable PossibleMultipleEnumeration
if (!injectors.Any())
// ReSharper restore PossibleMultipleEnumeration
return;
// we hook acticating to inject the logger into the known public properties
registration.Activating += (s, e) =>
{
// ReSharper disable PossibleMultipleEnumeration
foreach (var injector in injectors)
// ReSharper restore PossibleMultipleEnumeration
injector(e.Context, e.Instance);
};
}
示例8: AttachToComponentRegistration
protected override void AttachToComponentRegistration(
IComponentRegistry componentRegistry,
IComponentRegistration registration)
{
registration.Preparing += (sender, args) =>
log.Debug([email protected]"Resolving concrete type {args.Component.Activator.LimitType}");
}
示例9: ShapeAttributeOccurrence
public ShapeAttributeOccurrence(ShapeAttribute shapeAttribute, MethodInfo methodInfo, IComponentRegistration registration, Func<Feature> feature)
{
ShapeAttribute = shapeAttribute;
MethodInfo = methodInfo;
Registration = registration;
_feature = feature;
}
示例10: AttachToComponentRegistration
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
registration.Activating += (sender, e) =>
{
if (typeof (IMessageConsumer).IsAssignableFrom(e.Instance.GetType()))
consumerInterceptor.ItemCreated(e.Instance.GetType(), e.Component.Lifetime.GetType().Equals(typeof(CurrentScopeLifetime)));
};
}
示例11: AttachToComponentRegistration
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
registration.Preparing += (sender, args) => args.Parameters = args.Parameters.Concat(new[]
{
new ResolvedParameter((info, context) => info.ParameterType == typeof (ILog),
(info, context) => _logFactory(info.Member.DeclaringType))
});
}
示例12: ComponentRegistrationLifetimeDecorator
public ComponentRegistrationLifetimeDecorator(IComponentRegistration inner, IComponentLifetime lifetime)
{
if (inner == null) throw new ArgumentNullException("inner");
if (lifetime == null) throw new ArgumentNullException("lifetime");
_inner = inner;
_lifetime = lifetime;
}
示例13: AttachToComponentRegistration
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
// Handle constructor parameters.
registration.Preparing += OnComponentPreparing;
// Handle properties.
registration.Activated += (sender, e) => InjectLoggerProperties(e.Instance);
}
示例14: AddDecoratedComponentParameter
static IEnumerable<Parameter> AddDecoratedComponentParameter(Type decoratedParameterType, IComponentRegistration decoratedComponent, IEnumerable<Parameter> configuredParameters)
{
var parameter = new ResolvedParameter(
(pi, c) => pi.ParameterType == decoratedParameterType,
(pi, c) => c.ResolveComponent(decoratedComponent, Enumerable.Empty<Parameter>()));
return new[] { parameter }.Concat(configuredParameters);
}
示例15: ComponentRegisteredEventArgs
/// <summary>
/// Initializes a new instance of the <see cref="ComponentRegisteredEventArgs"/> class.
/// </summary>
/// <param name="registry">The container into which the registration
/// was made.</param>
/// <param name="componentRegistration">The component registration.</param>
public ComponentRegisteredEventArgs(IComponentRegistry registry, IComponentRegistration componentRegistration)
{
if (registry == null) throw new ArgumentNullException(nameof(registry));
if (componentRegistration == null) throw new ArgumentNullException(nameof(componentRegistration));
ComponentRegistry = registry;
ComponentRegistration = componentRegistration;
}