Esempio n. 1
0
        public void CanSpecifyScope()
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
            container.Register <App>(Lifestyle.Scoped);
            container.Register <ISomeService, SomeService>(Lifestyle.Scoped);

            ISomeService svcBeforeRun;

            using (var scope = AsyncScopedLifestyle.BeginScope(container))
            {
                svcBeforeRun = container.GetInstance <ISomeService>();
            }

            var testOutputs = new AppRunner <App>()
                              .UseSimpleInjector(container, runInScope: ctx => AsyncScopedLifestyle.BeginScope(container))
                              .RunInMem("Do", _testOutputHelper)
                              .TestOutputs;

            var services = testOutputs.Get <App.Services>();

            services.FromCtor.Should().BeSameAs(services.FromInterceptor);
            services.FromCtor.Should().NotBeSameAs(svcBeforeRun);
        }
        public void ShouldUseModelFromDependencyResolver()
        {
            var argModel = new ArgModel {
                Text = "some default"
            };
            var testOutputs = new AppRunner <App>()
                              .UseDependencyResolver(new TestDependencyResolver {
                new App(), argModel
            })
                              .RunInMem("Do lala", _testOutputHelper)
                              .TestOutputs;

            var resolvedArgModel = testOutputs.Get <ArgModel>();

            resolvedArgModel.Should().BeSameAs(argModel);
        }