/// <summary> /// Configures the default dependencies. /// </summary> /// <param name="dependencyInjectionContainer">The dependency injection container.</param> public void ConfigureDefaultDependencies(DependencyInjectionContainer dependencyInjectionContainer) { ExceptionUtilities.CheckArgumentNotNull(dependencyInjectionContainer, "dependencyInjectionContainer"); foreach (var param in this.TestParameters) { dependencyInjectionContainer.TestParameters[param.Key] = param.Value; } // set up dependency injector dependencyInjectionContainer.RegisterCustomResolver(typeof(Logger), this.GetLoggerForType).Transient(); dependencyInjectionContainer.RegisterInstance<IDependencyInjector>(dependencyInjectionContainer); dependencyInjectionContainer.InjectDependenciesInto(dependencyInjectionContainer); dependencyInjectionContainer.InjectDependenciesInto(this.implementationSelector); this.implementations = this.implementationSelector.GetImplementations(this.TestParameters).ToList(); // only register dependencies that cannot already be resolved (unless the dependency was specified as a // test parameter, in which case override the default) foreach (var implInfo in this.implementations.Where(i => i.IsTestParameterSpecified || !dependencyInjectionContainer.CanResolve(i.ContractType))) { var options = dependencyInjectionContainer.Register(implInfo.ContractType, implInfo.ImplementationType); options.IsTransient = implInfo.IsTransient; } }
/// <summary> /// Configures the default dependencies. /// </summary> /// <param name="dependencyInjectionContainer">The dependency injection container.</param> public void ConfigureDefaultDependencies(DependencyInjectionContainer dependencyInjectionContainer) { ExceptionUtilities.CheckArgumentNotNull(dependencyInjectionContainer, "dependencyInjectionContainer"); foreach (var param in this.TestParameters) { dependencyInjectionContainer.TestParameters[param.Key] = param.Value; } // set up dependency injector dependencyInjectionContainer.RegisterCustomResolver(typeof(Logger), this.GetLoggerForType).Transient(); dependencyInjectionContainer.RegisterInstance <IDependencyInjector>(dependencyInjectionContainer); dependencyInjectionContainer.InjectDependenciesInto(dependencyInjectionContainer); dependencyInjectionContainer.InjectDependenciesInto(this.implementationSelector); this.implementations = this.implementationSelector.GetImplementations(this.TestParameters).ToList(); // only register dependencies that cannot already be resolved (unless the dependency was specified as a // test parameter, in which case override the default) foreach (var implInfo in this.implementations.Where(i => i.IsTestParameterSpecified || !dependencyInjectionContainer.CanResolve(i.ContractType))) { var options = dependencyInjectionContainer.Register(implInfo.ContractType, implInfo.ImplementationType); options.IsTransient = implInfo.IsTransient; } }