I have a class like this which I would like to use its methods in another class which is being used by the controller:
public class CommunicationApi
{
private readonly IConfiguration _configuration;
private readonly ILogger _logger;
private readonly MyAuthentication _myAuthentication;
public myEmail MyMail { get; set; }
public string[] Attachments { get; set; }
public bool IsBodyHtml { get; set; }
public CommunicationApi(ILogger<AdoExtract> logger, Func<string, myAuthentication> SAuth, IConfiguration configuration = null)
{
_configuration = configuration;
_logger = logger;
_myAuthentication = mAuth("ApiGatewayScope");
}
public async Task<int> SendMail()
{
//.....
}
}
I am trying to use this class and method in another class like this
public class AdoExtract : IAdoExtract
{
private readonly IConfiguration _configuration;
private readonly ILogger _logger;
private readonly Communication _com;
public AdoExtract(ILogger<AdoExtract> logger, IConfiguration configuration = null, CommunicationApi com = null)
{
_configuration = configuration;
_logger = logger;
_com = com;
}
public async Task<int> TestMail()
{
_com // here I am trying to set the properties of the above communication APIs such as MyEmail,Attachments
}
}
I need to set the properties of the communicationAPI class in the TestMail function of the other class. But I am not getting any of the properties or function SendMail() which I really need to call to send email.
In the startup.cs I have added the CommunicationAPI like this
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<CommunicationApi>();
}
Which I really believe its not the correct way. Please help me to solve this. I am pretty new to DI.