public static IServiceCollection AddPriseWithPluginLoader <T, TPluginLoader>( this IServiceCollection services, Action <PluginLoadOptionsBuilder <T> > config = null, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) where T : class where TPluginLoader : class, IPluginLoader <T>, IPluginResolver <T> { var optionsBuilder = new PluginLoadOptionsBuilder <T>() .WithDefaultOptions(serviceLifetime: serviceLifetime); config?.Invoke(optionsBuilder); services = optionsBuilder.RegisterOptions(services); return(services .AddService(new ServiceDescriptor(typeof(IPluginLoader <T>), typeof(TPluginLoader), serviceLifetime)) .AddService(new ServiceDescriptor(typeof(IPluginResolver <T>), typeof(TPluginLoader), serviceLifetime)) .AddService(new ServiceDescriptor(typeof(T), (s) => { // Synchronous plugin loading return s.GetRequiredService <IPluginResolver <T> >().Load(); }, serviceLifetime)) .AddService(new ServiceDescriptor(typeof(IEnumerable <T>), (s) => { // Synchronous plugin loading return s.GetRequiredService <IPluginResolver <T> >().LoadAll(); }, serviceLifetime))); }
public static IServiceCollection AddPriseWithPluginLoader <T, TPluginLoader>(this IServiceCollection services, Action <PluginLoadOptionsBuilder <T> > config = null) where T : class where TPluginLoader : class, IPluginLoader <T>, IPluginResolver <T> { var optionsBuilder = new PluginLoadOptionsBuilder <T>().WithDefaultOptions(); config?.Invoke(optionsBuilder); services = optionsBuilder.RegisterOptions(services); return(services .AddScoped <IPluginLoader <T>, TPluginLoader>() .AddScoped <IPluginResolver <T>, TPluginLoader>() .AddScoped <T>((s) => { // Synchronous plugin loading return s.GetRequiredService <IPluginResolver <T> >().Load(); }) .AddScoped <IEnumerable <T> >((s) => { // Synchronous plugins loading return s.GetRequiredService <IPluginResolver <T> >().LoadAll(); })); }