I have a problem that I can not identify what it is causing. When trying to enter the log view, an "internal server error" occurs and the message below appears.
I'm using ASP.NET Core 2.1.1
InvalidOperationException: Can not conspire service 'AgendaWeb.Data.ApplicationDbContext' from singleton 'AgendaWeb.Domain.IRepository'1 [AgendaWeb.Domain.Users.User]'.
[AgendaWeb.Domain.Users.User]
using AgendaWeb.Domain.Adresses;
using System;
using System.Collections.Generic;
using System.Text;
namespace AgendaWeb.Domain.Users
{
public class User : Entity
{
public string UserName { get; private set; }
public string FullName { get; private set; }
public string Cpf { get; private set; }
public string Email { get; private set; }
public string Phone { get; private set; }
public string CellPhone { get; private set; }
public string PhotoUrl { get; private set; }
public string Password { get; private set; }
public DateTime RegistrationDate { get; private set; }
public DateTime? DateOfBirth { get; private set; }
public string ProfileType { get; private set; }
public Address Address { get; private set; }
public User()
{
}
public User(string userName, string fullName, string cpf, string email, string phone, string cellPhone, string photoUrl, string password, DateTime registrationDate, DateTime? dateOfBirth, string profileType, Address address)
{
ValidateValues(userName, fullName, cpf, email, phone, cellPhone, photoUrl, password, registrationDate, dateOfBirth, profileType, address);
SetProperties(userName, fullName, cpf, email, phone, cellPhone, photoUrl, password, registrationDate, dateOfBirth, profileType, address);
}
public void Update(string userName, string fullName, string cpf, string email, string phone, string cellPhone, string photoUrl, string password, DateTime registrationDate, DateTime? dateOfBirth, string profileType, Address address)
{
ValidateValues(userName, fullName, cpf, email, phone, cellPhone, photoUrl, password, registrationDate, dateOfBirth, profileType, address);
SetProperties(userName, fullName, cpf, email, phone, cellPhone, photoUrl, password, registrationDate, dateOfBirth, profileType, address);
}
private void SetProperties(string userName, string fullName, string cpf, string email, string phone, string cellPhone, string photoUrl, string password, DateTime registrationDate, DateTime? dateOfBirth, string profileType, Address address)
{
UserName = userName;
FullName = fullName;
Cpf = cpf;
Email = email;
Phone = phone;
CellPhone = cellPhone;
PhotoUrl = photoUrl;
Password = password;
RegistrationDate = registrationDate;
DateOfBirth = dateOfBirth;
ProfileType = profileType;
Address = address;
}
private static void ValidateValues(string userName, string fullName, string cpf, string email, string phone, string cellPhone, string photoUrl, string password, DateTime registrationDate, DateTime? dateOfBirth, string profileType, Address address)
{
DomainException.When(string.IsNullOrEmpty(userName), "O campo nome é obrigatório!");
DomainException.When(address == null, "O campo endereço é obrigatório!");
}
}
}
AgendaWeb.Domain.IRepository
using System;
using System.Collections.Generic;
using System.Text;
namespace AgendaWeb.Domain
{
public interface IRepository<TEntity>
{
TEntity GetById(int id);
void Save(TEntity entity);
}
}