コード例 #1
0
        public static StartableEndpointWithExternallyManagedContainer CreateWithExternallyManagedContainer(EndpointConfiguration endpointConfiguration, IConfigureComponents externalContainer)
        {
            var settings = endpointConfiguration.Settings;

            var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings);

            FinalizeConfiguration(endpointConfiguration, assemblyScanningComponent.AvailableTypes);

            var hostingSettings = settings.Get <HostingComponent.Settings>();

            var hostingConfiguration = HostingComponent.PrepareConfiguration(hostingSettings, assemblyScanningComponent, externalContainer);

            if (hostingSettings.CustomObjectBuilder != null)
            {
                throw new InvalidOperationException("An internally managed container has already been configured using 'EndpointConfiguration.UseContainer'. It is not possible to use both an internally managed container and an externally managed container.");
            }

            hostingConfiguration.AddStartupDiagnosticsSection("Container", new
            {
                Type = "external"
            });

            var endpointCreator = new EndpointCreator(settings, hostingConfiguration);

            endpointCreator.Initialize();

            var startableEndpoint = new StartableEndpointWithExternallyManagedContainer(endpointCreator, hostingConfiguration);

            //for backwards compatibility we need to make the IBuilder available in the container
            externalContainer.ConfigureComponent(_ => startableEndpoint.Builder.Value, DependencyLifecycle.SingleInstance);

            return(startableEndpoint);
        }
コード例 #2
0
        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 externallyManagedContainerHost = new ExternallyManagedContainerHost(endpointCreator, hostingConfiguration);

            return(externallyManagedContainerHost);
        }
コード例 #3
0
ファイル: Endpoint.cs プロジェクト: zheng1748/NServiceBus
        /// <summary>
        /// Creates a new startable endpoint based on the provided configuration.
        /// </summary>
        /// <param name="configuration">Configuration.</param>
        public static Task <IStartableEndpoint> Create(EndpointConfiguration configuration)
        {
            Guard.AgainstNull(nameof(configuration), configuration);

            return(EndpointCreator
                   .CreateWithInternallyManagedContainer(configuration));
        }
コード例 #4
0
ファイル: HostCreator.cs プロジェクト: wzl-bxg/NServiceBus
        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));
        }
コード例 #5
0
        /// <summary>
        /// Creates a new startable endpoint based on the provided configuration that uses an externally managed container.
        /// </summary>
        /// <param name="configuration">The endpoint configuration.</param>
        /// <param name="configureComponents">The registration API adapter for the external container.</param>
        public static IStartableEndpointWithExternallyManagedContainer Create(EndpointConfiguration configuration, IConfigureComponents configureComponents)
        {
            Guard.AgainstNull(nameof(configuration), configuration);
            Guard.AgainstNull(nameof(configureComponents), configureComponents);

            return(EndpointCreator
                   .CreateWithExternallyManagedContainer(configuration, configureComponents));
        }
コード例 #6
0
        public static EndpointCreator Create(SettingsHolder settings, HostingComponent.Configuration hostingConfiguration)
        {
            var endpointCreator = new EndpointCreator(settings, hostingConfiguration, settings.Get <Conventions>());

            endpointCreator.Initialize();

            return(endpointCreator);
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        public static Task <IStartableEndpoint> CreateWithInternallyManagedContainer(EndpointConfiguration endpointConfiguration)
        {
            FinalizeConfiguration(endpointConfiguration);

            endpointConfiguration.ContainerComponent.InitializeWithInternallyManagedContainer();

            var creator = new EndpointCreator(endpointConfiguration.Settings, endpointConfiguration.ContainerComponent, endpointConfiguration.PipelineComponent);

            creator.Initialize();

            return(creator.CreateStartableEndpoint());
        }
コード例 #9
0
        public static StartableEndpointWithExternallyManagedContainer CreateWithExternallyManagedContainer(EndpointConfiguration endpointConfiguration, IConfigureComponents configureComponents)
        {
            FinalizeConfiguration(endpointConfiguration);

            endpointConfiguration.ContainerComponent.InitializeWithExternallyManagedContainer(configureComponents);

            var creator = new EndpointCreator(endpointConfiguration.Settings, endpointConfiguration.ContainerComponent, endpointConfiguration.PipelineComponent);

            creator.Initialize();

            return(new StartableEndpointWithExternallyManagedContainer(creator));
        }
コード例 #10
0
        public StartableEndpointWithExternallyManagedContainer(EndpointCreator endpointCreator)
        {
            this.endpointCreator = endpointCreator;

            MessageSession = new Lazy<IMessageSession>(() =>
            {
                if (messageSession == null)
                {
                    throw new InvalidOperationException("The message session can only be used after the endpoint is started.");
                }
                return messageSession;
            });
        }
コード例 #11
0
        public ExternallyManagedContainerHost(EndpointCreator endpointCreator, HostingComponent hostingComponent)
        {
            this.endpointCreator  = endpointCreator;
            this.hostingComponent = hostingComponent;

            MessageSession = new Lazy <IMessageSession>(() =>
            {
                if (messageSession == null)
                {
                    throw new InvalidOperationException("The message session can only be used after the endpoint is started.");
                }
                return(messageSession);
            });

            Builder = new Lazy <IServiceProvider>(() =>
            {
                if (objectBuilder == null)
                {
                    throw new InvalidOperationException("The builder can only be used after the endpoint is started.");
                }
                return(objectBuilder);
            });
        }
        public StartableEndpointWithExternallyManagedContainer(EndpointCreator endpointCreator, HostingComponent.Configuration hostingConfiguration)
        {
            this.endpointCreator      = endpointCreator;
            this.hostingConfiguration = hostingConfiguration;

            MessageSession = new Lazy <IMessageSession>(() =>
            {
                if (messageSession == null)
                {
                    throw new InvalidOperationException("The message session can only be used after the endpoint is started.");
                }
                return(messageSession);
            });

            Builder = new Lazy <IBuilder>(() =>
            {
                if (objectBuilder == null)
                {
                    throw new InvalidOperationException("The builder can only be used after the endpoint is started.");
                }
                return(objectBuilder);
            });
        }
コード例 #13
0
        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));
        }