locked
How to use aspnetcore dependency injection to initialize sdk? RRS feed

  • Question

  • User1849955458 posted

    Traditional initialization methods:

    IClientProfile clientProfile = DefaultProfile.GetProfile("<your-region-id>", "<your-access-key-id>", "<your-access-key-secret>");

    DefaultAcsClient client = new DefaultAcsClient(clientProfile);

    I want to use dependency injection to initialize:

    public class IotController : ControllerBase
    {
    private DefaultAcsClient _client;

    public IotController(DefaultAcsClient client)
    {
    _client = client;
    //IClientProfile clientProfile = DefaultProfile.GetProfile("<your-region-id>", "<your-access-key-id>", "<your-access-key-secret>");
    //_client = new DefaultAcsClient(clientProfile);}
    }

    ------------------------------------------------------------------------------------

    public void ConfigureServices(IServiceCollection services)
    {

    var clientProfile = DefaultProfile.GetProfile(Configuration.GetSection("RegionId").Value, Configuration.GetSection("AccessKeyId").Value, Configuration.GetSection("AccessKeySecret").Value);

    services.AddScoped<DefaultAcsClient>();


    }

    Friday, June 7, 2019 3:15 PM

All replies