Created
January 7, 2013 13:58
-
-
Save mwjackson/4475177 to your computer and use it in GitHub Desktop.
SM init code
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 StructureMapConfiguration | |
{ | |
public static void Initialise(IEnumerable<Assembly> assembliesToScan, params Action<IInitializationExpression>[] extraConfigs) | |
{ | |
ObjectFactory.Initialize(config => | |
{ | |
config.Scan(scan => | |
{ | |
foreach(var assembly in assembliesToScan) | |
{ | |
scan.Assembly(assembly); | |
} | |
scan.AssemblyContainingType<FeedsConfig>(); | |
scan.RegisterConcreteTypesAgainstTheFirstInterface(); | |
scan.LookForRegistries(); | |
scan.WithDefaultConventions(); | |
}); | |
config.For<SqlConnection>().HybridHttpOrThreadLocalScoped().Use(() => | |
{ | |
var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SunshineDb"].ConnectionString); | |
conn.Open(); | |
return conn; | |
}); | |
foreach (var extraConfig in extraConfigs) | |
{ | |
extraConfig(config); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment