public void CanSpecifyScope() { var container = new Container(); container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle(); container.Register <IoCApp>(Lifestyle.Scoped); container.Register <ISomeIoCService, SomeIoCService>(Lifestyle.Scoped); ISomeIoCService svcBeforeRun; using (var scope = AsyncScopedLifestyle.BeginScope(container)) { svcBeforeRun = container.GetInstance <ISomeIoCService>(); } var result = new AppRunner <IoCApp>() .TrackingInvocations() .UseSimpleInjector(container, runInScope: ctx => AsyncScopedLifestyle.BeginScope(container)) .RunInMem("Do"); var app = result.CommandContext.GetCommandInvocationInfo <IoCApp>().Instance; app !.FromCtor.Should().BeSameAs(app.FromInterceptor); app.FromCtor.Should().NotBeSameAs(svcBeforeRun); }
public void CanSpecifyScope() { var serviceProvider = ConfigureMicrosoftServiceProvider(); ISomeIoCService svcBeforeRun; using (var scope = serviceProvider.CreateScope()) { svcBeforeRun = serviceProvider.GetRequiredService <ISomeIoCService>(); } var result = new AppRunner <IoCApp>() .UseMicrosoftDependencyInjection(serviceProvider, runInScope: ctx => serviceProvider.CreateScope()) .RunInMem("Do"); var app = result.CommandContext.GetCommandInvocationInfo <IoCApp>().Instance; app !.FromCtor.Should().BeSameAs(app.FromInterceptor); // TODO: why is this the same instance? //app.FromCtor.Should().NotBeSameAs(svcBeforeRun); }
public void CanSpecifyScope() { var container = ConfigureAutofacContainer(); ISomeIoCService svcBeforeRun; using (var scope = container.BeginLifetimeScope(LifetimeScopeTag)) { svcBeforeRun = container.Resolve <ISomeIoCService>(); } var result = new AppRunner <IoCApp>() .UseAutofac(container, runInScope: ctx => container.BeginLifetimeScope(LifetimeScopeTag)) .RunInMem("Do"); var app = result.CommandContext.GetCommandInvocationInfo <IoCApp>().Instance; app !.FromCtor.Should().BeSameAs(app.FromInterceptor); // TODO: why is this the same instance? //app.FromCtor.Should().NotBeSameAs(svcBeforeRun); }