Exemple #1
0
        public void Test_CanLoad_AndResolve_BindToType(int nTestThreads)
        {
            StandardDependencyResolver resolver =
                new StandardDependencyResolver();

            List <DependencyRegistration> dependencies =
                new List <DependencyRegistration>();

            dependencies.Add(DependencyRegistration.BindToType(typeof(IAsSingletonSampleDependency),
                                                               typeof(AsSingletonSampleDependencyImpl),
                                                               DependencyScope.Singleton));

            dependencies.Add(DependencyRegistration.BindToType(typeof(IAsThreadSingletonSampleDependency),
                                                               typeof(AsThreadSingletonSampleDependencyImpl),
                                                               DependencyScope.Thread));

            dependencies.Add(DependencyRegistration.BindToType(typeof(IAsTransientSampleDependency),
                                                               typeof(AsTransientSampleDependencyImpl),
                                                               DependencyScope.Transient));

            resolver.Load(dependencies);

            Assert_DependenciesCanBeResolved(resolver);
            Assert_DependenciesCorrectlyResolved(nTestThreads, resolver);
        }
Exemple #2
0
        private IDependencyResolver GetDependencyResolver()
        {
            IDependencyResolver dependencyResolver =
                new StandardDependencyResolver();

            dependencyResolver.Load(TestDependencyRegistrations
                                    .GetAll());

            return(dependencyResolver);
        }
Exemple #3
0
        public void Test_CanLoad_AndResolve_BindToInstance()
        {
            StandardDependencyResolver resolver =
                new StandardDependencyResolver();

            List <DependencyRegistration> dependencies =
                new List <DependencyRegistration>();

            IAsSingletonSampleDependency instance = new AsSingletonSampleDependencyImpl();

            dependencies.Add(DependencyRegistration.BindToInstance(typeof(IAsSingletonSampleDependency),
                                                                   instance));

            resolver.Load(dependencies);

            Assert.IsTrue(resolver.CanResolve(typeof(IAsSingletonSampleDependency)));
            Assert.IsTrue(resolver.CanResolve <IAsSingletonSampleDependency>());

            Assert.AreSame(instance,
                           resolver.TryResolve <IAsSingletonSampleDependency>());

            Assert.AreSame(resolver.TryResolve <IAsSingletonSampleDependency>(),
                           resolver.TryResolve <IAsSingletonSampleDependency>());
        }