Created
April 7, 2011 16:01
-
-
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
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
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