public static IServiceCollection AddCoreDi(this IServiceCollection services, Action <CodeDiOptions> actionOptions) { CodeDiOptions options = new CodeDiOptions(); actionOptions(options); return(new CodeDiService(services, options).AddService()); }
public CodeDiService(IServiceCollection service, CodeDiOptions options) { _service = service ?? throw new ArgumentNullException(nameof(service)); _options = options ?? new CodeDiOptions(); _addedService = new ServiceDescriptor[service.Count]; service.CopyTo(_addedService, 0); }
public static IList <Assembly> LoadAssembly(CodeDiOptions options) { var assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); if (!options.IncludeSystemAssemblies) { assemblies = assemblies.Where(assembly => assembly.ManifestModule.Name != "<In Memory Module>" && !assembly.GetAssemblyName().StartsWith("System") && !assembly.GetAssemblyName().StartsWith("Microsoft") && assembly.Location.IndexOf("App_Web", StringComparison.Ordinal) == -1 && assembly.Location.IndexOf("App_global", StringComparison.Ordinal) == -1 && assembly.GetAssemblyName().IndexOf("CppCodeProvider", StringComparison.Ordinal) == -1 && assembly.GetAssemblyName().IndexOf("WebMatrix", StringComparison.Ordinal) == -1 && assembly.GetAssemblyName().IndexOf("SMDiagnostics", StringComparison.Ordinal) == -1 && assembly.GetAssemblyName().IndexOf("Newtonsoft", StringComparison.Ordinal) == -1 && !string.IsNullOrEmpty(assembly.Location)).ToList(); } assemblies.AddRange(LoadFromPaths(options.AssemblyPaths).Where(toAdd => assemblies.All(u => u.GetAssemblyName() != toAdd.GetAssemblyName()))); return(assemblies.Where(u => options.AssemblyNames.Any(name => u.GetAssemblyName().Matches(name))) .Where(u => options.IgnoreAssemblies == null || options.IgnoreAssemblies.All(ignore => u.GetAssemblyName().Matches(ignore) == false)) .Distinct().ToList()); }
public static IServiceCollection AddCoreDi(this IServiceCollection services, CodeDiOptions options = null) { return(new CodeDiService(services, options).AddService()); }