Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

web api core dependency error

$
0
0
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

Viewing all articles
Browse latest Browse all 9386

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>