I am working on a web API with an ASP.NET core. When I execute my API with a mail request, an exception is thrown before my breakpoint in the Post UnitController method.
Exception
Request to start HTTP / 1.1 POST http: // localhost: 5000 / api / unit application / json 31 fail: Microsoft.AspNetCore.Server.Kestrel [13] Connection identifier "0HKVTL9A1LTD4": an unhandled exception was thrown by the application. System.InvalidOperationException: Cannot resolve the service for type "Project.DataAccess.Repository.UnitRepository" when trying to activate "Project.Service.UnitService".
Context
namespace Project.DataAccess.Library.Interface { public interface IBaseRepository<M> where M : class, IEntity { IEnumerable<M> SelectAll(); M SelectByID(int id); void Insert(M obj); void Update(M obj); void Delete(int id); void Save(); } } namespace Project.DataAccess.Library { public abstract class BaseRepository<M> : IBaseRepository<M> where M : class, IEntity { protected ProjectContext Db { get; } private DbSet<M> table = null; protected DbSet<M> Table { get { return this.table; } } public BaseRepository(ProjectContext dbContext) { Db = dbContext; this.table = Db.Set<M>(); } public void Delete(int id) { M existing = this.SelectByID(id); if (existing != null) this.table.Remove(existing); }
Version
"dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" }, "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.EntityFrameworkCore": "1.0.0", "MySql.Data.Core": "7.0.4-IR-191", "MySql.Data.EntityFrameworkCore": "7.0.4-IR-191", "IdentityServer4": "1.0.0-rc2", "AssoManager.Domain": "1.0.0-*", "AssoManager.Service": "1.0.0-*", "AssoManager.DataAccess": "1.0.0-*" },
Question
I think the problem may be related to the inheritance between BaseRepository and IBaseRepository. But I donβt understand where my mistake could be. How can I fix this error?
Thanks for the help:),
source share