protected override void OnApplicationStarting(object sender, EventArgs e) { _containerBootstrapper = ContainerBootstrapper.Bootstrap(); // setup the webapi dependency resolver to use Castle Windsor GlobalConfiguration.Configuration.DependencyResolver = new WindsorResolver(_containerBootstrapper.Container); AutoMapperConfig.RegisterAutoMapper(); base.OnApplicationStarting(sender, e); }
public void BootstrappingUsingAssemblyParamListShouldContainTypesInParamList() { var sut = new ContainerBootstrapper(); sut.Should().NotBeNull(); var result = sut.Bootstrap(null, typeof(Samples.Business.BusinessDependencyRegistrar).Assembly, typeof(Samples.Data.DataDependencyRegistrar).Assembly); result.Should().NotBeNull(); result.Catalog.Should().NotBeNull(); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Heliar.Composition.Core.Tests.TestApplicationDependencyRegistrar"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Business.BusinessDependencyRegistrar"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Data.DataDependencyRegistrar"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Heliar.Composition.Core.Tests.Foo"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Business.CustomerService"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Data.CustomerRepository"); }
public static async Task <TReturn> Run <TFunction, TReturn>(TraceWriter writer, ExecutionContext executionContext, Func <IContainer, ILog, Task <TReturn> > runAction) where TFunction : IFunction { try { var container = ContainerBootstrapper.Bootstrap(writer, executionContext); using (var nestedContainer = CreateNestedContainer <TFunction>(writer, container)) { using (StartTelemetryScope <TFunction>(nestedContainer)) { return(await runAction(nestedContainer, nestedContainer.GetInstance <ILog>())); } } } catch (Exception ex) { writer.Error($"Error invoking function: {typeof(TFunction)}.", ex); throw; } }
public static async Task Run <TFunction>(TraceWriter writer, ExecutionContext executionContext, Func <IContainer, ILog, Task> runAction) where TFunction : IFunction { try { var container = ContainerBootstrapper.Bootstrap(writer, executionContext); using (var nestedContainer = CreateNestedContainer <TFunction>(writer, container)) { using (StartTelemetryScope <TFunction>(nestedContainer)) //TODO: might be ok to wait for container to be disposed. in that case can get rid of this scope { await runAction(nestedContainer, nestedContainer.GetInstance <ILog>()); } } } catch (Exception ex) { writer.Error($"Error invoking function: {typeof(TFunction)}.", ex); throw; } }
public static void PreStart() { _bootstrapper = ContainerBootstrapper.Bootstrap(); }
public void BootstrappingUsingCatalogAndConventionShouldIncludeTestAndSampleParts() { // Build pre-wired assembly catalog RegistrationBuilder conventions = new RegistrationBuilder(); conventions.ForTypesDerivedFrom<IApplicationDependencyRegistrar>() .SetCreationPolicy(CreationPolicy.Shared) .ExportInterfaces() .Export(); var catalog = new AssemblyCatalog(typeof(ContainerBootstrapperTest).Assembly, conventions); var sut = new ContainerBootstrapper("Samples*.dll", catalog); sut.Should().NotBeNull(); var result = sut.Bootstrap(); result.Should().NotBeNull(); result.Catalog.Should().NotBeNull(); // Registrars result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Heliar.Composition.Core.Tests.TestApplicationDependencyRegistrar"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Business.BusinessDependencyRegistrar"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Data.DataDependencyRegistrar"); // Test/Sample types result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Heliar.Composition.Core.Tests.Foo"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Business.CustomerService"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Data.CustomerRepository"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Data.SampleConnectionFactory"); }
public void TypesRegisteredInExternalAssemblyShouldBeCreateable() { var sut = new ContainerBootstrapper(); sut.Should().NotBeNull(); var container = sut.Bootstrap(); container.Should().NotBeNull(); var client = container.GetExportedValue<HttpClient>(); client.Should().NotBeNull(); }
public void BootstrappingWithoutApplicationDependencyRegistrarShouldThrowException() { var sut = new ContainerBootstrapper("Foo*.dll"); sut.Should().NotBeNull(); var result = sut.Bootstrap(); }
public void BootstrappingUsingOnlyConventionShouldOnlyIncludeTestAssemblyTypes() { var sut = new ContainerBootstrapper(assemblyExpression); sut.Should().NotBeNull(); var result = sut.Bootstrap(); result.Should().NotBeNull(); result.Catalog.Parts.Should().HaveCount(c => c > 0); // Registrar types result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Heliar.Composition.Core.Tests.TestApplicationDependencyRegistrar"); result.Catalog.Parts.Should().NotContain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Business.BusinessDependencyRegistrar"); result.Catalog.Parts.Should().NotContain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Data.DataDependencyRegistrar"); // Test POCO type result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Heliar.Composition.Core.Tests.Foo"); }
public void BootstrappingUsingOnlyCatalogShouldIncludeTestAndSampleTypes() { var catalog = new AssemblyCatalog(typeof(CatalogBootstrapperTest).Assembly); var sut = new ContainerBootstrapper(null, catalog); sut.Should().NotBeNull(); var result = sut.Bootstrap(); result.Should().NotBeNull(); result.Catalog.Should().NotBeNull(); // Registrars result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Heliar.Composition.Core.Tests.TestApplicationDependencyRegistrar"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Business.BusinessDependencyRegistrar"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Data.DataDependencyRegistrar"); // Test/Sample types result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Heliar.Composition.Core.Tests.Foo"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Business.CustomerService"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Data.CustomerRepository"); result.Catalog.Parts.Should().Contain(p => (p as System.ComponentModel.Composition.Primitives.ICompositionElement).DisplayName == "Samples.Data.SampleConnectionFactory"); }
public static CompositionContainer Configure() { var bootstrapper = new ContainerBootstrapper(); return(bootstrapper.Bootstrap()); }