public static ExternallyManagedContainerHost CreateWithExternallyManagedContainer(EndpointConfiguration endpointConfiguration, IServiceCollection serviceCollection) { var settings = endpointConfiguration.Settings; CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings); var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings); endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes); var hostingSettings = settings.Get <HostingComponent.Settings>(); var hostingConfiguration = HostingComponent.PrepareConfiguration(hostingSettings, assemblyScanningComponent, serviceCollection); hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = "external" }); var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration); var hostingComponent = HostingComponent.Initialize(hostingConfiguration, serviceCollection, false); var externallyManagedContainerHost = new ExternallyManagedContainerHost(endpointCreator, hostingComponent); return(externallyManagedContainerHost); }
public static async Task <IStartableEndpoint> CreateWithInternallyManagedContainer(EndpointConfiguration endpointConfiguration, CancellationToken cancellationToken = default) { var settings = endpointConfiguration.Settings; CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings); var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings); endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes); var serviceCollection = new ServiceCollection(); var hostingConfiguration = HostingComponent.PrepareConfiguration(settings.Get <HostingComponent.Settings>(), assemblyScanningComponent, serviceCollection); hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = "internal" }); var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration); var hostingComponent = HostingComponent.Initialize(hostingConfiguration, serviceCollection, true); var serviceProvider = serviceCollection.BuildServiceProvider(); var startableEndpoint = endpointCreator.CreateStartableEndpoint(serviceProvider, hostingComponent); hostingComponent.RegisterBuilder(serviceProvider); await hostingComponent.RunInstallers(cancellationToken).ConfigureAwait(false); return(new InternallyManagedContainerHost(startableEndpoint, hostingComponent)); }
public static async Task <IStartableEndpoint> CreateWithInternallyManagedContainer(EndpointConfiguration endpointConfiguration) { var settings = endpointConfiguration.Settings; CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings); var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings); endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes); var hostingSetting = settings.Get <HostingComponent.Settings>(); var useDefaultBuilder = hostingSetting.CustomObjectBuilder == null; var container = useDefaultBuilder ? new LightInjectObjectBuilder() : hostingSetting.CustomObjectBuilder; var commonObjectBuilder = new CommonObjectBuilder(container); IConfigureComponents internalContainer = commonObjectBuilder; IBuilder internalBuilder = commonObjectBuilder; //for backwards compatibility we need to make the IBuilder available in the container internalContainer.ConfigureComponent(_ => internalBuilder, DependencyLifecycle.SingleInstance); var hostingConfiguration = HostingComponent.PrepareConfiguration(settings.Get <HostingComponent.Settings>(), assemblyScanningComponent, internalContainer); if (useDefaultBuilder) { hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = "internal" }); } else { var containerType = internalContainer.GetType(); hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = containerType.FullName, Version = FileVersionRetriever.GetFileVersion(containerType) }); } var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration); var hostingComponent = HostingComponent.Initialize(hostingConfiguration); var startableEndpoint = endpointCreator.CreateStartableEndpoint(internalBuilder, hostingComponent); hostingComponent.RegisterBuilder(internalBuilder, true); await hostingComponent.RunInstallers().ConfigureAwait(false); return(new InternallyManagedContainerHost(startableEndpoint, hostingComponent)); }
public async Task <IEndpointInstance> Start(IBuilder builder) { objectBuilder = builder; var hostingComponent = HostingComponent.Initialize(hostingConfiguration, null); var startableEndpoint = await endpointCreator.CreateStartableEndpoint(builder, hostingComponent).ConfigureAwait(false); var endpointInstance = await startableEndpoint.Start().ConfigureAwait(false); messageSession = endpointInstance; return(endpointInstance); }
public async Task <IEndpointInstance> Start(IServiceProvider externalBuilder) { objectBuilder = externalBuilder; var hostingComponent = HostingComponent.Initialize(hostingConfiguration); var startableEndpoint = endpointCreator.CreateStartableEndpoint(externalBuilder, hostingComponent); hostingComponent.RegisterBuilder(externalBuilder, false); await hostingComponent.RunInstallers().ConfigureAwait(false); var endpointInstance = await hostingComponent.Start(startableEndpoint).ConfigureAwait(false); messageSession = endpointInstance; return(endpointInstance); }
public static async Task <IStartableEndpoint> CreateWithInternallyManagedContainer(EndpointConfiguration endpointConfiguration) { var settings = endpointConfiguration.Settings; CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings); var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings); endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes); var serviceCollection = new MicrosoftExtensionsDependencyInjection.ServiceCollection(); var hostingConfiguration = HostingComponent.PrepareConfiguration(settings.Get <HostingComponent.Settings>(), assemblyScanningComponent, serviceCollection); hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = "internal" }); var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration); var hostingComponent = HostingComponent.Initialize(hostingConfiguration); var containerOptions = new ContainerOptions { EnableVariance = false }.WithMicrosoftSettings(); var serviceProvider = serviceCollection.CreateLightInjectServiceProvider(containerOptions); var startableEndpoint = endpointCreator.CreateStartableEndpoint(serviceProvider, hostingComponent); hostingComponent.RegisterBuilder(serviceProvider, true); await hostingComponent.RunInstallers().ConfigureAwait(false); return(new InternallyManagedContainerHost(startableEndpoint, hostingComponent)); }
void Initialize() { containerComponent.ContainerConfiguration.RegisterSingleton <ReadOnlySettings>(settings); RegisterCriticalErrorHandler(); var concreteTypes = settings.GetAvailableTypes() .Where(IsConcrete) .ToList(); featureComponent = new FeatureComponent(settings); // This needs to happen here to make sure that features enabled state is present in settings so both // IWantToRunBeforeConfigurationIsFinalized implementations and transports can check access it featureComponent.RegisterFeatureEnabledStatusInSettings(concreteTypes); ConfigRunBeforeIsFinalized(concreteTypes); transportComponent = TransportComponent.Initialize(settings.Get <TransportComponent.Configuration>(), settings); var receiveConfiguration = BuildReceiveConfiguration(transportComponent); var routingComponent = new RoutingComponent(settings); var pipelineSettings = settings.Get <PipelineSettings>(); routingComponent.Initialize(transportComponent, pipelineSettings, receiveConfiguration); var messageMapper = new MessageMapper(); settings.Set <IMessageMapper>(messageMapper); recoverabilityComponent = new RecoverabilityComponent(settings); var featureConfigurationContext = new FeatureConfigurationContext(settings, containerComponent.ContainerConfiguration, pipelineSettings, routingComponent, receiveConfiguration); featureComponent.Initalize(containerComponent, featureConfigurationContext); //The settings can only be locked after initializing the feature component since it uses the settings to store & share feature state. settings.PreventChanges(); hostingComponent = HostingComponent.Initialize(settings.Get <HostingComponent.Configuration>(), containerComponent, pipelineSettings); recoverabilityComponent.Initialize(receiveConfiguration, hostingComponent); pipelineComponent = PipelineComponent.Initialize(pipelineSettings, containerComponent); pipelineComponent.AddRootContextItem <IMessageMapper>(messageMapper); containerComponent.ContainerConfiguration.ConfigureComponent(b => settings.Get <Notifications>(), DependencyLifecycle.SingleInstance); var eventAggregator = new EventAggregator(settings.Get <NotificationSubscriptions>()); pipelineComponent.AddRootContextItem <IEventAggregator>(eventAggregator); receiveComponent = ReceiveComponent.Initialize(receiveConfiguration, transportComponent, pipelineComponent, eventAggregator, criticalError, settings.ErrorQueueAddress(), hostingComponent); installationComponent = InstallationComponent.Initialize(settings.Get <InstallationComponent.Configuration>(), concreteTypes, containerComponent, transportComponent); settings.AddStartupDiagnosticsSection("Endpoint", new { Name = settings.EndpointName(), SendOnly = settings.Get <bool>("Endpoint.SendOnly"), NServiceBusVersion = GitVersionInformation.MajorMinorPatch } ); }