public void KernelShouldReturnFooWhenAskedForIFoo()
        {
            IKernel kernel = new StandardKernel();

            kernel.AddServices(services => services.AddTransient <IFoo, Foo>());

            kernel.Get <IFoo>().Id.ShouldBe(Foo.MagicString);
        }
        public void KernelShouldReturnTheSameInstanceWhenAskedTwiceForSingletonScopedServices()
        {
            IKernel kernel = new StandardKernel();

            kernel.AddServices(services => services.AddSingleton <IFoo, Foo>());

            IFoo number1 = kernel.Get <IFoo>();
            IFoo number2 = kernel.Get <IFoo>();

            number1.ShouldBeSameAs(number2);
        }
        public void KernelShouldReturnDifferentInstancesWhenAskedTwiceForTransientScopedServices()
        {
            IKernel kernel = new StandardKernel();

            kernel.AddServices(services => services.AddTransient <IFoo, Foo>());

            IFoo number1 = kernel.Get <IFoo>();
            IFoo number2 = kernel.Get <IFoo>();

            number1.ShouldNotBeSameAs(number2);
        }
        public void KernelShouldUseConstantsToo()
        {
            IKernel kernel = new StandardKernel();

            kernel.AddServices(services =>
            {
                services.Add(new ServiceDescriptor(typeof(int), 3));
            });

            kernel.Get <int>().ShouldBe(3);
        }
        public void KernelShouldInjectInnerServicesToMethodsToo()
        {
            IKernel kernel = new StandardKernel();

            kernel.AddServices(services =>
            {
                services.AddTransient <IFoo>(serviceProvider => new Foo());
                services.AddTransient <IBar>(serviceProvider => new Bar(serviceProvider.GetService <IFoo>()));
            });

            kernel.Get <IBar>().MyFoo.Id.ShouldBe(Foo.MagicString);
        }
        public void KernelShouldInjectInnerServices()
        {
            IKernel kernel = new StandardKernel();

            kernel.AddServices(services =>
            {
                services.AddSingleton <IFoo, Foo>();
                services.AddSingleton <IBar, Bar>();
            });

            kernel.Get <IBar>().MyFoo.Id.ShouldBe(Foo.MagicString);
        }
        public void Scoped_Objects_Created_In_Different_Scopes_Should_Differ()
        {
            var kernel = new StandardKernel();

            kernel.AddServices(services =>
            {
                services.AddScoped <ScopedFoo>();
            });
            var scopeFactory = kernel.Get <IServiceScopeFactory>();
            var scopedFoo1   = scopeFactory.CreateScope().ServiceProvider.GetRequiredService <ScopedFoo>();
            var scopedFoo2   = scopeFactory.CreateScope().ServiceProvider.GetRequiredService <ScopedFoo>();

            scopedFoo1.ShouldNotBeSameAs(scopedFoo2);
        }
        public void Scoped_Objects_Created_In_The_Same_Scopes_Should_Be_The_Same()
        {
            var kernel = new StandardKernel();

            kernel.AddServices(services =>
            {
                services.AddScoped <ScopedFoo>();
            });
            var scopeFactory = kernel.Get <IServiceScopeFactory>();
            var scope        = scopeFactory.CreateScope();
            var scopedFoor1  = scope.ServiceProvider.GetRequiredService <ScopedFoo>();
            var scopedFoo2   = scope.ServiceProvider.GetRequiredService <ScopedFoo>();

            scopedFoor1.ShouldBeSameAs(scopedFoo2);
        }
        public void Scoped_Objects_Should_Be_Disposed_Together_With_The_Scope()
        {
            var kernel = new StandardKernel();

            kernel.AddServices(services =>
            {
                services.AddScoped <ScopedFoo>();
            });
            var scopeFactory = kernel.Get <IServiceScopeFactory>();
            var scope        = scopeFactory.CreateScope();
            var scopedFoo    = scope.ServiceProvider.GetRequiredService <ScopedFoo>();

            scopedFoo.IsDisposed.ShouldBeFalse();
            scope.Dispose();
            scopedFoo.IsDisposed.ShouldBeTrue();
        }