src/Topelab.Core.Resolver.Microsoft/ResolverFactory.cs
/// <summary>
/// Creates an IResolver based on the specified resolve info collection.
/// </summary>
/// <param name="resolveInfoCollection">The resolve info collection.</param>
Creates an IResolver based on the specified resolve info collection.
Creates an IResolver based on the specified resolve info collection .
public static IResolver Create(ResolveInfoCollection resolveInfoCollection)
        {
            if (resolveInfoCollection is null)
            {
                throw new ArgumentNullException(nameof(resolveInfoCollection));
            }
            IDictionary<string, IResolver> globalResolvers = new Dictionary<string, IResolver>();
            var resolveInfoCollectionWithDefaultKey = resolveInfoCollection.Where(r => (r.Key ?? DefaultKey) == DefaultKey);
            var collection = ServiceCollectionFactory.Create(resolveInfoCollectionWithDefaultKey);
            collection.AddSingleton(s =>
            {
                var serviceFactory = s.GetService<IServiceFactory>();
                var resolver = serviceFactory.Create<IResolver>(s, serviceFactory, DefaultKey, globalResolvers);
                List<string> otherKeys = resolveInfoCollection.Select(r => r.Key ?? DefaultKey).Where(k => k != DefaultKey).Distinct().ToList();
                otherKeys.ForEach(key => Create(key, resolveInfoCollection, globalResolvers));
                return resolver;
            });
            var serviceProvider = collection.BuildServiceProvider();
            resolver = (Resolver)serviceProvider.GetService<IResolver>();
            return resolver;
        }
public static IResolver Create ( ResolveInfoCollection resolveInfoCollection ) { if ( resolveInfoCollection is null ) { throw new ArgumentNullException ( nameof ( resolveInfoCollection ) ) ; } IDictionary < string , IResolver > globalResolvers = new Dictionary < string , IResolver > ( ) ; var resolveInfoCollectionWithDefaultKey = resolveInfoCollection . Where ( r => ( r . Key ?? DefaultKey ) == DefaultKey ) ; var collection = ServiceCollectionFactory . Create ( resolveInfoCollectionWithDefaultKey ) ; collection . AddSingleton ( s => { var serviceFactory = s . GetService < IServiceFactory > ( ) ; var resolver = serviceFactory . Create < IResolver > ( s , serviceFactory , DefaultKey , globalResolvers ) ; List < string > otherKeys = resolveInfoCollection . Select ( r => r . Key ?? DefaultKey ) . Where ( k => k != DefaultKey ) . Distinct ( ) . ToList ( ) ; otherKeys . ForEach ( key => Create ( key , resolveInfoCollection , globalResolvers ) ) ; return resolver ; } ) ; var serviceProvider = collection . BuildServiceProvider ( ) ; resolver = ( Resolver ) serviceProvider . GetService < IResolver > ( ) ; return resolver ; }
Creates an IResolver based on the specified resolve info collection.
Creates an IResolver based on the specified resolve info collection .
resolveInfoCollection
ResolveInfoCollection
The resolve info collection.
The resolve info collection .