Skip to content

Instantly share code, notes, and snippets.

@ruslander
Created April 7, 2011 16:01
Show Gist options
  • Save ruslander/908074 to your computer and use it in GitHub Desktop.
Save ruslander/908074 to your computer and use it in GitHub Desktop.
Track explicitly all application dependencies, verify them before letting the business to go wrong
public class AppDependencies
{
public static void AreAllSatisfied()
{
IsValidConnectionString();
IoC.AllTheTypesAreResolvable();
var appConfig = IoC.Resolve<IAppConfig>();
AssertDirectoryExists(appConfig.Logs);
AssertDirectoryExists(appConfig.Assets);
AssertDirectoryExists(appConfig.Temp);
IsFtpConfigured();
}
private static void IsFtpConfigured()
{
try{
var ftpProxy = IoC.Resolve<IFtpProxy>();
ftpProxy.GetFiles(@"\");
}
catch (Exception e){
throw new InvalidOperationException("The Ftp configuration is invalid.", e);
}
}
private static void AssertDirectoryExists(string path)
{
if (Directory.Exists(path) == false)
throw new InvalidOperationException(string.Format("The directory for '{0}' path does not exist.", path));
}
private static void IsValidConnectionString()
{
try{
using (SqlConnection conn = FluentCommandConnectionFactory.GetConnection()){
// this will force to get a open connection
}
}
catch (Exception e){
throw new InvalidOperationException("The connection string is invalid.", e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment