public CustomDutyClientService(HttpClient httpClient, DutyConfig dutyConfig)
        {
            _dutyConfig = dutyConfig;

            var    plainTextBytes = System.Text.Encoding.UTF8.GetBytes($"{_dutyConfig.ClientUsername}:{_dutyConfig.ClientPassword}");
            string val            = System.Convert.ToBase64String(plainTextBytes);

            kaoshiClient             = httpClient;
            kaoshiClient.BaseAddress = new Uri(_dutyConfig.BaseUrl);
            kaoshiClient.DefaultRequestHeaders.Add("Authorization", "Basic " + val);
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DutyConfig _dutyConfig = new DutyConfig();

            // Settings _settings = new Settings();

            // Configuration.Bind("ConnectonString", _settings);
            Configuration.Bind(nameof(DutyConfig), _dutyConfig);


            services.AddSingleton(_dutyConfig);
            services.AddSingleton(new CustomContext());
            services.AddAutoMapper(typeof(Startup));
            services.AddHttpClient <ICustomDutyClient, CustomDutyClientService>();
            // services.AddSingleton(_settings);
            //services.AddSingleton(new CustomContext());

            services.AddDbContext <CustomContext>(opt =>
            {
                opt.UseSqlServer(Configuration["ConnetionString:DefaultConnection"]);
            });

            //services.Configure<Settings>(Configuration.GetSection("ConnectonString"));

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Custom Duty api", Version = "v1"
                });

                //var security = new Dictionary<string, IEnumerable<string>>
                //{
                //    {"Bearer", new string[0] }
                //};
                //c.AddSecurityDefinition(name: "Bearer", new ApiKeyScheme {
                //    Description = "JWT Authorization header using bearer scheme",
                //    Name = "Authorization",
                //    In = "header",
                //    Type = "apiKey"
                //});
            });
            services.AddControllers().AddNewtonsoftJson();
        }
Example #3
0
 public TaxController(ICustomDutyClient client, DutyConfig dutyConfig, CustomContext context)
 {
     _client     = client;
     _dutyConfig = dutyConfig;
     _context    = context;
 }