Beispiel #1
0
        public AssemblyLocatorResult Locate(Func <AssemblySearchPatternFactory, AssemblySearchPatternFactory> assemblyNameFilter,
                                            IDependousConfiguration dependousConfiguration)
        {
            assemblyNameFilter = assemblyNameFilter ?? new Func <AssemblySearchPatternFactory, AssemblySearchPatternFactory>((pf) => pf.Self());
            var defaultFilters = assemblyNameFilter(new AssemblySearchPatternFactory());
            AssemblySearchPatternFactory factory = defaultFilters;

            if (dependousConfiguration.ProbingPaths != null && dependousConfiguration.ProbingPaths.Any())
            {
                List <FileInfo> results = new List <FileInfo>();
                foreach (var path in dependousConfiguration.ProbingPaths)
                {
                    if (path.Pattern != null)
                    {
                        factory = path.Pattern(new AssemblySearchPatternFactory());
                    }
                    else
                    {
                        factory = defaultFilters;
                    }
                    var assemblies = new DirectoryInfo(path.Path)
                                     .EnumerateFiles()
                                     .Where(name => factory.Patterns.Any(x => x.Match(name.Name)) &&
                                            this._extensions.Contains(name.Extension, StringComparer.OrdinalIgnoreCase));
                    results.AddRange(assemblies);
                }
                return(new AssemblyLocatorResult(results.Select(a =>
                {
                    var an = AssemblyName.GetAssemblyName(a.FullName);
                    an.CodeBase = a.FullName;
                    return an;
                })));
            }
            return(new AssemblyLocatorResult(Enumerable.Empty <AssemblyName>()));
        }
 /// <summary>
 /// Adds Dependous and Autofac as the preferred IOC container.
 /// </summary>
 /// <param name="hostBuilder">The host builder.</param>
 /// <param name="assemblySearchPatternFactory">The assembly search pattern factory.</param>
 /// <param name="configurationBuilder">The configuration builder.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="containerBuilder">The container builder.</param>
 /// <returns></returns>
 public static IHostBuilder UseAutoFacContainer(this IHostBuilder hostBuilder,
                                                AssemblySearchPatternFactory assemblySearchPatternFactory,
                                                Action <IDependousConfiguration> configurationBuilder = null,
                                                Action <object> logger = null,
                                                Action <ContainerBuilder> containerBuilder = null)
 {
     AutoFacSetup.SetAutoFacCircularDependencyLimit();
     return(hostBuilder.UseServiceProviderFactory(new AutoFacServiceProviderFactoryDecorator(assemblySearchPatternFactory, configurationBuilder, logger, containerBuilder)));
 }
        public static IContainer BuildAutoFacContainer(this IServiceCollection services,
                                                       AssemblySearchPatternFactory assemblyPaths,
                                                       Action <IDependousConfiguration> configurationBuilder = null,
                                                       Action <object> logger = null,
                                                       Action <ContainerBuilder> containerBuilder = null)
        {
            var container = new AutoFacServiceProviderFactoryDecorator(assemblyPaths, configurationBuilder, logger, containerBuilder).CreateBuilder(services).Build();

            return(container);
        }
 internal AutoFacServiceProviderFactoryDecorator(
     AssemblySearchPatternFactory assemblySearchPatternFactory,
     Action <IDependousConfiguration> configurationBuilder = null,
     Action <object> logger = null,
     Action <ContainerBuilder> containerBuilder = null)
 {
     _assemblySearchPatternFactory = assemblySearchPatternFactory;
     _configurationBuilder         = configurationBuilder;
     _logger     = logger;
     _decorateer = new AutofacServiceProviderFactory(containerBuilder);
 }
        private void PopulateAutoFacContainer(IServiceCollection services,
                                              ContainerBuilder containerBuilder,
                                              Action <IDependousConfiguration> configurationBuilder = null,
                                              Action <object> logger = null)
        {
            Func <AssemblySearchPatternFactory, AssemblySearchPatternFactory> patternBuilder = (b) =>
            {
                AssemblySearchPatternFactory.Merge(_assemblySearchPatternFactory, b);
                AssemblySearchPatternFactory.Merge(_assemblyPaths, b);
                return(b);
            };

            BuildContainer(
                containerBuilder,
                patternBuilder,
                () =>
            {
                var serviceProvider = services.BuildServiceProvider();
                return(serviceProvider.GetService <IDependencyScanner>());
            },
                configurationBuilder,
                logger);
        }