Last active
December 11, 2015 12:38
-
-
Save droyad/4602086 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
| protected override void Load(ContainerBuilder builder) | |
| { | |
| builder.Register(CreatedDbFunc).As<Func<Owned<IDb>>>().InstancePerDependency(); | |
| builder.Register(c => CreatedDbWithConnectionFunc()).As<Func<DbConnection, Owned<IDb>>>().InstancePerDependency(); | |
| builder.RegisterType<CurrentDatabase>().InstancePerMatchingLifetimeScope(LifetimeScopes.Workspace); | |
| } | |
| private Func<Owned<IDb>> CreatedDbFunc(IComponentContext context) | |
| { | |
| var currentDbFunc = context.Resolve<Func<CurrentDatabase>>(); | |
| return () => | |
| { | |
| var db = new Db(currentDbFunc()); | |
| return new Owned<IDb>(db, db); | |
| }; | |
| } | |
| private Func<DbConnection, Owned<IDb>> CreatedDbWithConnectionFunc() | |
| { | |
| return connection => | |
| { | |
| var db = new Db(connection); | |
| return new Owned<IDb>(db, db); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment