Created
November 14, 2009 03:15
-
-
Save dvhthomas/234357 to your computer and use it in GitHub Desktop.
Heartbeat monitor IoC registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Configuration; | |
using CityIQ.HealthMonitor.Notifiers; | |
using CityIQ.HealthMonitor.Testers; | |
using StructureMap.Attributes; | |
using StructureMap.Configuration.DSL; | |
namespace CityIQ.HealthMonitor | |
{ | |
public class HeartbeatRegistry : Registry | |
{ | |
private const string CircuitBreakerThreshold = "Circuit.Breaker.Threshold"; | |
public HeartbeatRegistry() | |
{ | |
TimeSpan circuitBreakerTimeout = ConfiguredTimeSpan("Circuit.Breaker.Timeout.Seconds"); | |
TimeSpan websiteTimeout = ConfiguredTimeSpan("Website.Timeout.Seconds"); | |
// All notification methods | |
ForRequestedType<INotifier>() | |
.AddInstances(x => x.OfConcreteType<ConsoleNotifier>().WithName("console")) | |
.TheDefault.Is.TheInstanceNamed("console"); | |
// Default circuit breaker - use this for web tests | |
ForRequestedType<ICircuitBreaker>() | |
.CacheBy(InstanceScope.Singleton) | |
.TheDefault.Is.OfConcreteType<CircuitBreaker>() | |
.WithCtorArg("threshold").EqualToAppSetting(CircuitBreakerThreshold) | |
.CtorDependency<TimeSpan>().Is(circuitBreakerTimeout); | |
// Circuit breaker for db tests | |
ForRequestedType<ICircuitBreaker>().AsSingletons() | |
.AddInstances(x => | |
{ | |
x.OfConcreteType<CircuitBreaker>() | |
.WithName("SpatialDb") | |
.WithCtorArg("threshold").EqualToAppSetting(CircuitBreakerThreshold) | |
.CtorDependency<TimeSpan>().Is(circuitBreakerTimeout); | |
x.OfConcreteType<CircuitBreaker>() | |
.WithName("Map") | |
.WithCtorArg("threshold").EqualToAppSetting(CircuitBreakerThreshold) | |
.CtorDependency<TimeSpan>().Is(circuitBreakerTimeout); | |
}); | |
ForRequestedType<IResourceTester>().TheDefault.Is.OfConcreteType<WebSite>() | |
.WithCtorArg("name").EqualTo("CityIQ") | |
.WithCtorArg("target").EqualToAppSetting("CityIQ.Url") | |
.CtorDependency<TimeSpan>().Is(websiteTimeout); | |
ForRequestedType<IHeartbeatMonitor>().TheDefaultIsConcreteType<HeartbeatMonitor>(); | |
} | |
private static TimeSpan ConfiguredTimeSpan(string key) | |
{ | |
return TimeSpan.FromSeconds(Convert.ToDouble(ConfigurationManager.AppSettings[key])); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment