Created
August 17, 2013 09:29
-
-
Save JakeGinnivan/6256092 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
| var cb = new ContainerBuilder(); | |
| cb.RegisterType<Foo>().As<IFoo>().InstancePerLifetimeScope(); | |
| cb.RegisterType<Bar>().As<IBar>().InstancePerMatchingLifetimeScope("LifetimeScopeTag"); | |
| var container = cb.Build(); | |
| using (var scope = container.BeginLifetimeScope("LifetimeScopeTag")) | |
| { | |
| IFoo foo1; | |
| IFoo foo2; | |
| IBar bar1; | |
| IBar bar2; | |
| using (var scope2 = scope.BeingLifetimeScope()) | |
| { | |
| foo1 = scope2.Resolve<IFoo>(); | |
| bar1 = scope2.Resolve<IBar>(); | |
| } | |
| using (var scope3 = scope.BeingLifetimeScope()) | |
| { | |
| foo2 = scope3.Resolve<IFoo>(); | |
| bar2 = scope3.Resolve<IBar>(); | |
| } | |
| Assert.NotSame(foo1, foo2); | |
| Assert.Same(bar1, bar2); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment