public void ConfigureServices(IServiceCollection serviceCollection) { Dictionary <Assembly, List <Plugin> > assemblies = new Dictionary <Assembly, List <Plugin> >(); foreach (var grouped in PluginConstructors.Where(x => typeof(IServiceHolder).IsAssignableFrom(x.Type)).GroupBy(x => x.Type.Assembly).ToArray()) { List <Plugin> assemblyInstances = new List <Plugin>(); foreach (var constructor in grouped) { if (constructor.RequiresServices) { Log.Warn($"Could not configure plugin as ServiceHolder. IServiceHolder implementations require an empty Constructor! (Type: {constructor.Type})"); continue; } if (CreateInstance(constructor, out Plugin instance, assemblies)) { PluginContainer.RegisterSingleton(instance.GetType(), instance); IServiceHolder serviceHolder = instance as IServiceHolder; serviceHolder?.ConfigureServices(serviceCollection); // pluginInstances++; assemblyInstances.Add(instance); //serviceCollection.AddSingleton(constructor.Type, instance); } PluginConstructors.Remove(constructor); } if (!assemblies.ContainsKey(grouped.Key)) { assemblies.Add(grouped.Key, assemblyInstances); } else { assemblies[grouped.Key].AddRange(assemblyInstances); } //PluginConstructors.Remove(constructor); } foreach (var grouped in assemblies) { if (LoadedAssemblies.ContainsKey(grouped.Key)) { LoadedAssemblies[grouped.Key].PluginTypes.AddRange(grouped.Value.Select(x => x.GetType())); continue; } else { LoadedAssemblies.Add(grouped.Key, new LoadedAssembly(grouped.Key, grouped.Value.Select(x => x.GetType()), new Assembly[0], grouped.Key.Location)); } } }
public void RegisterHolder(IServiceHolder holder) { ServiceHolders.Add(holder); }