public void Discovery_should_monitors_that_cannot_be_instantiated() { var expected = new[] { typeof(HttpMonitor), typeof(HttpJsonMonitor) }; var monitors = MonitorDiscovery.DiscoverAll( typeof(BrokenMonitor).Assembly.Location, typeof(HttpMonitor).Assembly.Location); CollectionAssert.AreEquivalent(expected, monitors.Select(p => p.GetType())); }
public void Discovery_should_scan_given_assembly_only_once() { var expected = new[] { typeof(HttpMonitor), typeof(HttpJsonMonitor) }; var monitors = MonitorDiscovery.DiscoverAll( typeof(HttpMonitor).Assembly.Location, typeof(HttpMonitor).Assembly.Location ); CollectionAssert.AreEquivalent(expected, monitors.Select(p => p.GetType())); }
public void Discovery_should_skip_assemblies_that_cannot_be_loaded() { var expected = new[] { typeof(HttpMonitor), typeof(HttpJsonMonitor) }; var monitors = MonitorDiscovery.DiscoverAll( "some_inexistent_assembly.dll", typeof(HttpMonitor).Assembly.Location); CollectionAssert.AreEquivalent(expected, monitors.Select(p => p.GetType())); }
public void Discovery_should_load_and_instantiate_all_monitors() { var expected = new[] { typeof(HttpMonitor), typeof(HttpJsonMonitor), typeof(TestHealthMonitor), typeof(TestHealthMonitor2) }; var monitors = MonitorDiscovery.DiscoverAll( typeof(HttpMonitor).Assembly.Location, typeof(TestHealthMonitor).Assembly.Location); CollectionAssert.AreEquivalent(expected, monitors.Select(p => p.GetType())); }
private static IContainer StartHost() { var exchangeClient = new HealthMonitorExchangeClient(ConfigurationManager.AppSettings["HealthMonitoringUrl"]); var settings = LoadSettings(exchangeClient); var builder = new ContainerBuilder(); builder.RegisterAssemblyTypes(typeof(HealthMonitorRegistry).Assembly).AsSelf().AsImplementedInterfaces().SingleInstance(); builder.RegisterInstance(exchangeClient).AsSelf().AsImplementedInterfaces(); builder.RegisterInstance(settings.MonitorSettings).AsImplementedInterfaces(); builder.RegisterInstance(settings.ThrottlingSettings).AsImplementedInterfaces(); builder.RegisterInstance(AppSettingsDataExchangeConfigProvider.ReadConfiguration()); builder.Register(c => new ThrottlingSampler(c.Resolve <HealthSampler>(), c.Resolve <IThrottlingSettings>())).AsImplementedInterfaces(); builder.RegisterInstance <IHealthMonitorRegistry>(new HealthMonitorRegistry(MonitorDiscovery.DiscoverAllInCurrentFolder())); builder.RegisterType <EndpointMonitor>().AsSelf().AsImplementedInterfaces().SingleInstance(); builder.RegisterType <MonitorDataExchange>().AsSelf().AsImplementedInterfaces().SingleInstance(); var container = builder.Build(); container.Resolve <EndpointMonitor>(); return(container); }
private void ConfigureDependencies(HttpConfiguration config) { var builder = new ContainerBuilder(); builder.RegisterAssemblyTypes(typeof(Program).Assembly).Where(t => typeof(ApiController).IsAssignableFrom(t)).AsSelf(); builder.RegisterAssemblyTypes(typeof(HealthMonitorRegistry).Assembly).AsSelf().AsImplementedInterfaces().SingleInstance(); builder.RegisterAssemblyTypes(typeof(SqlEndpointConfigurationStore).Assembly).AsSelf().AsImplementedInterfaces().SingleInstance(); builder.Register(c => new ThrottlingSampler(c.Resolve <HealthSampler>(), c.Resolve <IThrottlingSettings>())).AsImplementedInterfaces(); builder.RegisterInstance <IHealthMonitorRegistry>(new HealthMonitorRegistry(MonitorDiscovery.DiscoverAllInCurrentFolder())); var container = builder.Build(); container.Resolve <EndpointMonitor>(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); }