public void ImplicitlyInstantiatedConcreteClassHasDefaultLifestyle()
        {
            var container = new PandoraContainer(new ComponentStore());

            var c1 = container.Resolve <ClassWithNoDependencies>();
            var c2 = container.Resolve <ClassWithNoDependencies>();

            Assert.Same(c1, c2);
        }
        public void ImplicitlyInstantiatedConcreteClassHasDefaultLifestyle()
        {
            var container = new PandoraContainer(new ComponentStore());

            var c1 = container.Resolve<ClassWithNoDependencies>();
            var c2 = container.Resolve<ClassWithNoDependencies>();

            Assert.Same(c1, c2);
        }
        public void ActivationHappensEveryTime()
        {
            var store = new ComponentStore();
            var registration = store.Add<IService, ClassWithNoDependencies>();
            registration.Lifestyle = ComponentLifestyles.Transient;

            var container = new PandoraContainer(store);
            var service = container.Resolve<IService>();
            var service2 = container.Resolve<IService>();

            Assert.NotSame(service, service2);
        }
        public void ActivationHappensEveryTime()
        {
            var store = new ComponentStore();
            var registration = store.Add<IService, ClassWithNoDependencies>();
            registration.Lifestyle = ComponentLifestyles.Transient;

            var container = new PandoraContainer(store);
            var service = container.Resolve<IService>();
            var service2 = container.Resolve<IService>();

            Assert.NotSame(service, service2);
        }
        public void ImplicitlyInstantiatedConcreteClassLifestyleCanBeConfigured()
        {
            var configuration = new BehaviorConfiguration
            {
                ImplicitTypeLifestyle = BehaviorConfiguration.Lifestyle.Transient
            };
            var container = new PandoraContainer(configuration);

            var c1 = container.Resolve <ClassWithNoDependencies>();
            var c2 = container.Resolve <ClassWithNoDependencies>();

            Assert.NotSame(c1, c2);
        }
        public void ImplicitlyInstantiatedConcreteClassLifestyleCanBeConfigured()
        {
            var configuration = new BehaviorConfiguration
                                    {
                                        ImplicitTypeLifestyle = BehaviorConfiguration.Lifestyle.Transient
                                    };
            var container = new PandoraContainer(configuration);

            var c1 = container.Resolve<ClassWithNoDependencies>();
            var c2 = container.Resolve<ClassWithNoDependencies>();

            Assert.NotSame(c1, c2);
        }
        public void ActivationHappensOnlyOnceForSingletonComponents()
        {
            var store        = new ComponentStore();
            var registration = store.Add <IService, ClassWithNoDependencies>("test");

            registration.Lifestyle = ComponentLifestyles.Singleton;

            var container = new PandoraContainer(store);

            var service  = container.Resolve <IService>("test");
            var service2 = container.Resolve <IService>("test");

            Assert.Same(service, service2);
        }
        public void CanConfigureLifestyle()
        {
            store.Register((p) =>
            {
                p.Service <IService>()
                .Implementor <ClassWithDependencyOnItsOwnService>()
                .Lifestyle.Singleton();
                p.Service <IService>()
                .Implementor <ClassWithNoDependencies>()
                .Lifestyle.Singleton();
            });

            Assert.DoesNotThrow(() => container.Resolve <IService>());
        }
        public void NoRegistrationIsRequiredToInstantiateConcreteClassWithoutDependencies()
        {
            var container    = new PandoraContainer(new ComponentStore());
            var dependencies = container.Resolve <ClassWithNoDependencies>();

            Assert.IsType <ClassWithNoDependencies>(dependencies);
        }
        public void CanSplitGraph()
        {
            /*
             * Dotty Graph:
             *
             * digraph G {
             * a [label="IService :: A"] ;
             * a -> b [label="service1"] ;
             * a -> c [label="service2"] ;
             * b [label="IService :: B"] ;
             * b -> d ;
             * d [label="IService :: C"] ;
             * c [label="IService :: B"] ;
             * c -> f ;
             * f [label="IService :: C"] ;
             * }
             */

            var store = new ComponentStore();

            store.Add <IService, ClassWithTwoDependenciesOnItsOwnService>();
            store.Add <IService, ClassWithDependencyOnItsOwnService>();
            store.Add <IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(store);

            var service = container.Resolve <IService>();

            Assert.IsType(typeof(ClassWithTwoDependenciesOnItsOwnService), service);
        }
        public void ClassWithDependencyOnConcreteClassResolves()
        {
            var container  = new PandoraContainer(new ComponentStore());
            var dependency =
                container.Resolve <GenericWithDependency <ClassWithNoDependencies> >();

            Assert.IsType <ClassWithNoDependencies>(dependency.Dependency);
        }
        public void CanResolveConcreteType()
        {
            var store = new ComponentStore();
            store.Add<ClassWithNoDependencies, ClassWithNoDependencies>();
            var container = new PandoraContainer(store);

            Assert.DoesNotThrow(() => container.Resolve<ClassWithNoDependencies>());
        }
 public void ConcreteClassInstantiationCanBeTurnedOff()
 {
     var behaviorConfiguration = new BehaviorConfiguration
                                     {
                                         EnableImplicitTypeInstantiation = false
                                     };
     var container = new PandoraContainer(behaviorConfiguration);
     Assert.Throws<ServiceNotFoundException>(() => container.Resolve<ClassWithNoDependencies>());
 }
        public void CanRegisterOnContainerWithoutStore()
        {
            container.Register(p => p.Service <IService>()
                               .Implementor <ClassWithNoDependencies>());

            var service = container.Resolve <IService>();

            Assert.IsType <ClassWithNoDependencies>(service);
        }
        public void ThrowsExceptionIfDependencyCouldNotBeSatisfied()
        {
            var store = new ComponentStore();

            store.Add <ClassWithOneDependency, ClassWithOneDependency>();
            var container = new PandoraContainer(store);

            Assert.Throws <DependencyMissingException>(() => container.Resolve <ClassWithOneDependency>());
        }
        public void CanResolveConcreteType()
        {
            var store = new ComponentStore();

            store.Add <ClassWithNoDependencies, ClassWithNoDependencies>();
            var container = new PandoraContainer(store);

            container.Resolve <ClassWithNoDependencies>();
        }
        public void CanResolveWhenGivenTwoConstructorsWhereOneCantBeSatisfied()
        {
            var store = new ComponentStore();

            store.Add <IService4, ClassWithMultipleConstructors>();

            var container = new PandoraContainer(store);

            container.Resolve <IService4>();
        }
        public void ThrowsExceptionIfTypeNotRegistered()
        {
            var store = new ComponentStore();

            var container = new PandoraContainer(store);

            Assert.Throws <ServiceNotFoundException>(() => {
                var result = container.Resolve <IService>();
            });
        }
        public void NoRegistrationIsRequiredToInstantiateConcreteClassWithoutDependencies()
        {
            var container = new PandoraContainer(new ComponentStore());

            Assert.DoesNotThrow(() =>
                                    {
                                        var dependencies = container.Resolve<ClassWithNoDependencies>();
                                        Assert.IsType<ClassWithNoDependencies>(dependencies);
                                    });
        }
        public void ConcreteClassInstantiationCanBeTurnedOff()
        {
            var behaviorConfiguration = new BehaviorConfiguration
            {
                EnableImplicitTypeInstantiation = false
            };
            var container = new PandoraContainer(behaviorConfiguration);

            Assert.Throws <ServiceNotFoundException>(() => container.Resolve <ClassWithNoDependencies>());
        }
        public void CanResolveClassWithoutDependencies()
        {
            var componentStore = new ComponentStore();
            componentStore.Add<IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(componentStore);
            var result = container.Resolve<IService>();

            Assert.IsType<ClassWithNoDependencies>(result);
        }
        public void ThrowsDependencyMissingExceptionIfDependencyChainCannotBeSatisfied()
        {
            var store = new ComponentStore();

            store.Add <IService, ClassWithDependencyOnItsOwnService>();

            var container = new PandoraContainer(store);

            Assert.Throws <DependencyMissingException>(() => container.Resolve <IService>());
        }
Example #23
0
        public void RetrievalByNameThrowsExceptionWhenNameNotRegistered()
        {
            var store = new ComponentStore();
            var container = new PandoraContainer(store);
            //To make it lookup something
            container.Register(p =>
                p.Service<ClassWithNoDependencies>()
                    .Implementor<ClassWithNoDependencies>());

            Assert.Throws<ServiceNotFoundException>(() => container.Resolve<ClassWithNoDependencies>("test"));
        }
        public void CanInsertInstanceWithoutName()
        {
            var store = new ComponentStore();
            var instance = new ClassWithNoDependencies();
            store.AddInstance<IService>(instance);
            var container = new PandoraContainer(store);

            var service = container.Resolve<IService>();

            Assert.Same(instance, service);
        }
        public void CanResolveClassWithOneDependency()
        {
            IComponentStore componentStore = new ComponentStore();
            componentStore.Add<IService, ClassWithNoDependencies>();
            componentStore.Add<IService2, ClassWithOneDependency>();

            PandoraContainer locator = new PandoraContainer(componentStore);
            var result = locator.Resolve<IService2>();

            Assert.IsType<ClassWithOneDependency>(result);
        }
Example #26
0
        public void CanRetrieveServiceByName()
        {
            var store = new ComponentStore();
            //This registration is to give the container something to choose from, in case named lookup won't work
            store.Add<IService, ClassWithDependencyOnItsOwnService>("memory.repository");
            store.Add<IService, ClassWithNoDependencies>("db.repository");
            var container = new PandoraContainer(store);

            var service = container.Resolve<IService>("db.repository");
            Assert.IsType<ClassWithNoDependencies>(service);
        }
        public void CanResolveClassWithTwoDependenciesOnItsOwnServiceWithOnlyOneSubdependencyRegistration()
        {
            var store = new ComponentStore();
            store.Add<IService, ClassWithTwoDependenciesOnItsOwnService>();
            store.Add<IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(store);

            var service = container.Resolve<IService>();
            Assert.IsType(typeof (ClassWithTwoDependenciesOnItsOwnService), service);
        }
        public void DependencyMissingExceptionPropagatesThroughMultipleLevels()
        {
            var store = new ComponentStore();

            store.Add <IService3, ClassDependingOnClassWithOneDependency>();
            store.Add <IService2, ClassWithOneDependency>();

            var container = new PandoraContainer(store);

            Assert.Throws <DependencyMissingException>(() => container.Resolve <IService3>());
        }
        public void ClassWithDependencyOnConcreteClassResolves()
        {
            var container = new PandoraContainer(new ComponentStore());

            Assert.DoesNotThrow(() =>
                                    {
                                        var dependency =
                                            container.Resolve<GenericWithDependency<ClassWithNoDependencies>>();
                                        Assert.IsType<ClassWithNoDependencies>(dependency.Dependency);
                                    });
        }
        public void CanResolveClassWithoutDependencies()
        {
            var componentStore = new ComponentStore();

            componentStore.Add <IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(componentStore);
            var result    = container.Resolve <IService>();

            Assert.IsType <ClassWithNoDependencies>(result);
        }
Example #31
0
        public void RetrievalByNameThrowsExceptionWhenNameNotRegistered()
        {
            var store     = new ComponentStore();
            var container = new PandoraContainer(store);

            //To make it lookup something
            container.Register(p =>
                               p.Service <ClassWithNoDependencies>()
                               .Implementor <ClassWithNoDependencies>());

            Assert.Throws <ServiceNotFoundException>(() => container.Resolve <ClassWithNoDependencies>("test"));
        }
        public void CanResolveClassWithMultipleDependencies()
        {
            var store = new ComponentStore();
            store.Add<IService, ClassWithNoDependencies>();
            store.Add<IService2, ClassWithOneDependency>();
            store.Add<IService3, ClassDependingOnClassWithOneDependency>();

            var container = new PandoraContainer(store);
            var result = container.Resolve<IService3>();

            Assert.IsType<ClassDependingOnClassWithOneDependency>(result);
        }
Example #33
0
        public void CanInsertInstanceWithoutName()
        {
            var store    = new ComponentStore();
            var instance = new ClassWithNoDependencies();

            store.AddInstance <IService>(instance);
            var container = new PandoraContainer(store);

            var service = container.Resolve <IService>();

            Assert.Same(instance, service);
        }
        public void CanResolveClassWithOneDependency()
        {
            IComponentStore componentStore = new ComponentStore();

            componentStore.Add <IService, ClassWithNoDependencies>();
            componentStore.Add <IService2, ClassWithOneDependency>();

            PandoraContainer locator = new PandoraContainer(componentStore);
            var result = locator.Resolve <IService2>();

            Assert.IsType <ClassWithOneDependency>(result);
        }
        public void CanSpecifyDependencyByName()
        {
            var store = new ComponentStore();
            store.Add<IService, ClassWithNoDependencies>("service1");
            store.Add<IService, ClassWithNoDependencies2>("service2");
            store.Add<ClassWithOneDependency, ClassWithOneDependency>()
                .Parameters["dependency"] = "service2";
            var container = new PandoraContainer(store);

            var service2 = container.Resolve<ClassWithOneDependency>();

            Assert.IsType<ClassWithNoDependencies2>(service2.Dependency);
        }
        public void CanResolveClassWithMultipleDependencies()
        {
            var store = new ComponentStore();

            store.Add <IService, ClassWithNoDependencies>();
            store.Add <IService2, ClassWithOneDependency>();
            store.Add <IService3, ClassDependingOnClassWithOneDependency>();

            var container = new PandoraContainer(store);
            var result    = container.Resolve <IService3>();

            Assert.IsType <ClassDependingOnClassWithOneDependency>(result);
        }
        public void CanResolveClassWithTwoDependenciesOnItsOwnServiceWithOnlyOneSubdependencyRegistration()
        {
            var store = new ComponentStore();

            store.Add <IService, ClassWithTwoDependenciesOnItsOwnService>();
            store.Add <IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(store);

            var service = container.Resolve <IService>();

            Assert.IsType(typeof(ClassWithTwoDependenciesOnItsOwnService), service);
        }
Example #38
0
        public void CanRetrieveServiceByName()
        {
            var store = new ComponentStore();

            //This registration is to give the container something to choose from, in case named lookup won't work
            store.Add <IService, ClassWithDependencyOnItsOwnService>("memory.repository");
            store.Add <IService, ClassWithNoDependencies>("db.repository");
            var container = new PandoraContainer(store);

            var service = container.Resolve <IService>("db.repository");

            Assert.IsType <ClassWithNoDependencies>(service);
        }
        public void CanResolveSpecificGenericClass()
        {
            store.Register(p =>
                           p.Service <GenericClass <string> >()
                           .Implementor <GenericClass <string> >());

            container.Resolve <GenericClass <string> >();
        }
        public void CanResolveSpecificGenericClass()
        {
            store.Register(p =>
                           p.Service <GenericClass <string> >()
                           .Implementor <GenericClass <string> >());

            Assert.DoesNotThrow(() => container.Resolve <GenericClass <string> >());
        }
        public void CanSpecifyDependencyByName()
        {
            var store = new ComponentStore();

            store.Add <IService, ClassWithNoDependencies>("service1");
            store.Add <IService, ClassWithNoDependencies2>("service2");
            store.Add <ClassWithOneDependency, ClassWithOneDependency>()
            .Parameters["dependency"] = "service2";
            var container = new PandoraContainer(store);

            var service2 = container.Resolve <ClassWithOneDependency>();

            Assert.IsType <ClassWithNoDependencies2>(service2.Dependency);
        }
        public void CanResolveDependencyChainOfSameService()
        {
            var store = new ComponentStore();

            store.Add <IService, ClassWithDependencyOnItsOwnService>();
            store.Add <IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(store);

            var service = container.Resolve <IService>();

            Assert.IsType(typeof(ClassWithDependencyOnItsOwnService), service);
            var ownService = (ClassWithDependencyOnItsOwnService)service;

            Assert.IsType(typeof(ClassWithNoDependencies), ownService.SubService);
        }
        public void CanInstantiateClassThatDependsOnAString()
        {
            var store = new ComponentStore();
            store.Register(
                p =>
                {
                    p.Service<ClassDependingOnAString>()
                        .Implementor<ClassDependingOnAString>()
                        .Parameters("string1");
                    p.Service<string>("string1")
                        .Instance("Hello World");
                });
            var container = new PandoraContainer(store);

            var resolve = container.Resolve<ClassDependingOnAString>();
            Assert.Equal("Hello World", resolve.Dependency);
        }
Example #44
0
        public void CanInstantiateClassThatDependsOnAString()
        {
            var store = new ComponentStore();

            store.Register(
                p =>
            {
                p.Service <ClassDependingOnAString>()
                .Implementor <ClassDependingOnAString>()
                .Parameters("string1");
                p.Service <string>("string1")
                .Instance("Hello World");
            });
            var container = new PandoraContainer(store);

            var resolve = container.Resolve <ClassDependingOnAString>();

            Assert.Equal("Hello World", resolve.Dependency);
        }
        public void CanResolveDependencyChainOfSameServiceWithMultipleLevels()
        {
            var store = new ComponentStore();

            store.Add <IService, ClassWithDependencyOnItsOwnService>();
            store.Add <IService, ClassWithDependencyOnItsOwnService>();
            store.Add <IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(store);

            var service = container.Resolve <IService>();

            var level1 = (ClassWithDependencyOnItsOwnService)service;
            var level2 = (ClassWithDependencyOnItsOwnService)level1.SubService;
            var level3 = (ClassWithNoDependencies)level2.SubService;

            Assert.IsType(typeof(ClassWithDependencyOnItsOwnService), level1);
            Assert.IsType(typeof(ClassWithDependencyOnItsOwnService), level2);
            Assert.IsType(typeof(ClassWithNoDependencies), level3);
        }
        public void CanResolveDependencyChainOfSameServiceWithMultipleLevels()
        {
            var store = new ComponentStore();
            store.Add<IService, ClassWithDependencyOnItsOwnService>();
            store.Add<IService, ClassWithDependencyOnItsOwnService>();
            store.Add<IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(store);

            var service = container.Resolve<IService>();

            var level1 = (ClassWithDependencyOnItsOwnService) service;
            var level2 = (ClassWithDependencyOnItsOwnService) level1.SubService;
            var level3 = (ClassWithNoDependencies)level2.SubService;

            Assert.IsType(typeof (ClassWithDependencyOnItsOwnService), level1);
            Assert.IsType(typeof(ClassWithDependencyOnItsOwnService), level2);
            Assert.IsType(typeof(ClassWithNoDependencies), level3);
        }
        public void CanResolveWhenGivenTwoConstructorsWhereOneCantBeSatisfied()
        {
            var store = new ComponentStore();
            store.Add<IService4, ClassWithMultipleConstructors>();

            var container = new PandoraContainer(store);

            Assert.DoesNotThrow(() => container.Resolve<IService4>());
        }
        public void CanSplitGraph()
        {
            /*
             * Dotty Graph:
             *
            digraph G {
              a [label="IService :: A"] ;
              a -> b [label="service1"] ;
              a -> c [label="service2"] ;
              b [label="IService :: B"] ;
              b -> d ;
              d [label="IService :: C"] ;
              c [label="IService :: B"] ;
              c -> f ;
              f [label="IService :: C"] ;
            }
             */

            var store = new ComponentStore();
            store.Add<IService, ClassWithTwoDependenciesOnItsOwnService>();
            store.Add<IService, ClassWithDependencyOnItsOwnService>();
            store.Add<IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(store);

            var service = container.Resolve<IService>();
            Assert.IsType(typeof (ClassWithTwoDependenciesOnItsOwnService), service);
        }
        public void DependencyMissingExceptionPropagatesThroughMultipleLevels()
        {
            var store = new ComponentStore();
            store.Add<IService3, ClassDependingOnClassWithOneDependency>();
            store.Add<IService2, ClassWithOneDependency>();

            var container = new PandoraContainer(store);

            Assert.Throws<DependencyMissingException>(() => container.Resolve<IService3>());
        }
        public void ThrowsDependencyMissingExceptionIfDependencyChainCannotBeSatisfied()
        {
            var store = new ComponentStore();
            store.Add<IService, ClassWithDependencyOnItsOwnService>();

            var container = new PandoraContainer(store);

            Assert.Throws<DependencyMissingException>(() => container.Resolve<IService>());
        }
        public void ThrowsExceptionIfDependencyCouldNotBeSatisfied()
        {
            var store = new ComponentStore();
            store.Add<ClassWithOneDependency, ClassWithOneDependency>();
            var container = new PandoraContainer(store);

            Assert.Throws<DependencyMissingException>(() => container.Resolve<ClassWithOneDependency>());
        }
        public void ThrowsExceptionIfTypeNotRegistered()
        {
            var store = new ComponentStore();

            var container = new PandoraContainer(store);

            Assert.Throws<ServiceNotFoundException>(() => {
                                                              var result = container.Resolve<IService>();
            });
        }
        public void CanResolveDependencyChainOfSameService()
        {
            var store = new ComponentStore();
            store.Add<IService, ClassWithDependencyOnItsOwnService>();
            store.Add<IService, ClassWithNoDependencies>();

            var container = new PandoraContainer(store);

            var service = container.Resolve<IService>();

            Assert.IsType(typeof (ClassWithDependencyOnItsOwnService), service);
            var ownService = (ClassWithDependencyOnItsOwnService)service;
            Assert.IsType(typeof (ClassWithNoDependencies), ownService.SubService);
        }