Beispiel #1
0
        public static T GetOrAdd <T>(
            [NotNull] this IServiceProviderDictionary serviceProviderDictionary,
            string key,
            [NotNull] Func <T> factory
            )
            where T : class
        {
            if (serviceProviderDictionary == null)
            {
                throw new ArgumentNullException(nameof(serviceProviderDictionary));
            }

            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            if (!(serviceProviderDictionary[key] is T value))
            {
                value = factory();
                serviceProviderDictionary.Set(value);
            }

            return(value);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConventionTestHost" /> class.
 /// </summary>
 /// <param name="scanner">The scanner.</param>
 /// <param name="assemblyCandidateFinder">The assembly candidate finder.</param>
 /// <param name="assemblyProvider">The assembly provider.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <param name="serviceProperties">The service properties.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="environment">The environment.</param>
 internal ConventionTestHost(
     IConventionScanner scanner,
     IAssemblyCandidateFinder assemblyCandidateFinder,
     IAssemblyProvider assemblyProvider,
     DiagnosticSource diagnosticSource,
     IServiceProviderDictionary serviceProperties,
     ILoggerFactory loggerFactory,
     IRocketEnvironment environment
     ) : base(scanner, assemblyCandidateFinder, assemblyProvider, diagnosticSource, serviceProperties)
 {
     serviceProperties.Set(HostType.UnitTestHost);
     _loggerFactory = loggerFactory;
     _environment   = environment;
     _logger        = ServiceProperties.Get <ILogger>();
 }