コード例 #1
0
 /// <summary>
 /// Registers the specified service descriptor.
 /// </summary>
 /// <param name="registration"></param>
 void Register(ServiceDescriptor registration)
 {
     if (registration.ServiceType.GetTypeInfo().IsGenericTypeDefinition == false)
     {
         builder.Register(registration.ToComponentRegistration(lifetimeScopeTagForSingletons));
     }
     else
     {
         builder.AddRegistrationSource(registration.ToRegistrationSource(builder, lifetimeScopeTagForSingletons));
     }
 }
コード例 #2
0
        private static void AttachExport(IComponentRegistryBuilder registry, IComponentRegistration registration, ExportConfigurationBuilder exportConfiguration)
        {
            var contractService = new ContractBasedService(exportConfiguration.ContractName, exportConfiguration.ExportTypeIdentity);

            var rb = RegistrationBuilder.ForDelegate((c, p) =>
            {
                var ctx = c.Resolve <IComponentContext>();
                return(new Export(
                           new ExportDefinition(exportConfiguration.ContractName, exportConfiguration.Metadata),
                           () => ctx.ResolveComponent(new ResolveRequest(contractService, registration, Array.Empty <Parameter>()))));
            })
                     .As(contractService)
                     .ExternallyOwned()
                     .WithMetadata((IEnumerable <KeyValuePair <string, object> >)exportConfiguration.Metadata);

            registry.Register(rb.CreateRegistration());
        }
コード例 #3
0
        /// <summary>
        /// Register a component in the component registry. This helper method is necessary
        /// in order to execute OnRegistered hooks and respect PreserveDefaults.
        /// </summary>
        /// <remarks>Hoping to refactor this out.</remarks>
        /// <param name="cr">Component registry to make registration in.</param>
        /// <param name="builder">Registration builder with data for new registration.</param>
        public static void RegisterSingleComponent <TLimit, TActivatorData, TSingleRegistrationStyle>(
            IComponentRegistryBuilder cr,
            IRegistrationBuilder <TLimit, TActivatorData, TSingleRegistrationStyle> builder)
            where TSingleRegistrationStyle : SingleRegistrationStyle
            where TActivatorData : IConcreteActivatorData
        {
            if (cr == null)
            {
                throw new ArgumentNullException(nameof(cr));
            }

            var registration = CreateRegistration(builder);

            cr.Register(registration, builder.RegistrationStyle.PreserveDefaults);

            var registeredEventArgs = new ComponentRegisteredEventArgs(cr, registration);

            foreach (var rh in builder.RegistrationStyle.RegisteredHandlers)
            {
                rh(cr, registeredEventArgs);
            }
        }