protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection)
        {
            var factory   = new WindsorServiceProviderFactory();
            var container = factory.CreateBuilder(serviceCollection);

            return(factory.CreateServiceProvider(container));
        }
        public async Task Should_resolve_dependencies_from_serviceprovider()
        {
            IWindsorContainer container       = null;
            IServiceProvider  serviceProvider = null;

            var context = await Scenario.Define <Context>()
                          .WithEndpoint <EndpointWithExternallyManagedContainer>(endpointBuilder =>
            {
                var serviceCollection = new ServiceCollection();
                // register service using the IServiceCollection API:
                serviceCollection.AddSingleton <ServiceCollectionService>();

                // register service using the NServiceBus container API:
                endpointBuilder.CustomConfig(endpointConfiguration => endpointConfiguration
                                             .RegisterComponents(c => c
                                                                 .RegisterSingleton(new InternalApiService())));

                endpointBuilder.ToCreateInstance(
                    configuration => Task.FromResult(EndpointWithExternallyManagedServiceProvider
                                                     .Create(configuration, serviceCollection)),
                    startableEndpoint =>
                {
                    var windsorFactory = new WindsorServiceProviderFactory();
                    container          = windsorFactory.CreateBuilder(serviceCollection);
                    // register service using the container native API:
                    container.Register(Component.For <NativeApiService>().LifeStyle.Singleton);

                    serviceProvider = windsorFactory.CreateServiceProvider(container);
                    return(startableEndpoint.Start(serviceProvider));
                });

                endpointBuilder.When(session => session.SendLocal(new TestMessage()));
            })
                          .Done(c => c.InjectedInternalApiService != null)
                          .Run();

            Assert.AreSame(context.InjectedNativeApiService, container.Resolve <NativeApiService>());
            Assert.AreSame(context.InjectedNativeApiService, serviceProvider.GetService <NativeApiService>());
            Assert.AreSame(context.InjectedInternalApiService, container.Resolve <InternalApiService>());
            Assert.AreSame(context.InjectedInternalApiService, serviceProvider.GetService <InternalApiService>());
            Assert.AreSame(context.InjectedServiceCollectionService, container.Resolve <ServiceCollectionService>());
            Assert.AreSame(context.InjectedServiceCollectionService, serviceProvider.GetService <ServiceCollectionService>());
        }