public static PluginLoadContext AddHostServices(this PluginLoadContext pluginLoadContext, IServiceCollection hostServices, IEnumerable <Type> includeTypes = null, IEnumerable <Type> excludeTypes = null) { if (includeTypes == null || !includeTypes.Any()) { return(pluginLoadContext); // short circuit } var hostTypes = new List <Type>(); var priseServices = hostServices.Where(s => IsPriseService(s.ServiceType)); var includeServices = hostServices.Where(s => Includes(s.ServiceType, includeTypes)); var excludeServices = hostServices.Where(s => Excludes(s.ServiceType, excludeTypes)); foreach (var hostService in hostServices .Except(priseServices) .Union(includeServices) .Except(excludeServices)) { pluginLoadContext.AddHostService(hostService); } return(pluginLoadContext); }
public static PluginLoadContext AddHostService <T>(this PluginLoadContext pluginLoadContext, T implementation, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) { return(pluginLoadContext.AddHostService(new ServiceDescriptor(typeof(T), (s) => implementation, serviceLifetime))); }
public static PluginLoadContext AddHostService(this PluginLoadContext pluginLoadContext, Type hostServiceType, Type hostServiceImplementationType, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) { return(pluginLoadContext.AddHostService(new ServiceDescriptor(hostServiceType, hostServiceImplementationType, serviceLifetime))); }