Exemplo n.º 1
0
 protected override void Dispose(bool explicitDispose)
 {
     _settings = null;
     //
     base.Dispose(explicitDispose);
 }
Exemplo n.º 2
0
        internal static ServiceInfo Find(Type expectedType, ServiceScope serviceScope, DependencyResolutionSettings settings)
        {
            if (!settings.IsServiceAutoDetectionEnabled)
            {
                throw new InvalidOperationException("Attempted to auto detect service implementation when auto detection is disabled.");
            }

            var implementations =
                settings.ServiceAutoDetectionAssemblies
                .SelectMany(x => x.GetTypes())
                .Where(expectedType.IsAssignableFrom)
                .Where(x => !x.IsAbstract && !x.IsInterface && x.GetConstructors().Any(x => x.GetParameters().Length == 0))
                .ToList();

            if (implementations.Count > 1)
            {
                throw new InvalidOperationException(
                          $"Attempted to auto detect service implementation for {expectedType.Name} but multiple types were matched ({string.Join(", ", implementations.Select(x => x.Name))}).");
            }

            if (implementations.Count == 0)
            {
                throw new InvalidOperationException($"Attempted to auto detect service implementation for {expectedType.Name} but no types were matched.");
            }

            return(new ServiceInfo(expectedType, implementations[0], serviceScope, null, null, InjectionMode.Property));
        }