src/Topelab.Core.Resolver.Microsoft/ResolverFactory.cs
/// <summary>
/// Adds the resolver to service collection.
/// </summary>
/// <param name="services">The services.</param>
/// <param name="resolveInfoCollection">The resolve information collection.</param>
Adds the resolver to service collection.
Adds the resolver to service collection .
public static IServiceCollection AddResolver(this IServiceCollection services, 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, services);
            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;
            });
            return services;
        }
public static IServiceCollection AddResolver ( this IServiceCollection services , 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 , services ) ; 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 ; } ) ; return services ; }
Adds the resolver to service collection.
Adds the resolver to service collection .
IServiceCollection
this
resolveInfoCollection
ResolveInfoCollection
The resolve information collection.
The resolve information collection .
services
None