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); }
private IDependencyResolver GetDependencyResolver() { IDependencyResolver dependencyResolver = new StandardDependencyResolver(); dependencyResolver.Load(TestDependencyRegistrations .GetAll()); return(dependencyResolver); }
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>()); }