public void Builders_should_not_determine_existence_by_building_components() { var serviceCollection = new ServiceCollection(); InitializeBuilder(serviceCollection); Assert.True(serviceCollection.HasComponent(typeof(ExistingComponentWithUnsatisfiedDependency))); }
public void Existing_components_should_return_true() { var serviceCollection = new ServiceCollection(); InitializeBuilder(serviceCollection); Assert.True(serviceCollection.HasComponent(typeof(ExistingComponent))); }
public void Non_existing_components_should_return_false() { var serviceCollection = new ServiceCollection(); InitializeBuilder(serviceCollection); Assert.False(serviceCollection.HasComponent(typeof(NonExistingComponent))); }
public void Should_dispose_all_IDisposable_components() { var serviceCollection = new ServiceCollection(); DisposableComponent.DisposeCalled = false; AnotherSingletonComponent.DisposeCalled = false; serviceCollection.AddSingleton(typeof(DisposableComponent)); serviceCollection.AddSingleton(typeof(AnotherSingletonComponent), new AnotherSingletonComponent()); var builder = BuildContainer(serviceCollection); builder.GetService(typeof(DisposableComponent)); builder.GetService(typeof(AnotherSingletonComponent)); (builder as IDisposable)?.Dispose(); Assert.True(DisposableComponent.DisposeCalled, "Dispose should be called on DisposableComponent"); Assert.False(AnotherSingletonComponent.DisposeCalled, "Dispose should not be called on AnotherSingletonComponent"); }
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)); }