Exported <TLimit, TActivatorData, TSingleRegistrationStyle>( this IRegistrationBuilder <TLimit, TActivatorData, TSingleRegistrationStyle> registration, Action <ExportConfigurationBuilder> configurationAction) where TSingleRegistrationStyle : SingleRegistrationStyle { if (registration == null) { throw new ArgumentNullException("registration"); } if (configurationAction == null) { throw new ArgumentNullException("configurationAction"); } var configuration = new ExportConfigurationBuilder(); configurationAction(configuration); registration.OnRegistered(e => AttachExport(e.ComponentRegistry, e.ComponentRegistration, configuration)); return(registration); }
static void AttachExport(IComponentRegistry registry, IComponentRegistration registration, ExportConfigurationBuilder exportConfiguration) { var contractService = new ContractBasedService(exportConfiguration.ContractName, exportConfiguration.ExportTypeIdentity); var service = registration.Services.FirstOrDefault(); var rb = RegistrationBuilder.ForDelegate((c, p) => new Export( new ExportDefinition(exportConfiguration.ContractName, exportConfiguration.Metadata), () => c.ResolveComponent(service, registration, new Parameter[0]))) .As(contractService) .ExternallyOwned() .WithMetadata(exportConfiguration.Metadata); registry.Register(rb.CreateRegistration()); }