/// <summary>
 /// Adds an <see cref="ICustomResourceWatcher"/> for the specified custom resource type
 /// </summary>
 /// <typeparam name="TResource">The type of the custom resource to watch</typeparam>
 /// <param name="services">The <see cref="IServiceCollection"/> to configure</param>
 /// <param name="configuration">An <see cref="Action{T}"/> used to configure the <see cref="ICustomResourceWatcher"/> to use</param>
 /// <returns>The configured <see cref="IServiceCollection"/></returns>
 public static IServiceCollection AddCustomResourceWatcher <TResource>(this IServiceCollection services, Action <ICustomResourceWatcherOptionsBuilder> configuration)
     where TResource : class, ICustomResource, new()
 {
     services.TryAddSingleton(typeof(ICustomResourceWatcher <TResource>), provider =>
     {
         ICustomResourceWatcherOptionsBuilder optionsBuilder = new CustomResourceWatcherOptionsBuilder();
         configuration(optionsBuilder);
         CustomResourceWatcherOptions options = optionsBuilder.Build();
         return(ActivatorUtilities.CreateInstance <CustomResourceWatcher <TResource> >(provider, options));
     });
     return(services);
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new <see cref="ICustomResourceWatcher{TResource}"/>.
 /// </summary>
 /// <param name="logger">The service used to perform logging</param>
 /// <param name="kubernetes">The service used to communicate with Kubernetes.</param>
 /// <param name="options">The current <see cref="CustomResourceWatcherOptions"/></param>
 public CustomResourceWatcher(ILogger <CustomResourceWatcher <TResource> > logger, IKubernetes kubernetes, CustomResourceWatcherOptions options)
 {
     this.Logger             = logger;
     this.Kubernetes         = kubernetes;
     this.ResourceDefinition = new TResource().Definition;
     this.Options            = options;
     this.StartAsync();
 }