I'm trying to build a web api based project using .net core.
I have a problem on debug
InvalidOperationException: Unable to resolve service for type 'PropertiesApplication.API.Models.IMyPropertiesRepository' while attempting to activate 'PropertiesApplication.API.Controllers.MyPropertiesController'.
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)
lambda_method(Closure , IServiceProvider , Object[] )
here is my api
[Route("api/[controller]")]
public class MyPropertiesController : Controller
{
public IMyPropertiesRepository _repo;
public MyPropertiesController(IMyPropertiesRepository repo)
{
_repo = repo;
}
[HttpGet]
public IEnumerable<MyProperty> GetAll()
{
return _repo.GetProperties();
}
}
here is my repository
public class MyPropertisRepository:IMyPropertiesRepository
{
private readonly MyPropertiesContext _context;
public MyPropertisRepository(MyPropertiesContext context)
{
_context = context;
}
public IEnumerable<MyProperty> GetProperties()
{
return _context.MyProperties.ToList();
}
}
here is my interface
public interface IMyPropertiesRepository
{
IEnumerable<MyProperty> GetProperties();
}
and here is my startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var connection = @"Server=(localdb)\mssqllocaldb;Database=MyPropertiesDB;Trusted_Connection=True;ConnectRetryCount=0";
services.AddDbContext<MyPropertiesContext>(options => options.UseSqlServer(connection));
}
please provide me with more info if possible
thank you
I have a problem on debug
InvalidOperationException: Unable to resolve service for type 'PropertiesApplication.API.Models.IMyPropertiesRepository' while attempting to activate 'PropertiesApplication.API.Controllers.MyPropertiesController'.
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)
lambda_method(Closure , IServiceProvider , Object[] )
here is my api
[Route("api/[controller]")]
public class MyPropertiesController : Controller
{
public IMyPropertiesRepository _repo;
public MyPropertiesController(IMyPropertiesRepository repo)
{
_repo = repo;
}
[HttpGet]
public IEnumerable<MyProperty> GetAll()
{
return _repo.GetProperties();
}
}
here is my repository
public class MyPropertisRepository:IMyPropertiesRepository
{
private readonly MyPropertiesContext _context;
public MyPropertisRepository(MyPropertiesContext context)
{
_context = context;
}
public IEnumerable<MyProperty> GetProperties()
{
return _context.MyProperties.ToList();
}
}
here is my interface
public interface IMyPropertiesRepository
{
IEnumerable<MyProperty> GetProperties();
}
and here is my startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var connection = @"Server=(localdb)\mssqllocaldb;Database=MyPropertiesDB;Trusted_Connection=True;ConnectRetryCount=0";
services.AddDbContext<MyPropertiesContext>(options => options.UseSqlServer(connection));
}
please provide me with more info if possible
thank you