Created
April 17, 2014 13:43
-
-
Save mgroves/10984484 to your computer and use it in GitHub Desktop.
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
| // This is StructureMap 2.x | |
| using StructureMap; | |
| public static class IoC { | |
| public static IContainer Initialize() { | |
| ObjectFactory.Initialize(x => | |
| { | |
| // ... snip ... | |
| x.For<IDbConnection>().HttpContextScoped().Use(GetConnection); | |
| }); | |
| return ObjectFactory.Container; | |
| } | |
| static SqlConnection GetConnection() | |
| { | |
| // .. return a SqlConnection or whatever | |
| } | |
| } |
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
| // This is StructureMap 3.x with StructureMap.Web | |
| using StructureMap; | |
| using StructureMap.Web.Pipeline; | |
| public static class IoC { | |
| public static IContainer Initialize() { | |
| ObjectFactory.Initialize(x => | |
| { | |
| // ... snip ... | |
| x.For<IDbConnection>().Use("Getting Sql Connection", GetConnection).LifecycleIs<HttpContextLifecycle>(); | |
| }); | |
| return ObjectFactory.Container; | |
| } | |
| static IDbConnection GetConnection() | |
| { | |
| // .. return a SqlConection or whatever | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment