Exemplo n.º 1
0
        /// <summary>
        /// Adds and configures a new <see cref="IResourceController{TResource}"/>
        /// </summary>
        /// <typeparam name="TController">The type of the <see cref="IResourceController{TResource}"/> implementation to add</typeparam>
        /// <typeparam name="TResource">The type of <see cref="ICustomResource"/> to manage</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="IResourceController"/> to add</param>
        /// <returns>The configured <see cref="IServiceCollection"/></returns>
        public static IServiceCollection AddResourceController <TController, TResource>(this IServiceCollection services, Action <IResourceControllerOptionsBuilder <TResource> > configuration)
            where TController : class, IResourceController <TResource>
            where TResource : class, ICustomResource, new()
        {
            ResourceControllerOptionsBuilder <TResource> optionsBuilder = new();

            configuration?.Invoke(optionsBuilder);
            ResourceControllerOptions <TResource> options = optionsBuilder.Build();

            services.AddSingleton(Options.Create(options));
            services.AddSingleton <TController>();
            services.AddSingleton <IResourceController <TResource> >(provider => provider.GetRequiredService <TController>());
            services.AddSingleton <IHostedService>(provider => provider.GetRequiredService <TController>());
            return(services);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new <see cref="ResourceControllerOptionsBuilder{TResource}"/>
 /// </summary>
 /// <param name="options">The <see cref="ResourceControllerOptions{TResource}"/> to configure</param>
 public ResourceControllerOptionsBuilder(ResourceControllerOptions <TResource> options)
 {
     this.Options = options;
 }