Here is my controller class
Registering Service from Constructor Class
public class NCElasticAPI : Controller
{
public NCElasticAPI(IElasticClient elasticClient,IConfiguration _config)
{
ConnectionToEs.GetConnectionKey(ConnectionStringKey.AcquirerElasticConnection);
_elasticClient = elasticClient;
}
}
Here i am intiliazing IServiceCollection
I am calling GetConnectionKey Method from ConnectionToES Static Class
public static IServiceCollection services { get; }
public static void GetConnectionKey(string key)
{
Key_ = key;
if (Key_ == ConnectionStringKey.AcquirerElasticConnection)
{
AcqNode = CommonObjects.GetCongifValue(ConfigKeys.AcqDataUrl);
AcqNodes = new Uri[] { new Uri(AcqNode), };
AcqPool = new StaticConnectionPool(AcqNodes);
AcqConnection = new ConnectionSettings(AcqPool)
.BasicAuthentication(CommonObjects.GetCongifValue(ConfigKeys.AcqDataUserName), CommonObjects.GetCongifValue(ConfigKeys.AcqDataPassword))
.DisableDirectStreaming();
var AcqClient = new ElasticClient(AcqConnection);
services.AddSingleton<IElasticClient>(AcqClient);
>services variables is parameterless or null
}
}
I know that in order to use IServiceCollection i have to do something like this
public static void (this IServiceCollection services){}
but i dont want to call it from Start Up .cs Instead from Constructor Class