public static IServiceCollection AddUCenterApi <TUcApi>(
            this IServiceCollection services, IConfiguration configuration)
            where TUcApi : BaseUcApi
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            UCenterApiOptions options = new UCenterApiOptions();

            configuration.GetSection("UCenterApi").Bind(options);

            services.AddSingleton(typeof(UCenterApiOptions), options);
            services.AddSingleton <IUcConfig>(options);

            services.AddScoped <UcUtility>();
            services.AddTransient <UcClient>();
            services.AddTransient <IUcClient, UcClient>();
            services.AddTransient <IUcApi, TUcApi>();


            return(services);
        }
Example #2
0
 public UCenterApiMiddleware(RequestDelegate next, IOptions <UCenterApiOptions> optionsAccessor)
 {
     _next    = next;
     _options = optionsAccessor.Value;
 }