I have a class that contains a method that uses some database connection strings and instead of hard coding them, I want to pull them from my appsettings.json file. So, following others who have done similar things, I created a constructor with an IConfiguration parameter. I am attempting to use the SearchOfficer method in a Blazor Page's base class, to do so I tried to make a new instance of Search but couldn't figure out: what should I pass to the constructor?
The Class with the Method:
public class Searches
{
private readonly IConfiguration _config;
public Searches(IConfiguration configuration)
{
_config = configuration;
}
public async Task<List<NameScore>> SearchOfficer(string Input)
{
//processy stuff
//Querying stuff
DataAccess data = new DataAccess();
string sql = "SELECT IdOfficer, Name FROM officers";
List<FirstLoadOfficer> Names = await data.LoadData<FirstLoadOfficer, dynamic>
(sql, new { }, _config.GetConnectionString("DataDB"));
//Sorting and Comparing stuff
return SortedNames;
}
}
How I am attempting to use it:
Searches searches = new Searches(/*what should I put here?*/);
SimilarPeople = await searches.SearchOfficer("Input Name");