/// <summary> /// Creates the visitors that are <see cref="TypeInfo.IsAssignableFrom(TypeInfo)"/> to the specified type. /// </summary> /// <typeparam name="TRegistration">The type of visitor.</typeparam> /// <param name="container">The <see cref="CompositionContainer"/>.</param> /// <param name="manager">The <see cref="VisitorManager"/>.</param> /// <returns> /// The visitors that are <see cref="TypeInfo.IsAssignableFrom(TypeInfo)"/> to the specified type. /// </returns> public IEnumerable <IRegistrationVisitor <TRegistration> > CreateVisitors <TRegistration>( CompositionContainer container, VisitorManager manager) where TRegistration : class, IRegistration { if (container == null) { throw new ArgumentNullException(nameof(container)); } if (manager == null) { throw new ArgumentNullException(nameof(manager)); } Type visitorType = typeof(IRegistrationVisitor <TRegistration>); IReadOnlyList <object> nonTypedFactories = VisitorFactoryCache.GetOrAdd(visitorType, t => CreateVisitorFactories <TRegistration>()); IEnumerable <Func <CompositionContainer, VisitorManager, IRegistrationVisitor <TRegistration> > > factories = nonTypedFactories .Cast <Func <CompositionContainer, VisitorManager, IRegistrationVisitor <TRegistration> > >(); return(factories.Select(f => f(container, manager))); }
private static void VisitRegistration <TRegistration>(VisitorManager manager, IRegistration registration) where TRegistration : class, IRegistration { if (registration == null) { throw new ArgumentNullException(nameof(registration)); } if (manager == null) { throw new ArgumentNullException(nameof(manager)); } Type visitorType = typeof(IRegistrationVisitor <TRegistration>); if (!manager._visitors.TryGetValue(visitorType, out IRegistrationVisitor[] visitors))
private static void ProcessRegistrations( CompositionContainer container, IEnumerable <Type> externalVisitorTypes = null) { if (container == null) { throw new ArgumentNullException(nameof(container)); } var visitorManager = new VisitorManager(container, externalVisitorTypes); IEnumerable <IRegistration> registrations = container.Registrations.Values.SelectMany(r => r); foreach (IRegistration registration in registrations) { visitorManager.Visit(registration); } }