Controller
public class GetBanksController : ControllerBase
{
private readonly IGetBanks _interfacegetbanks;
public GetBanksController(IGetBanks interfacegetbanks)
{
_interfacegetbanks = interfacegetbanks;
}
public ActionResult GetBanks(GetBankRequest request)
{
GetBankResponse response = new GetBankResponse();
try
{
response = _interfacegetbanks.GetBanks(request);
}
catch (Exception e)
{
}
return Ok(response);
}
}
Repository
public class GetBanksRepository :IGetBanks
{
private readonly DAL.GetBanksDAL _objgetbankdal;
public GetBanksRepository(DAL.GetBanksDAL objgetbankdal)
{
_objgetbankdal = objgetbankdal;
}
public GetBankResponse GetBanks(GetBankRequest request)
{
try
{
return _objgetbankdal.GetBankDAL(request);
}
catch (Exception e)
{
throw e;
}
}
}
Interface
public interface IGetBanks
{public GetBankResponse GetBanks(GetBankRequest request);
}
DAL
public GetBankResponse GetBankDAL(GetBankRequest _objgetbanksrequest)
{
try
{
using (var con = new SqlConnection(this.Sqlconnection()))
{
GetBankResponse response = new GetBankResponse();
con.Open();
SqlCommand cmd = new SqlCommand("sp_GetBanks", con);
cmd.Parameters.AddWithValue("@ChannelID", _objgetbanksrequest.ChannelID);
cmd.Parameters.AddWithValue("@ReferenceID", _objgetbanksrequest.ReferenceID);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
response.BankNames = Convert.ToString(dr["BankNames"]);
response.BankURL = Convert.ToString(dr["BankURL"]);
}
con.Close();
return response;
}
}
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IGetBanks, GetBanksRepository>();
services.AddControllers();
}
Program.cs
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();// getting error as "Some services are not able to be constructed (Error while//validating the service descriptor 'ServiceType: Interface.IGetBanks Lifetime://Transient ImplementationType: Repositories.GetBanksRepository': Unable to resolve service for type 'DAL.GetBanksDAL' while attempting to
}
can anyone assist me?
Thanks